How can I get missing values recorded as NULL when importing from csv

你。 提交于 2019-12-05 12:01:07

sqlite3 imports values as text and there does not seem to be a way to make it treat empty values as nulls.

However, you can update the tables yourself after import, setting empty strings to nulls, like

UPDATE t SET a1=NULL WHERE a1='';

Repeat for each column.

You can also create a trigger for such updates:

CREATE TRIGGER trig_a1 AFTER INSERT ON t WHEN new.a1='' BEGIN
  UPDATE t SET a1=NULL WHERE rowid=new.rowid;
END;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!