mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-19 15:04:10 +02:00
Skip type detection when CSV insert created no table
Closes #702. A CSV that's only a header row leaves insert_all with no rows, so no table gets created. The follow-up transform(types=tracker.types) hit the 'Cannot transform a table that doesn't exist yet' assertion. Guard both insert paths on the table actually existing. Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
This commit is contained in:
parent
8f0c06e188
commit
0c5e9eb104
2 changed files with 19 additions and 2 deletions
|
|
@ -1175,7 +1175,9 @@ def insert_upsert_implementation(
|
|||
)
|
||||
else:
|
||||
raise
|
||||
if tracker is not None:
|
||||
if tracker is not None and db.table(table).exists():
|
||||
# A header-only CSV creates no table, so there is nothing to
|
||||
# retype - skip the transform to avoid the assertion in it.
|
||||
db.table(table).transform(types=tracker.types)
|
||||
|
||||
# Clean up open file-like objects
|
||||
|
|
@ -2032,7 +2034,7 @@ def memory(
|
|||
rows = (_flatten(row) for row in rows)
|
||||
|
||||
db.table(file_table).insert_all(rows, alter=True)
|
||||
if tracker is not None:
|
||||
if tracker is not None and db.table(file_table).exists():
|
||||
db.table(file_table).transform(types=tracker.types)
|
||||
# Add convenient t / t1 / t2 views
|
||||
view_names = ["t{}".format(i + 1)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue