mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-23 09:24:31 +02:00
When inserting a CSV file that contains only a header row (no data rows), the --detect-types option would crash with an AssertionError because it tried to transform a table that didn't exist. This fix adds a check to ensure the table exists before attempting to apply type transformations. The fix is applied in two places: 1. insert_upsert_implementation() for the insert command 2. memory() command for CSV/TSV files Added test case: test_insert_csv_headers_only Co-authored-by: Test User <test@example.com>
This commit is contained in:
parent
1a28416e10
commit
2b0cc04c8d
2 changed files with 20 additions and 2 deletions
|
|
@ -1177,7 +1177,7 @@ def insert_upsert_implementation(
|
|||
)
|
||||
else:
|
||||
raise
|
||||
if tracker is not None:
|
||||
if tracker is not None and db.table(table).exists():
|
||||
db.table(table).transform(types=tracker.types)
|
||||
|
||||
# Clean up open file-like objects
|
||||
|
|
@ -2034,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