最佳答案
运行 COPY
会导致 ERROR: invalid input syntax for integer: ""
错误消息。我遗漏了什么?
我的 /tmp/people.csv
文件:
"age","first_name","last_name"
"23","Ivan","Poupkine"
"","Eugene","Pirogov"
我的 /tmp/csv_test.sql
文件:
CREATE TABLE people (
age integer,
first_name varchar(20),
last_name varchar(20)
);
COPY people
FROM '/tmp/people.csv'
WITH (
FORMAT CSV,
HEADER true,
NULL ''
);
DROP TABLE people;
产出:
$ psql postgres -f /tmp/sql_test.sql
CREATE TABLE
psql:sql_test.sql:13: ERROR: invalid input syntax for integer: ""
CONTEXT: COPY people, line 3, column age: ""
DROP TABLE
问答: