kushwah_a
kushwah_a

Reputation: 135

Copy NULL in PostgreSQL database

I am trying to copy a CSV file into Postgres 9.5.3 and running into issues with NULL. The file is encoded in ASCII, my client_encoding is UTF-8, and server encoding is UTF-8. The null is in a quoted string as shown below.

enter image description here

I get this error

ERROR:  invalid byte sequence for encoding "UTF8": 0x00
CONTEXT:  COPY test_null, line 1
********** Error **********

ERROR: invalid byte sequence for encoding "UTF8": 0x00
SQL state: 22021
Context: COPY test_null, line 1

My table structure is

CREATE TABLE TEST_NULL(NULLCOLUMN CHAR(10));

copy TEST_NULL from 'F:\User Area\DCS.TXT' csv  NULL AS 'null';

I have tried escaping it by specifying "\", and tried other options of Copy command, but nothing seems to work. Not sure, how to process this.

Upvotes: 2

Views: 683

Answers (1)

Laurenz Albe
Laurenz Albe

Reputation: 246818

Your file contains ASCII 0 characters, which are rejected by PostgreSQL.

You'll have to use some other representation for NULL values if you want to load them into the database with COPY.

Upvotes: 2

Related Questions