Postgres COPY TO NULL integers

2019-01-27 17:40发布

I have a CSV that contains various columns. One of the columns contains integer data. However, when running a copy to:

COPY soc 
FROM '~/soc.asc'
WITH DELIMITER '$';

I'm getting the following:

ERROR:  invalid input syntax for integer: ""
CONTEXT:  COPY soc, line 1, column soc_code: ""

as it appears that Postgres is trying to stick an empty string in an integer. How can I fix this? I don't really want to fudge my schema to suit the import if it can be helped.

1条回答
萌系小妹纸
2楼-- · 2019-01-27 18:06

You can tell postgres to interpret some value as NULL, for example:

COPY soc FROM '~/soc.asc' WITH DELIMITER AS '$' NULL AS ''
查看更多
登录 后发表回答