通过psql运行SQL脚本会给出PgAdmin中不会发生的语法错误 [英] Running SQL script through psql gives syntax errors that don't occur in PgAdmin
本文介绍了通过psql运行SQL脚本会给出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)
);
它在PgAdmin的查询工具中运行良好。但是,当我尝试使用psql从命令行运行它时:
It runs fine in the query tool of PgAdmin. 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
为什么我使用psql而不是使用语法得到语法错误pgAdmin?
Why do I get a syntax error using psql and not with pgAdmin?
推荐答案
通过十六进制转储程序运行文件00101-CreateStateTable.sql。我敢打赌,您会在文件开头(在-注释字符之前)使用UTF-16标记。
Run your file 00101-CreateStateTable.sql through a hex dumper. I'll bet you have a UTF-16 marker at the beginning of the file (before the "--" comment characters).
这篇关于通过psql运行SQL脚本会给出PgAdmin中不会发生的语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文