Re: COPY TO order - Mailing list pgsql-general

From Guy Fraser
Subject Re: COPY TO order
Date
Msg-id 407C3813.8050400@incentre.net
Whole thread Raw
In response to Re: COPY TO order  (Clodoaldo Pinto Neto <clodoaldo_pinto@yahoo.com.br>)
Responses Re: COPY TO order
List pgsql-general
Ahh, I see.

Like this from the command line :

psql --no-align --tuples-only --field-separator , -c "select
data,comment from test_table order by test_id ;" database >/tmp/file

 From psql prompt :

\a\t\f,
select data,comment from test_table order by test_id \g /tmp/file
\a\t\f|

Either way you should get a file {/tmp/file} contaning :

27,some kind of entry
32,another kind of entry
16,yet another entry
...



Clodoaldo Pinto Neto wrote:

> --- Guy Fraser <guy@incentre.net>
>
>
>>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.
>>
>>
>
>The problem I have is with COPY TO and not COPY FROM as I need to write a file.
>
>
...snip...



pgsql-general by date:

Previous
From: Michael Fuhr
Date:
Subject: Join works in 7.3.6, fails in 7.4.2
Next
From: Chris Kratz
Date:
Subject: insert rule not firing on insert with exists subselect