postgresql 如何在 postgres 前端 COPY 中指定选项卡
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6113115/
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
How to specify a tab in a postgres front-end COPY
提问by Chris Curvey
I would like to use the psql "\copy" command to pull data from a tab-delimited file into Postgres. I'm using this command:
我想使用 psql "\copy" 命令将数据从制表符分隔的文件中提取到 Postgres。我正在使用这个命令:
\copy cm_state from 'state.data' with delimiter '\t' null as ;
But I'm getting this warning (the table actually loads fine):
但是我收到了这个警告(表格实际上加载得很好):
WARNING: nonstandard use of escape in a string literal
LINE 1: COPY cm_state FROM STDIN DELIMITER '\t' NULL AS ';'
HINT: Use the escape string syntax for escapes, e.g., E'\r\n'.
How do I specify a tab if '\t' is not correct?
如果 '\t' 不正确,如何指定选项卡?
回答by Seth Robertson
Use E'\t'
to tell postgresql there may be escaped characters in there:
用E'\t'
告诉的PostgreSQL有可能被转义字符有:
\copy cm_state from 'state.data' with delimiter E'\t' null as ;
回答by user4372693
you can do this copy cm_state from stdin with (format 'text')
你可以这样做 copy cm_state from stdin with (format 'text')