Re: psql -f COPY from STDIN

From: Tarlika Elisabeth Schmitz <postgresql2(at)numerixtechnology(dot)de>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: psql -f COPY from STDIN
Date: 2010-11-13 15:04:02
Message-ID: 20101113150402.67e3ddfe@dick.coachhouse
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Sat, 13 Nov 2010 12:01:35 +0000
Tarlika Elisabeth Schmitz <postgresql2(at)numerixtechnology(dot)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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message berelith 2010-11-13 23:48:02 Need help with plpgsql function.
Previous Message Tom Lane 2010-11-13 14:54:57 Re: psql -f COPY from STDIN