From: | "Ben K(dot)" <bkim(at)coe(dot)tamu(dot)edu> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Most efficient way to hard-sort records |
Date: | 2006-05-07 14:16:41 |
Message-ID: | Pine.GSO.4.64.0605070837330.12629@coe.tamu.edu |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
> CREATE TABLE sorted (order_no SERIAL PRIMARY KEY, other columns...)
> INSERT INTO sorted (columns) SELECT * FROM main_table INNER JOIN
> key_table ON main_table.id = key_table.main_table_id WHERE key = 'param' ORDER
> BY value SELECT
> The SERIAL will automatically generate the order_no you want, which
> corresponds to the position in the sorted set.
> Then, to get the records in-order :
> SELECT * FROM sorted ORDER BY order_no
Good ... I just got myself into the habit of not recreating a table since
I have to clean up permissions and what not. I guess it depends.
Another version along that line ?
# create sequence counterseq start 1;
-- (set/reset whenever a counter is needed)
# select main_table.*, nextval('counterseq') as position2
into sorted_main_table
from main_table, keytable where main_table.id =
keytable.main_table_id
order by value;
Regards,
Ben K.
Developer
http://benix.tamu.edu
From | Date | Subject | |
---|---|---|---|
Next Message | PFC | 2006-05-07 22:58:15 | Re: Most efficient way to hard-sort records |
Previous Message | Markus Schaber | 2006-05-07 08:39:48 | Re: Returning String as Integer |