Join the Stack Overflow Community
Stack Overflow is a community of 6.7 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I created a huge database in PostgreSQL where I have integer fields that can take NULL values. However when I am trying to import data into the database from a CSV file, it throws me the following error:

ERROR:  invalid input syntax for integer: "NULL"
CONTEXT:  COPY reports_results, line 1, column teacher_id: "NULL"

I am trying to import into the database using the copy command like:

copy  reports_results(test_type_id, teacher_id)
from '/Downloads/mydata.csv';

So what I understood so far is that the database will not accept NULL values in quotes ie. "NULL". But my csv file does not have any quotes wherever the NULL values are present. How do I import them in such cases?

share|improve this question
up vote 2 down vote accepted

Assuming your csv is something like:

1,NULL
2,NULL

Your command would be:

copy  reports_results(test_type_id, teacher_id)
from '/Downloads/mydata.csv';
with NULL as 'NULL'
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.