1

I am trying to copy the contents of a dat file to a table in PostgreSQL but getting errors. The dat file has the following:

1,'"{{text}}","{{NoName}}":"{test},{OneName}:{test}"'

Table Schema:

Create Table TestInfo (ID int, TestValues text);

I run the following query:

COPY Test from '/opt/Data/TestInfo.dat' WITH DELIMITER AS ',' NULL AS '';

but get the following error

ERROR:  extra data after last expected column

Even tried

COPY Test from '/opt/Data/TestInfo.dat' WITH DELIMITER AS ',' csv;

still the same error.... Can some one please help me getting the contents of the dat file copied to the DB?

Thanks

1 Answer 1

1

I suspect this is because because the default quote character for the copy command in Postgres is a double quote, and it appears in your csv, it's a single quote instead.

Try this:

COPY Test from '/opt/Data/TestInfo.dat' WITH DELIMITER AS ',' QUOTE AS '''' NULL AS '';

Note the need to escape the single quote, resulting in 4 single quotes.

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

2 Comments

Worked like a charm.. Thanks
Sure, no problem.

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.