Re: COPY TO order

Поиск
Список
Период
Сортировка
От Guy Fraser
Тема Re: COPY TO order
Дата
Msg-id 407ACBB5.3020003@incentre.net
обсуждение исходный текст
Ответ на Re: COPY TO order  (Christopher Browne <cbbrowne@acm.org>)
Ответы Re: COPY TO order  (Clodoaldo Pinto Neto <clodoaldo_pinto@yahoo.com.br>)
Список pgsql-general
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.




В списке pgsql-general по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: ERROR: REINDEX DATABASE: Can be executed only on the currently open database.
Следующее
От: Clodoaldo Pinto Neto
Дата:
Сообщение: Re: COPY TO order