Skip to content

sqlite-utils transform should set empty strings to null when converting text columns to integer/float #488

@simonw

Description

@simonw
/tmp % echo "id,age,weight\n1,3,2.5\n2,," | sqlite-utils insert test.db test - --csv
/tmp % sqlite-utils schema test.db                                                  
CREATE TABLE [test] (
   [id] TEXT,
   [age] TEXT,
   [weight] TEXT
);
/tmp % sqlite-utils transform test.db test --type age integer --type weight float   
/tmp % sqlite-utils schema test.db                                               
CREATE TABLE "test" (
   [id] TEXT,
   [age] INTEGER,
   [weight] FLOAT
);
/tmp % sqlite-utils rows test.db test
[{"id": "1", "age": 3, "weight": 2.5},
 {"id": "2", "age": "", "weight": ""}]

It would be neat if this resulted in the following instead:

 {"id": "2", "age": null, "weight": null}

Related Discord discussion: https://discord.com/channels/823971286308356157/823971286941302908/1019635490833567794

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions