--empty-null option for CSV and TSV imports, closes #563

This commit is contained in:
Simon Willison 2023-07-02 22:42:26 -07:00
commit f7af23837d
5 changed files with 55 additions and 2 deletions

View file

@ -266,6 +266,7 @@ See :ref:`cli_inserting_data`, :ref:`cli_insert_csv_tsv`, :ref:`cli_insert_unstr
--nl Expect newline-delimited JSON
-c, --csv Expect CSV input
--tsv Expect TSV input
--empty-null Treat empty strings as NULL
--lines Treat each line as a single value called 'line'
--text Treat input as a single value called 'text'
--convert TEXT Python code to convert each item
@ -321,6 +322,7 @@ See :ref:`cli_upsert`.
--nl Expect newline-delimited JSON
-c, --csv Expect CSV input
--tsv Expect TSV input
--empty-null Treat empty strings as NULL
--lines Treat each line as a single value called 'line'
--text Treat input as a single value called 'text'
--convert TEXT Python code to convert each item
@ -372,6 +374,7 @@ See :ref:`cli_bulk`.
--nl Expect newline-delimited JSON
-c, --csv Expect CSV input
--tsv Expect TSV input
--empty-null Treat empty strings as NULL
--lines Treat each line as a single value called 'line'
--text Treat input as a single value called 'text'
--convert TEXT Python code to convert each item

View file

@ -1281,6 +1281,22 @@ You can set the ``SQLITE_UTILS_DETECT_TYPES`` environment variable if you want `
export SQLITE_UTILS_DETECT_TYPES=1
If a CSV or TSV file includes empty cells, like this one:
.. code-block:: csv
name,age,weight
Cleo,6,
Dori,,3.5
They will be imported into SQLite as empty string values, ``""``.
To import them as ``NULL`` values instead, use the ``--empty-null`` option:
.. code-block:: bash
sqlite-utils insert creatures.db creatures creatures.csv --csv --empty-null
.. _cli_insert_csv_tsv_delimiter:
Alternative delimiters and quote characters