From: Tarlika Elisabeth Schmitz <postgresql2@numerixtechnology.de>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-sql@postgresql.org
Subject: Re: psql -f COPY from STDIN
Date: Sat, 13 Nov 2010 12:01:35 +0000
Message-ID: <20101113120135.6b7fdc9e@dick.coachhouse> (raw)
In-Reply-To: <8452.1289618531@sss.pgh.pa.us>
References: <20101112220340.36a0bc75@dick.coachhouse>
<8452.1289618531@sss.pgh.pa.us>
On Fri, 12 Nov 2010 22:22:11 -0500
Tom Lane <tgl@sss.pgh.pa.us> wrote:
>Tarlika Elisabeth Schmitz <postgresql2@numerixtechnology.de> writes:
>> The following command works fine when pasing it to psql via the -c
>> option:
>
>> cat event.csv | \
>> psql -c "COPY (event_id, event_name) FROM STDIN DELIMITER AS ',' NULL
>> AS ''"
>
>> When executed from a file via -f, it does nothing
>
>> event.sql:
>> COPY (event_id, event_name) FROM STDIN DELIMITER AS ',' NULL AS ''
>
>> cat event.csv | psql -f event.sql
>
>[...]
>
>I think you can get the effect you're after using \copy ... from
>pstdin. See the psql man page.
Thank you for your reply, Tom. I had not appreciated the difference
between \COPY and COPY. The psql command is executed on the client; the
import data are on the client, so I ought to use \COPY.
Strangely, cat event.csv |psql -c "COPY ... worked, presumably
because both the COPY command and data came from the same source (client
stdin).
I changed event.sql (3 lines):
\COPY
(event_id, event_name)
FROM STDIN DELIMITER AS ',' NULL AS ''
Now I am getting error messages:
psql:event.sql:1: \copy:parse error at end of line
psql:event.sql:4: ERROR:syntax error at or near "event_id" LINE 1:
(event_id,
When I remove the linefeeds I don't get errors but it does not import
anything.
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 -f.
--
Best Regards,
Tarlika Elisabeth Schmitz
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, tgl@sss.pgh.pa.us
Subject: Re: psql -f COPY from STDIN
In-Reply-To: <20101113120135.6b7fdc9e@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