Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id B01C7B5D803 for ; Wed, 26 Oct 2011 13:50:41 -0300 (ADT) 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 12009-09 for ; Wed, 26 Oct 2011 16:50:35 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from lists.commandprompt.com (host-215.commandprompt.net [207.173.203.215]) by mail.postgresql.org (Postfix) with ESMTP id 593D8B5DCF4 for ; Wed, 26 Oct 2011 13:50:34 -0300 (ADT) Received: from perhan.alvh.no-ip.org (spinlock.commandprompt.com.commandprompt.com [207.173.203.215]) by lists.commandprompt.com (Postfix) with ESMTPA id 6B1C634C393; Wed, 26 Oct 2011 09:50:32 -0700 (PDT) Received: from perhan.alvh.no-ip.org ([200.85.200.200] helo=perhan.alvh.no-ip.org) by assp.commandprompt.com with ESMTP (2.0.1); 26 Oct 2011 09:50:29 -0700 Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 167766E5B6; Wed, 26 Oct 2011 13:50:29 -0300 (CLST) Content-Type: text/plain; charset=UTF-8 Cc: Pg Bugs Subject: Re: BUG #6271: psql -f reporting unexpected syntax errors on first command From: Alvaro Herrera To: Shannon In-reply-to: <201110260408.p9Q480jo087565@wwwmaster.postgresql.org> References: <201110260408.p9Q480jo087565@wwwmaster.postgresql.org> Date: Wed, 26 Oct 2011 13:50:29 -0300 Message-Id: <1319647711-sup-4649@alvh.no-ip.org> User-Agent: Sup/git Content-Transfer-Encoding: 8bit X-Assp-Version: 2.0.1(3.2.15) on assp.commandprompt.com X-Assp-Client-TLS: yes X-Assp-ID: assp.commandprompt.com m1-47832-00328 X-Assp-Original-Subject: Re: [BUGS] BUG #6271: psql -f reporting unexpected syntax errors on first command 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: 201110/251 X-Sequence-Number: 31521 Excerpts from Shannon's message of mié oct 26 01:08:00 -0300 2011: > Given the following 2 line SQL script in a file: > > --- test.sql --- > SHOW client_encoding; > SHOW client_encoding; > ---------------- > > $ psql -ftest.sql -U postgres template1 > > psql:test.sql:1: ERROR: syntax error at or near "SHOW" > LINE 1: SHOW client_encoding; > ^ > client_encoding > ----------------- > UTF8 > (1 row) > > > See what happened there? The first line is treated as a syntax error and the > second line works which is insane because the two lines are identical! They are not identical -- the first line contains a BOM, which I actually see in the error messages you pasted (but you likely don't): > psql:test.sql:1: ERROR: syntax error at or near "SHOW" > LINE 1: SHOW client_encoding; This is being hidden from you by your text editor. You need to remove those bytes before passing the file to psql. -- Álvaro Herrera The PostgreSQL Company - Command Prompt, Inc. PostgreSQL Replication, Consulting, Custom Development, 24x7 support