如何在postgres前端COPY中指定选项卡

Chr*_*vey 71 postgresql

我想使用psql"\ copy"命令将制表符分隔文件中的数据提取到Postgres中.我正在使用此命令:

\copy cm_state from 'state.data' with delimiter '\t' null as ;
Run Code Online (Sandbox Code Playgroud)

但是我收到了这个警告(表格实际加载正常):

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'.
Run Code Online (Sandbox Code Playgroud)

如果'\ t'不正确,如何指定标签?

Set*_*son 165

使用E'\t'在那儿告诉PostgreSQL的有可能被转义字符:

\copy cm_state from 'state.data' with delimiter E'\t' null as ;
Run Code Online (Sandbox Code Playgroud)

  • 谢谢!这也解决了信息量较小的错误`COPY分隔符必须是单个单字节字符`.在这里添加它,以便搜索引擎可以接收它. (10认同)

use*_*693 5

you can do this copy cm_state from stdin with (format 'text')

  • 文本文件的默认分隔符是制表符..我已经使用了它并且它有效.. https://www.postgresql.org/docs/9.2/static/sql-copy.html (2认同)