mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-10 10:34:10 +02:00
Add --extract option to insert/upsert commands
Wires the extracts= Python API feature through the CLI so imports can create lookup tables in one step: --extract species for a table named after the column, or --extract species:Species for a custom name. Closes #352
This commit is contained in:
parent
f34dfb25da
commit
d4d075c924
5 changed files with 111 additions and 0 deletions
25
docs/cli.rst
25
docs/cli.rst
|
|
@ -1445,6 +1445,31 @@ The column type should be one of ``TEXT``, ``INTEGER``, ``FLOAT``, ``REAL`` or `
|
|||
|
||||
As with detected column types, ``--type`` only affects tables created by the command. If the table already exists, its existing column types are left unchanged.
|
||||
|
||||
.. _cli_insert_extract:
|
||||
|
||||
Extracting columns into a separate table
|
||||
-----------------------------------------
|
||||
|
||||
Use ``--extract column-name`` to extract a column out into a separate lookup table during the insert, instead of running a separate :ref:`extract <cli_extract>` command afterwards.
|
||||
|
||||
This can be used more than once, and works with both ``insert`` and ``upsert``:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
sqlite-utils insert trees.db trees trees.csv --csv \
|
||||
--extract species
|
||||
|
||||
This creates a ``species`` lookup table containing one row per distinct value, and replaces the ``species`` column on ``trees`` with a foreign key reference to it.
|
||||
|
||||
To use a different name for the lookup table, add it after a colon:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
sqlite-utils insert trees.db trees trees.csv --csv \
|
||||
--extract species:Species
|
||||
|
||||
See :ref:`python_api_extracts` for more details on how this works, including how ``null`` values are handled.
|
||||
|
||||
To disable type detection and treat all columns as TEXT, use ``--no-detect-types``:
|
||||
|
||||
.. code-block:: bash
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue