I have a table, items
, with a priority
column, which is just an integer. In trying to do some bulk operations, I'm trying to reset the priority
to be a sequential number.
I've been able to use ROW_NUMBER()
to successfully generate a table that has the new priority
values I want. Now, I just need to get the values from that SELECT
query into the matching records in the actual items
table.
I've tried something like this:
UPDATE
"items"
SET
"priority" = tempTable.newPriority
FROM
(
SELECT
ROW_NUMBER() OVER (
ORDER BY
/* pile of sort conditions here */
) AS "newPriority"
FROM
"items"
) AS tempTable
WHERE
"items"."id" = "tempTable"."id"
;
I keep getting a syntax error "near FROM".
How can I correct the syntax here?