2

I am using pgloader to import from a .csv file which has empty strings in double quotes. A sample line is

12334,0,"MAIL","CA","","Sanfransisco","TX","","",""

After a successful import, the fields that has double quotes ("") are shown as two single quotes('') in postgres database.

Is there a way we can insert a null or even empty string in place of two single quotes('')?

I am using the arguments -

WITH truncate,
           fields optionally enclosed by '"',
           fields escaped by double-quote,
           fields terminated by ','
SET client_encoding to 'UTF-8',
           work_mem to '12MB',
           standard_conforming_strings to 'on'

I tried using 'empty-string-to-null' mentioned in the documentation like this -

CAST column enumerate.fax using empty-string-to-null

But it gives me an error saying -

pgloader nph_opr_addr.test.load An unhandled error condition has been signalled: At LOAD CSV

^ (Line 1, Column 0, Position 0) Could not parse subexpression ";" when parsing

Oxi
  • 2,918
  • 17
  • 28
Jehoshuah
  • 671
  • 2
  • 9
  • 20

1 Answers1

0

Use the field option:

null if blanks

Something like this:

...
having fields foo, bar, mynullcol null if blanks, baz

From the documentation:

null if

This option takes an argument which is either the keyword blanks or a double-quoted string.

When blanks is used and the field value that is read contains only space characters, then it's automatically converted to an SQL NULL value.

When a double-quoted string is used and that string is read as the field value, then the field value is automatically converted to an SQL NULL value

Bohemian
  • 412,405
  • 93
  • 575
  • 722
  • Thanks that was what I needed. dimitri also gave a details explanation at https://github.com/dimitri/pgloader/issues/334 – Jehoshuah Feb 05 '16 at 13:07