mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-08-14 21:34:09 +02:00
transform: coerce empty strings to NULL when converting TEXT columns to numeric types (#805)
* transform: coerce empty strings to NULL when converting TEXT columns to numeric types When a TEXT column is transformed to INTEGER, FLOAT, or REAL and a row contains an empty string, the empty string is now converted to NULL during the INSERT...SELECT copy, matching the expected behavior described in #488. Fixes #488
This commit is contained in:
parent
75ba588462
commit
e4935e0644
5 changed files with 57 additions and 5 deletions
|
|
@ -1826,6 +1826,8 @@ To alter the type of a column, use the ``types=`` argument:
|
|||
# Convert the 'age' column to an integer, and 'weight' to a float
|
||||
table.transform(types={"age": int, "weight": float})
|
||||
|
||||
When a ``TEXT`` column is changed to ``INTEGER``, ``FLOAT`` or ``REAL``, exact empty-string values are stored as ``NULL``. Other values, including whitespace-only strings, are copied normally.
|
||||
|
||||
See :ref:`python_api_add_column` for a list of available types.
|
||||
|
||||
.. _python_api_transform_strict:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue