Skip to content
Advertisement

Data type when reading from a TSV-file (postgresql)

Im reading data from a tsv-file to a postgresql table. The problem I have is that in one column (death year) it is either a year or N if the actor is not dead yet. If i try to use INTEGER as data type I get an error because of the N. Do anyone know how to solve this?

This is my table:

CREATE TABLE name_mock(nconst VARCHAR, primaryName VARCHAR, birthYear INTEGER, deathYear INTEGER, primaryProfession VARCHAR, knownForTitles VARCHAR);

Then I import the data from the csv-file:

COPY name_mock FROM '/home/pathtofile/name.basics.tsv' DELIMITER E't' CSV HEADER;

And I get the following error:

ERROR:  invalid input syntax for type integer: "N"
CONTEXT:  COPY name_mock, line 4, column deathyear: "N"

Thank you.

Advertisement

Answer

COPY takes a parameter, NULL.

Please try this:

COPY name_mock FROM '/home/pathtofile/name.basics.tsv' DELIMITER E't' NULL 'N' CSV HEADER;
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement