Christopher Browne wrote:
[color=blue]
>Centuries ago, Nostradamus foresaw when
clodoaldo_pinto@yahoo.com.br (Clodoaldo Pinto Neto) would write:
>
>[color=green]
>>How to make sure COPY TO writes the table lines to the file in the same order
>>they were inserted?
>>
>>[/color]
>
>You probably want to rewrite PostgreSQL then.
>
>
>[color=green]
>>I'm producing html pages in pl/pgsql and using COPY TO to write then
>>to file. Occasionaly, about once in 7 or 9, the lines are copied to
>>the file out of the order they were inserted in the table.
>>
>>[/color]
>
>If you need to maintain data in some order, then you need to add a key
>field that indicates that ordering, and use ORDER BY in order to
>select the data in that order.
>
>That will involve not using COPY TO.
>
>[/color]
Not really.
If you have a 'serial' or 'bigserial' field like this :
create table test_table (
test_id bigserial,
data integer,
comment text
);
and you use :
copy test_table (data,comment)
from '/wherever/the/file/is'
using delimiters ',';
to insert data like this :
27,some kind of entry
32,another kind of entry
16,yet another entry
....
Assuming this is the first set of data entered the table will get populated with :
1 | 27 | some kind of entry
2 | 32 | another kind of entry
3 | 16 | yet another entry
....
I have used this in the past and it works well.
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?
http://archives.postgresql.org