5

I was trying to import a CSV file into a PostgreSQL table using the COPY command. The delimiter of the CSV file is comma (,). However, there's also a text field with a comma in the value. For example:

COPY schema.table from '/folder/foo.csv' delimiter ',' CSV header

Here's the content of the foo.csv file:

Name,Description,Age
John,Male\,Tall,30

How to distinguish between the literal comma and the delimiter?

Thanks for your help.

1
  • 1
    The problem is that that's not really CSV. CSV expects delimiter characters to be quoted, and normal CSV doesn't allow for escaping delimiters. See Clodoaldo's answer. Commented Oct 2, 2014 at 15:42

1 Answer 1

5

To have the \ to be recognized as a escape character it is necessary to use the text format

COPY schema.table from '/folder/foo.csv' delimiter ',' TEXT

But then it is also necessary to delete the first line as the HEADER option is only valid for the CSV format.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.