taga
taga

Reputation: 3895

Cannot read CSV file with pgAdmin,

I want to read CSV file thats on my desktop named "tripdata". I wrote a code but I always get this error:

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

I do not know whats the problem. I read at the same way other CSV files.

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;

Upvotes: 1

Views: 86

Answers (1)

madflow
madflow

Reputation: 8520

I believe you will have to tell COPY what NULL is.

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.

So in your case:

COPY ... NULL AS 'NULL';

Upvotes: 2

Related Questions