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>...snip...
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.
---------------------------(end of broadcast)--------------------------- TIP 4: Don't 'kill -9' the postmaster