Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 432A51337B8B for ; Fri, 12 Nov 2010 23:22:25 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 00814-03 for ; Sat, 13 Nov 2010 03:22:19 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id B05371337B79 for ; Fri, 12 Nov 2010 23:22:17 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id oAD3MBQ9008453; Fri, 12 Nov 2010 22:22:11 -0500 (EST) To: Tarlika Elisabeth Schmitz cc: pgsql-sql@postgresql.org Subject: Re: psql -f COPY from STDIN In-reply-to: <20101112220340.36a0bc75@dick.coachhouse> References: <20101112220340.36a0bc75@dick.coachhouse> Comments: In-reply-to Tarlika Elisabeth Schmitz message dated "Fri, 12 Nov 2010 22:03:40 +0000" Date: Fri, 12 Nov 2010 22:22:11 -0500 Message-ID: <8452.1289618531@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201011/23 X-Sequence-Number: 34761 Tarlika Elisabeth Schmitz 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