mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-23 17:34:32 +02:00
Added table.extract(rename=) option, refs #42
This commit is contained in:
parent
c755f2852d
commit
c3210f2ffb
3 changed files with 33 additions and 9 deletions
|
|
@ -1136,6 +1136,27 @@ This produces the following schema:
|
|||
[LatinName] TEXT
|
||||
)
|
||||
|
||||
You can use the ``rename=`` argument to rename columns in the lookup table. To create a ``Species`` table with columns called ``name`` and ``latin`` you can do this:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
db["Trees"].extract(
|
||||
["CommonName", "LatinName"],
|
||||
table="Species",
|
||||
fk_column="species_id",
|
||||
rename={"CommonName": "name", "LatinName": "latin"}
|
||||
)
|
||||
|
||||
This produces a lookup table like so:
|
||||
|
||||
.. code-block:: sql
|
||||
|
||||
CREATE TABLE [Species] (
|
||||
[id] INTEGER PRIMARY KEY,
|
||||
[name] TEXT,
|
||||
[latin] TEXT
|
||||
)
|
||||
|
||||
.. _python_api_hash:
|
||||
|
||||
Setting an ID based on the hash of the row contents
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue