From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | "Jennifer Lee" <jlee(at)scri(dot)sari(dot)ac(dot)uk> |
Cc: | pgsql-novice(at)postgresql(dot)org |
Subject: | Re: adding data to tables with sequences |
Date: | 2003-02-27 15:13:27 |
Message-ID: | 10926.1046358807@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
"Jennifer Lee" <jlee(at)scri(dot)sari(dot)ac(dot)uk> writes:
> what I've tried is
> INSERT INTO data_value (data_id, element_number, value)
> SELECT d.data_id, nextval('element_seq'), t.value
> FROM data d, temp_data t, data_type dt
> WHERE d.type_id = dt.type_id
> AND t.marker = dt.description
> ORDER BY t.temp_id;
> This works only the element_numbers using the sequences are in a
> random order. The values seem to be inserted in the order of the
> temp_id so if I do a select * from the table the are listed in the order I'd
> like them in.
Well, yeah: you asked to ORDER BY temp_id, and that happens after the
SELECT-list expressions are computed. You could probably get the
behavior you want with a two-level SELECT:
INSERT INTO data_value (data_id, element_number, value)
SELECT data_id, nextval('element_seq'), value
FROM
(SELECT d.data_id, t.value
FROM data d, temp_data t, data_type dt
WHERE d.type_id = dt.type_id
AND t.marker = dt.description
ORDER BY t.temp_id) ss;
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Gilbert | 2003-02-27 15:49:50 | initdb hangs even though ipc-daemon is running? |
Previous Message | Aspire Something | 2003-02-27 14:25:19 | Function Comit |