Re: selective export for subsequent import (COPY) - Mailing list pgsql-general

From Brent Wood
Subject Re: selective export for subsequent import (COPY)
Date
Msg-id 46283A73.5040004@niwa.co.nz
Whole thread Raw
In response to Re: selective export for subsequent import (COPY)  (chrisj <chrisj.wood@sympatico.ca>)
Responses Re: selective export for subsequent import (COPY)  (chrisj <chrisj.wood@sympatico.ca>)
List pgsql-general
chrisj wrote:
> Thanks Alan,
> This helped a lot, but ideally I want a tab field delimiter and -F '\t' does
> not seem to work, any ideas??
>
> I noticed one other post on this same problem of the fieldsep '\t' not
> working but the only advise offered was to use \pset.  Can \pset be used on
> the command line, I can only get it to work within the psql command
> processor.
>
>

You can always have a text file (file.sql):

\pset ...
select .....


the run the commands is a single client connection with

psql database -Atf file.sql

This runs a file of sql commands in a single psql connection instead of
opening a new connection for every -c "" command.
Thus the result of the \pset is still in force when the next sql
statement is executed.

or run your command as it is & pipe the output through tr to translate
the commas to tabs.
You can see what tr does using
echo "1,2" | tr "," "\t"

eg:
psql $DATABASEHOST -U $DATABASEUSER -d $DATABASE -q -P footer -A -F , -c "$DETAIL_SQL" | tr "," "\t" >table.csv


Cheers,

  Brent Wood


pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Is it possible to move a database to another tablespace?
Next
From: "Mike Frysinger"
Date:
Subject: cant get pg_dump/pg_restore to behave