Help converting a MySQL query to postgres
This kind of queries do not need variables in Postgres. You can use window functions:

WITH cte AS
( SELECT id,
         1 + (ROW_NUMBER() OVER (ORDER BY id DESC) - 1) / $n  AS new_x
  FROM t
)
UPDATE t
SET x = new_x
FROM cte
WHERE t.id = cte.id ;


You 1 + (ROW_NUMBER() OVER (ORDER BY id DESC) - 1) / $n could also be written similarly to your expression, if you prefer. Assuming that $n is an integer parameter, the result will be the same:

ceiling(ROW_NUMBER() OVER (ORDER BY id DESC) / $n::numeric)