无法使用 pgAdmin 读取 CSV 文件,

Cannot read CSV file with pgAdmin,

我想读取我桌面上名为 "tripdata" 的 CSV 文件。我写了一个代码,但我总是得到这个错误:

ERROR:  invalid input syntax for integer: "NULL"
CONTEXT:  COPY tripdata, line 4, column birth_year: "NULL"
SQL state: 22P02

我不知道是什么问题。我以同样的方式阅读其他 CSV 文件。

CREATE TABLE public."tripdata"  (tripduration integer,
                starttime timestamp,
                stoptime timestamp,
                start_station_id integer,
                start_station_name varchar(100),
                start_station_latitude float,
                start_station_longituder float,
                end_station_id integer,
                end_station_name varchar(100),
                end_station_latitude float,
                end_station_longituder float,
                bikeid integer,
                usertime varchar(100),
                birth_year integer,
                gender varchar(100));

SELECT * FROM public."tripdata";
COPY public."tripdata" FROM 'C:\Users\Pc\Desktop\tripdata.csv' DELIMITER ',' CSV HEADER;

select * from tripdata;

我相信你必须告诉 COPY NULL 是什么。

https://www.postgresql.org/docs/10/sql-copy.html

NULL Specifies the string that represents a null value. The default is \N (backslash-N) in text format, and an unquoted empty string in CSV format.

所以在你的情况下:

COPY ... NULL AS 'NULL';