Click to See Complete Forum and Search --> : adding a sequential key to the table


wdguy
10-21-2007, 03:55 PM
I was wondering if there's any way in PostgreSQL to sort a table by a certain column and then add a column that just contains numbers 1,2,3,4, and so on. For example, if the table is


fruit quantity
apple 5
orange 8
banana 2
peach 10


the resulting table should look like:


fruit quantity key
banana 2 1
apple 5 2
orange 8 3
peach 10 4

BrainDonor
10-24-2007, 12:09 PM
this may (or may not) help...

http://www.thescripts.com/forum/thread173080.html