postgresql “(” COPY FROM WITH ( FORMAT csv, DELIMITER E'\t', QUOTE '*', HEADER false, ENCODING 'UTF8') 处或附近的语法错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20545296/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
syntax error at or near "(" COPY FROM WITH ( FORMAT csv, DELIMITER E'\t', QUOTE '*', HEADER false, ENCODING 'UTF8')
提问by Badr4si
I'm Importing data from a txt file This is the table
我正在从 txt 文件中导入数据 这是表格
CREATE TABLE test.geonames_load(geonameid INTEGER PRIMARY KEY,
name VARCHAR(200),
asciiname VARCHAR(200),
alternatenames VARCHAR,
latitude FLOAT8,
longitude FLOAT8,
feature_class char(1),
feature_code VARCHAR(10),
country_code VARCHAR(2),
cc2 VARCHAR(60),
admin1 VARCHAR(20),
admin2 VARCHAR(80),
admin3 VARCHAR(20),
admin4 VARCHAR(20),
population INTEGER,
elevation INTEGER,
dem INTEGER,
timezone VARCHAR(40),
modification VARCHAR(18)
);
After I tried to copy from a txt file
在我尝试从 txt 文件复制之后
COPY test.geonames_load FROM 'C:Program Files/PostgreSQL/8.4/data/US/US.txt' WITH (
FORMAT csv,
DELIMITER E'\t',
QUOTE '*',
HEADER false,
ENCODING 'UTF8'
);
But it shows me an Error
但它向我显示了一个错误
ERROR: syntax error at or near "(" LINE 1: ... FROM 'C:Program Files/PostgreSQL/8.4/data/US/US.txt' WITH ( ^ ********** Error ********** ERROR: syntax error at or near "(" SQL State: 42601 Character: 83
采纳答案by Daniel Vérité
The syntax of COPY
has changed quite a bit in version 9.0 compared to 8.4
COPY
与 8.4 版相比,9.0 版中的语法发生了很大变化
Assuming you're using version 8.4, based on this .../PostgreSQL/8.4/...
path,
the syntax that applies is documented here:
假设您使用的是 8.4 版,根据此.../PostgreSQL/8.4/...
路径,此处记录了适用的语法:
http://www.postgresql.org/docs/8.4/static/sql-copy.html
http://www.postgresql.org/docs/8.4/static/sql-copy.html
And it does not allow any parenthesis after the WITH
keyword that appeared in 9.0, nor the ENCODING
option that appeared in 9.1
并且不允许WITH
在 9.0 中出现的关键字后有任何括号,也不允许ENCODING
出现在 9.1 中的选项
It looks like you need to adapt the statement to your exact version of PostgreSQL.
看起来您需要使语句适应您的 PostgreSQL 的确切版本。