From: Tom Lane <tgl@sss.pgh.pa.us>
To: Tarlika Elisabeth Schmitz <postgresql2@numerixtechnology.de>
Cc: pgsql-sql@postgresql.org
Subject: Re: psql -f COPY from STDIN
Date: Fri, 12 Nov 2010 22:22:11 -0500
Message-ID: <8452.1289618531@sss.pgh.pa.us> (raw)
In-Reply-To: <20101112220340.36a0bc75@dick.coachhouse>
References: <20101112220340.36a0bc75@dick.coachhouse>
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 (no error messages
> either):
> event.sql:
> COPY (event_id, event_name) FROM STDIN DELIMITER AS ',' NULL AS ''
> cat event.csv | psql -f event.sql
I believe that psql's interpretation of "stdin" when reading from a file
is that the COPY data is to come from that same file (look at the script
produced by pg_dump for an example). So it reads to the end of the
file, which is right away --- otherwise you'd get some incorrect-data
errors. The data sourced from the cat command is never noticed at all.
I think you can get the effect you're after using \copy ... from pstdin.
See the psql man page.
regards, tom lane
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: tgl@sss.pgh.pa.us, postgresql2@numerixtechnology.de
Subject: Re: psql -f COPY from STDIN
In-Reply-To: <8452.1289618531@sss.pgh.pa.us>
* 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