1pa
1pa

Reputation: 735

Wrong copy command output with postgres

I'm trying to use the copy command to copy the content of a file into a database. One of the lines have this:

CCc1ccc(cc1)C(=O)/N=c\1/n(ccs1)C

and when i insert this normally into database there is no errors.

But when i'm trying to use the following command, this line is not insert correctly.

cat smile_test.txt | psql -c "copy testzincsmile(smile) from stdout" teste

This i what i get (it is wrong):

CCc1ccc(cc1)C(=O)/N=c/n(ccs1)C

What's wrong here?

Thank you :)

Upvotes: 0

Views: 81

Answers (2)

1pa
1pa

Reputation: 735

I figure out how to do this:

This is my answer:

cat smile_test.txt | sed '1d; s/\\/\\\\/g' | psql -c "copy testzincsmile(smile) from stdout" teste

Upvotes: 0

Craig Ringer
Craig Ringer

Reputation: 324285

copy expects a specific input format and cannot just be used to read random text from a file into a field.

See the manual.

The specific issue you're hitting is probably a backslash being interpreted as an escape by the default copy in/out format.

Upvotes: 1

Related Questions