Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 389851337B58 for ; Sat, 13 Nov 2010 11:29:10 -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 21572-03 for ; Sat, 13 Nov 2010 15:29:04 +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 B2EF81337990 for ; Sat, 13 Nov 2010 11:29:02 -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 1PHI2G-0003BW-Ka for pgsql-sql@postgresql.org; Sat, 13 Nov 2010 15:29:02 +0000 Received: from [192.168.0.32] (helo=dick.coachhouse ident=tarlika) by bolek.coachhouse with esmtp (Exim 4.69) (envelope-from ) id 1PHHe7-0007sl-3h for pgsql-sql@postgresql.org; Sat, 13 Nov 2010 15:04:03 +0000 Date: Sat, 13 Nov 2010 15:04:02 +0000 From: Tarlika Elisabeth Schmitz To: pgsql-sql@postgresql.org Subject: Re: psql -f COPY from STDIN Message-ID: <20101113150402.67e3ddfe@dick.coachhouse> In-Reply-To: <20101113120135.6b7fdc9e@dick.coachhouse> References: <20101112220340.36a0bc75@dick.coachhouse> <8452.1289618531@sss.pgh.pa.us> <20101113120135.6b7fdc9e@dick.coachhouse> 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/26 X-Sequence-Number: 34764 On Sat, 13 Nov 2010 12:01:35 +0000 Tarlika Elisabeth Schmitz wrote: >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 "STDIN: All rows are read from the same source that issued the command" - As I understand now, this applies to both COPY and \COPY. In other words the input file must contain command and data. I have found a few solutions to achieve my objective: 1) using COPY FROM STDIN cat event.csv | psql -c "$(cat event.sql)" 2) using COPY FROM STDIN psql -f <(cat event.sql event.csv) 3) using \COPY FROM PSTDIN cat event.csv | psql -f event.sql 4) using \COPY FROM STDIN psql -f <(cat event.sql event.csv <(echo "\.")) What I don't like about \COPY is that it has to be on one line. Indeed it can't be split over multiple lines, Tom, not with backslash either. \COPY FROM STDIN requires the data to be terminated with "\." whereas COPY is happy with EOF. I'll go for 2) because it allows me to format the COPY command over multiple lines. -- Best Regards, Tarlika Elisabeth Schmitz