Help converting a MySQL query to postgres Is it possible to do this query in postgresql?

SET @p:= 0;
UPDATE t SET x=CEIL((@p:= @p + 1) / $n) ORDER BY id DESC;


I'm struggling with the variable syntax.  I tried:

\set p 0
update t set x=CEIL((:p := :p+1) / 10);
ERROR:  syntax error at or near ":="
LINE 1: update t set x=CEIL((0 := 0+1) / 10);
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)