Running SQL script through psql gives syntax errors that are not found in PgAdmin

I have the following script to create a table:

-- Create State table.
DROP TABLE IF EXISTS "State" CASCADE;
CREATE TABLE "State" (
 StateID SERIAL PRIMARY KEY NOT NULL,
 StateName VARCHAR(50)
);

It works great in the PgAdmin query tool. But when I try to run it from the command line using psql:

psql -U postgres -d dbname -f 00101-CreateStateTable.sql

I get a syntax error as shown below.

2: ERROR:  syntax error at or near ""
LINE 1: 
        ^
psql:00101-CreateStateTable.sql:6: NOTICE:  CREATE TABLE will create implicit sequence "State_stateid_seq" for serial column "State.stateid"
psql:00101-CreateStateTable.sql:6: NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "State_pkey" for table "State"
CREATE TABLE

Why am I getting a syntax error using psql and not with PGAdmin?

Yours faithfully

Peter

+5
source share
4 answers

Run the 00101-CreateStateTable.sql file through a hex dump truck. I bet you have a UTF-16 marker at the beginning of the file (before the comment characters "-").

+10

BOM Ubuntu, bomstrip, bomstrip-files

+3

(-s) ? IF EXISTS 8.2, , 8.1 psql.

0

, . . SQL- PSQL. , , , . bomstrip Ubuntu, SQL- .

0

All Articles