Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 25C4A1337B6C for ; Sat, 13 Nov 2010 08:29:15 -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 30875-07 for ; Sat, 13 Nov 2010 12:29:09 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from zebedee.cranntara.net (zebedee.cranntara.net [91.186.7.79]) by mail.postgresql.org (Postfix) with ESMTP id 6F9361337B58 for ; Sat, 13 Nov 2010 08:29:06 -0400 (AST) Received: from [88.210.158.208] (helo=bolek.coachhouse) by zebedee.cranntara.net with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1PHFE6-00025L-CF; Sat, 13 Nov 2010 12:29:04 +0000 Received: from [192.168.0.32] (helo=dick.coachhouse ident=tarlika) by bolek.coachhouse with esmtp (Exim 4.69) (envelope-from ) id 1PHEnY-0007gN-BK; Sat, 13 Nov 2010 12:01:36 +0000 Date: Sat, 13 Nov 2010 12:01:35 +0000 From: Tarlika Elisabeth Schmitz To: Tom Lane Cc: pgsql-sql@postgresql.org Subject: Re: psql -f COPY from STDIN Message-ID: <20101113120135.6b7fdc9e@dick.coachhouse> In-Reply-To: <8452.1289618531@sss.pgh.pa.us> References: <20101112220340.36a0bc75@dick.coachhouse> <8452.1289618531@sss.pgh.pa.us> X-Mailer: Claws Mail 3.5.0 (GTK+ 2.12.12; i486-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-5 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201011/24 X-Sequence-Number: 34762 On Fri, 12 Nov 2010 22:22:11 -0500 Tom Lane wrote: >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 > >> 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