Re: BUG #6271: psql -f reporting unexpected syntax errors on first command

From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Shannon <shannon(at)arc(dot)net(dot)au>
Cc: Pg Bugs <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #6271: psql -f reporting unexpected syntax errors on first command
Date: 2011-10-26 16:50:29
Message-ID: 1319647711-sup-4649@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs


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 "<feff>SHOW"
> LINE 1: <feff>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 <alvherre(at)commandprompt(dot)com>
The PostgreSQL Company - Command Prompt, Inc.
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Kevin Grittner 2011-10-26 17:13:20 Re: BUG #6269: Anomaly detection
Previous Message Peter Eisentraut 2011-10-26 16:39:14 Re: BUG #6271: psql -f reporting unexpected syntax errors on first command