Re: psql -f COPY from STDIN

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Tarlika Elisabeth Schmitz <postgresql2(at)numerixtechnology(dot)de>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: psql -f COPY from STDIN
Date: 2010-11-13 03:22:11
Message-ID: 8452.1289618531@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Tarlika Elisabeth Schmitz <postgresql2(at)numerixtechnology(dot)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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tarlika Elisabeth Schmitz 2010-11-13 12:01:35 Re: psql -f COPY from STDIN
Previous Message Adrian Klaver 2010-11-12 23:17:59 Re: psql -f COPY from STDIN