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
{{ message }}
Repository navigation
Import a file as UPDATE or UPSERT instead of INSERT #2521
Importing CSV, TSV, JSON or XLSX rows only inserts. Every batch goes to insertRows (apple/Plugins/TableProPluginKit/RowImportRunner.swift:87-95), and the one other choice is Delete existing rows before import, which empties the table first (features/import-export.mdx:383-385). Emptying loses every row the file does not carry and breaks foreign keys that point at the table.
So refreshing a table from a corrected file means writing the UPDATE statements by hand. There is no way to match rows on a key and update only the columns the file carries.
SQL export already writes each engine's form for rows that exist: skip, replace or update, as INSERT IGNORE and REPLACE INTO on MySQL and MariaDB, INSERT OR IGNORE and INSERT OR REPLACE on SQLite, and ON CONFLICT on PostgreSQL (features/import-export.mdx:123, :147). Import has nothing like it.
Proposed solution
A mode on the import sheet: Insert, Update, Upsert, or Insert and Skip Existing.
A key selector, defaulting to the primary key, that matches file columns to it. A unique index can stand in for the key.
Update writes only the columns mapped in the sheet and leaves the rest alone.
Upsert uses the engine's own form, the ones SQL export already writes, plus MERGE on SQL Server and Oracle. Where the engine has none, fall back to a select-then-write per batch, and say so in the sheet.
The summary reports matched, updated, inserted and skipped rows separately, and Skip and Continue reports a row whose key matched more than one row.
Done when: a 10,000-row CSV holding 500 new and 9,500 changed rows lands correctly in Update and Upsert modes on PostgreSQL, MySQL, SQLite and SQL Server, with each count right in the summary.
Alternatives considered
Load the file into a staging table and write the UPDATE by hand.
Activity