1

I try to import a text file into a single column table, i.e. I don't want a single line of the source file to be delimited into columns. The file contains many different characters (tabs, commas, spaces) that could be recognized as delimiters. Since bell (CHR(7)) doesn't exist in the data file I chose it as delimiter:

COPY data_table(single_column) FROM '/tmp/data' WITH ENCODING 'LATIN1' DELIMITER CHR(7);

Unfortunately, this results in an error:

ERROR: syntax error at or near "chr"

What would be the correct syntax?

2
  • which version of postgresql are you using? Commented Sep 23, 2021 at 11:15
  • psql --version returns psql (PostgreSQL) 13.4 (Ubuntu 13.4-0ubuntu0.21.04.1) Commented Sep 23, 2021 at 11:17

1 Answer 1

2

You can't use a function there. Use the escape notation.

 DELIMITER E'\007'
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! That's much better than using a hex editor to get the bell character into the script...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.