Re: psql -f COPY from STDIN - Mailing list pgsql-sql

From Tarlika Elisabeth Schmitz
Subject Re: psql -f COPY from STDIN
Date
Msg-id 20101113150402.67e3ddfe@dick.coachhouse
Whole thread Raw
In response to Re: psql -f COPY from STDIN  (Tarlika Elisabeth Schmitz <postgresql2@numerixtechnology.de>)
List pgsql-sql
On Sat, 13 Nov 2010 12:01:35 +0000
Tarlika Elisabeth Schmitz <postgresql2@numerixtechnology.de> wrote:

>I'd like the store the COPY command in a separate file without
>specifying an input file name. I want to feed it the data from the
>shell script that calls psql


"STDIN: All rows are read from the same source that issued the command"
- As I understand now, this applies to both COPY and \COPY. In other
words the input file must contain command and data.


I have found a few solutions to achieve my objective:

1) using COPY FROM STDIN
cat event.csv | psql -c "$(cat event.sql)"

2) using COPY FROM STDIN
psql -f  <(cat event.sql event.csv)

3) using \COPY FROM PSTDIN
cat event.csv | psql -f event.sql

4) using \COPY FROM STDIN
psql -f  <(cat event.sql event.csv <(echo "\."))


What I don't like about \COPY is that it has to be on one line. Indeed
it can't be split over multiple lines, Tom, not with backslash either.

\COPY FROM STDIN requires the data to be terminated with "\." whereas
COPY is happy with EOF.

I'll go for 2) because it allows me to format the COPY command over
multiple lines.

-- 

Best Regards,
Tarlika Elisabeth Schmitz


pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: psql -f COPY from STDIN
Next
From: berelith
Date:
Subject: Need help with plpgsql function.