1

I've been given some CSV data I need to load into a PostgreSQL table with the following format:

7227, {text with, commas}, 10.0, 3.0, text with no commas

I want my table rows to appear as:

   7227 | text with, commas | 10.0 | 3.0 | text with no commas

How can I use COPY and get it to ignore commas between the brackets?

I'm trying to avoid pre-processing the file, although that is an option.

1 Answer 1

2

I'm afraid you'll have to edit the file. This format should be ok:

7227, "text with, commas", 10.0, 3.0, text with no commas

Alternatively

7227, text with\, commas, 10.0, 3.0, text with no commas

according to this principle in the documentation:

Backslash characters (\) can be used in the COPY data to quote data characters that might otherwise be taken as row or column delimiters. In particular, the following characters must be preceded by a backslash if they appear as part of a column value: backslash itself, newline, carriage return, and the current delimiter character.

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

Comments

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.