Question:

I wished to import a CSV file representing nulls as empty strings (nothing 
between the commas).  I observed that the .import command by default imports 
those as empty strings.

A minimalistic example: Let's create a table T with a single column (c) and a 
file containing only one new line (\n) which I named "onenewline".

If you then attempt to import that using the usual import command, the table 
will receive an empty string:

create table T(c);

.mode csv
.import onenewline T

select *,typeof(c) from T;
"",text

A workaround is to add a view with an instead of trigger and target that with 
the import instead:

create view V as select c from T;
create trigger T instead of insert on V begin insert into T select 
nullif(new.c,''); end;

.mode csv
.import onenewline V

select *,typeof(c) from T;
,null

So that works, but I wish there was a more direct method.  Am I missing 
something, or is this the only way?

Thanks,

Jean

Reply via email to