pg.ddx.io pgsql-sql@postgresql.org mailing list archivehelp / color / mirror / Atom feed
From: Tarlika Elisabeth Schmitz <postgresql2@numerixtechnology.de>
To: pgsql-sql@postgresql.org
Subject: Re: psql -f COPY from STDIN
Date: Sat, 13 Nov 2010 15:04:02 +0000
Message-ID: <20101113150402.67e3ddfe@dick.coachhouse> (raw)
In-Reply-To: <20101113120135.6b7fdc9e@dick.coachhouse>
References: <20101112220340.36a0bc75@dick.coachhouse>
<8452.1289618531@sss.pgh.pa.us>
<20101113120135.6b7fdc9e@dick.coachhouse>
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
view thread (6+ messages)
Message-ID: <20101113150402.67e3ddfe@dick.coachhouse> Permalink: ../20101113150402.67e3ddfe@dick.coachhouse/ Also on: postgresql.org/message-id/20101113150402.67e3ddfe@dick.coachhouse ·
reply
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Reply to all the recipients using the --to and --cc options: reply via email To: pgsql-sql@postgresql.org Cc: postgresql2@numerixtechnology.de Subject: Re: psql -f COPY from STDIN In-Reply-To: <20101113150402.67e3ddfe@dick.coachhouse> * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox