You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/cli.rst
+30Lines changed: 30 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1078,6 +1078,36 @@ The command will fail if you reference columns that do not exist on the table. T
1078
1078
.. note::
1079
1079
``upsert`` in sqlite-utils 1.x worked like ``insert ... --replace`` does in 2.x. See `issue #66 <https://github.com/simonw/sqlite-utils/issues/66>`__ for details of this change.
1080
1080
1081
+
1082
+
.. _cli_bulk:
1083
+
1084
+
Executing SQL in bulk
1085
+
=====================
1086
+
1087
+
If you have a JSON, newline-delimited JSON, CSV or TSV file you can execute a bulk SQL query using each of the records in that file using the ``sqlite-utils bulk`` command.
1088
+
1089
+
The command takes the database file, the SQL to be executed and the file containing records to be used when evaluating the SQL query.
1090
+
1091
+
The SQL query should include ``:named`` parameters that match the keys in the records.
1092
+
1093
+
For example, given a ``chickens.csv`` CSV file containing the following::
1094
+
1095
+
id,name
1096
+
1,Blue
1097
+
2,Snowy
1098
+
3,Azi
1099
+
4,Lila
1100
+
5,Suna
1101
+
6,Cardi
1102
+
1103
+
You could insert those rows into a pre-created ``chickens`` table like so::
1104
+
1105
+
$ sqlite-utils bulk chickens.db \
1106
+
'insert into chickens (id, name) values (:id, :name)' \
1107
+
chickens.csv --csv
1108
+
1109
+
This command takes the same options as the ``sqlite-utils insert`` command - so it defaults to expecting JSON but can accept other formats using ``--csv`` or ``--tsv`` or ``--nl`` or other options described above.
0 commit comments