postgresql Postgres COPY TO NULL 整数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10821068/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Postgres COPY TO NULL integers
提问by Neil Middleton
I have a CSV that contains various columns. One of the columns contains integer data. However, when running a copy to:
我有一个包含各种列的 CSV。其中一列包含整数数据。但是,当运行副本时:
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.
因为看起来 Postgres 试图在一个整数中粘贴一个空字符串。我怎样才能解决这个问题?如果可以帮助,我真的不想捏造我的模式以适应导入。
回答by valodzka
You can tell postgres to interpret some value as NULL, for example:
您可以告诉 postgres 将某些值解释为 NULL,例如:
COPY soc FROM '~/soc.asc' WITH DELIMITER AS '$' NULL AS ''