How to specify a tab in a postgres front-end COPY

Chris Curvey picture Chris Curvey · May 24, 2011 · Viewed 64.3k times · Source

I would like to use the psql "\copy" command to pull data from a tab-delimited file into Postgres. I'm using this command:

\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?

Answer

Seth Robertson picture Seth Robertson · May 24, 2011

Use E'\t' to tell postgresql there may be escaped characters in there:

\copy cm_state from 'state.data' with delimiter E'\t' null as ';'