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