Search Postgresql Archives

Re: COPY TO order

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Christopher Browne wrote:

Centuries ago, Nostradamus foresaw when clodoaldo_pinto@yahoo.com.br (Clodoaldo Pinto Neto) would write:


How to make sure COPY TO writes the table lines to the file in the same order
they were inserted?



You probably want to rewrite PostgreSQL then.




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.



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.


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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux