On May 6, 2006, at 17:13 , Miroslav Šulc wrote:
I have a table with cca 100,000 records. I need to hard-sort the
records
by a key from second table. By hard-sorting I mean storing position of
each row in the main table. Here is what my tables look like:
main_table: id, name, position
key_tab
Hi PFC,
the generate_series() seems to be the right thing I need in my scenario
but I didn't figure out how to create a SELECT stattement that will
contain sorted main_table.id in first column and generated series in
second column which I would use to update the main_table.position. Is it
possible
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
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 wa
Is it possible to do this :
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 automat
main_table: id, name, position
key_table: id, main_table_id, key, value
Here is how I need to sort the records:
SELECT * FROM main_table
INNER JOIN key_table ON main_table.id = key_table.main_table_id
WHERE key = 'param'
ORDER BY value
I currently collect all ids from main_table in sorted order
Hi, Miroslav,
Miroslav Šulc schrieb:
> I have a table with cca 100,000 records. I need to hard-sort the records
> by a key from second table. By hard-sorting I mean storing position of
> each row in the main table. Here is what my tables look like:
>
> main_table: id, name, position
> key_table:
Hello,
I have a table with cca 100,000 records. I need to hard-sort the records
by a key from second table. By hard-sorting I mean storing position of
each row in the main table. Here is what my tables look like:
main_table: id, name, position
key_table: id, main_table_id, key, value
Here is how