Fixes for upsert() and upsert_all():
table.upsert_all()no longer overwrites existing values withNULLwhen records in the same batch have different keys. Each record now only updates the columns it provides. (#873)table.upsert()andtable.upsert_all()no longer raiseIntegrityErrorwhen updating an existing row with a record that omits aNOT NULLcolumn that has no default. An upsert that would create a new row without that column still raises the error. (#878)- SQL
conversions=are now applied once when an upsert updates an existing row. Previously they were applied twice, so a conversion such as? * 100stored the wrong value. Thanks, Sanidhya Saluja. (#946, #947)
Fixes for full-text search:
table.enable_fts(..., fts_version="FTS4", create_triggers=True)now creates triggers that work. Previously any update or delete of an indexed row raisedsqlite3.OperationalError: SQLlogic error. Existing FTS4 tables keep their old triggers until you runtable.enable_fts(...,replace=True)orsqlite-utils enable-fts ... --replace. With the new FTS4 triggers a row that is skipped byUPDATE OR IGNOREis removed from the search index. Thanks, Caldera. (#922, #923)table.detect_fts()no longer treats_and%in a table name as wildcards, which could causetable.search()to use the search index belonging to a different table. Thanks, Ilya Khalafi. (#930, #931)table.enable_fts(),table.search()andtable.search_sql()now accept an iterator or generator of column names. Thanks, Syed Ahnaf Raza. Thanks, Pengyi Peng. (#902, #903, #942, #943)
Other fixes:
- Carriage returns inside quoted CSV and TSV fields are now preserved on import. Previously
\r\nand\rinside a quoted value were stored as\n. This affectssqlite-utils insert --csv,--tsv,sqlite-utils memoryandrows_from_file(). Thanks, Agustin Saiz. (#895, #897) table.transform()now preservesCOLLATEclauses on columns. Previously aTEXT COLLATENOCASEcolumn silently became case-sensitive after any transform. Thanks, Yewan Moon. (#954, #955)table.transform(not_null={"column": False})no longer adds aNOT NULLconstraint to a column that was already nullable. (#944)- Calling
table.convert()more than once with different callables that share a name, such as twodict.getmethods, now runs the correct callable each time. Thanks, Zihan Dai. (#910, #911) - numpy integer and floating point scalars such as
np.int64(5)are now stored as SQLite integers and floats. Previously they were stored asBLOBvalues. Thanks, Tanbir Hossain Ramim. (#876, #877) table.analyze_column()andsqlite-utils analyze-tablesnow handle columns containingNULLvalues correctly. They previously reported wrong counts, could raiseTypeErrorwhen counts were tied and could omit values from the results.analyze-tables --savenow stores a JSONnullfor a null value where it used to store the string"None". (#887)rows_from_file()now respectsignore_extras=andextras_key=for TSV files and for files where the format is detected automatically. (#892)table.insert_all(..., truncate=True)andsqlite-utils insert --truncatenow delete the existing rows when the new input is empty, for example a JSON[]or a CSV file with only a header row. Previously the existing rows were left in place. Thanks, Peter Olkhovets. (#935, #936)sqlite-utils rows --limit 0now returns no rows. Previously it returned every row in the table. Thanks, LucioLiu. (#964, #965)rows_from_file()now closes the buffered reader it creates when detecting the format of a JSON file, avoiding aResourceWarning.