I was wondering how to add a field to a table (e.g. country
) based on sorting some of its fields (e.g. ISO
code)?
I searched around SO and found the following question, but the solution is based on MySQL. I tried to use the solution there in Postgres 9.3 and it's giving me an syntax error on :=
. What I tried is:
SELECT l.*,
@curRow := @curRow + 1 AS row_number
FROM country l ORDER BY ISO
JOIN (SELECT @curRow := 0) r;
How to adapt this to Postgres?