2

When using the \copy command with psql I have a file with empty values. These values are not to be null but instead always an empty string.

My command:

\copy agltransact FROM 'dbo_agltransact.csv' with null as '' CSV HEADER;

The error I get:

ERROR:  null value in column "apar_id" violates not-null constraint

I have this data:

account,amount,apar_id,apar_type
14015,3000000.000,,1
14015,3000000.000,,2

I want the next to last columns to be an empty string.

1

Figured it out. I need to escape and output the single quotes

\copy agltransact FROM 'dbo_agltransact.csv' with null as E'\'\'' CSV HEADER;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.