Skip to main content

Privacy First

CSV to SQL UPSERT

Generate SQL UPSERTs from CSV

Generate upsert statements from CSV for PostgreSQL (INSERT ... ON CONFLICT), MySQL/MariaDB (INSERT ... ON DUPLICATE KEY UPDATE), or Microsoft SQL Server (MERGE ... WHEN MATCHED). Choose conflict target columns, choose which columns to update on conflict, and review the output before running. Composite conflict targets are supported.

Example output

INSERT INTO customers ("customer_id", "email", "status")
VALUES (123, 'ada@example.com', 'active')
ON CONFLICT ("customer_id")
DO UPDATE SET
  "email" = EXCLUDED."email",
  "status" = EXCLUDED."status";
Your file is processed locally in your browser and is never uploaded to WebF1.

Import CSV

Drag and drop a CSV file here, or

Paste CSV text instead

Validation

  • At least one conflict target column is required for UPSERT.

Review before running

Generated SQL can modify or overwrite data. Review all output, test in a non-production environment, and make a backup before running it.CSV Data Handyman does not execute SQL or connect to any database.

Frequently asked questions

What is a SQL UPSERT?
An UPSERT inserts a row, and if a conflict is detected on the conflict target columns, it either updates the conflicting row or does nothing. PostgreSQL spells this as INSERT ... ON CONFLICT (...) DO UPDATE SET ... or DO NOTHING. MySQL/MariaDB uses INSERT ... ON DUPLICATE KEY UPDATE. Microsoft SQL Server uses MERGE ... WHEN MATCHED THEN UPDATE.
Which dialects are supported?
PostgreSQL, MySQL/MariaDB, and Microsoft SQL Server. Pick the dialect in the output settings; the page defaults to PostgreSQL.
What is a conflict target?
The column or columns whose unique constraint determines whether a conflict happens, typically a primary key or unique index. At least one conflict target is required.
Can I use a composite conflict target?
Yes. Select multiple columns as conflict targets and they appear in ON CONFLICT (col1, col2).
What happens if I select no update columns?
When no columns are selected for update, CSV Data Handyman generates ON CONFLICT (...) DO NOTHING (PostgreSQL), INSERT IGNORE (MySQL), or a MERGE with no WHEN MATCHED clause (MSSQL), all of which silently skip conflicting rows.
Is the generated SQL safe to run?
Review it first, test in a non-production environment, and make a backup. CSV Data Handyman does not execute SQL or connect to any database; it only generates text.

Related tools

  • CSV to JSON

    Convert CSV rows to a JSON array with renamed and nested fields.

  • CSV to XML

    Convert CSV rows to XML with configurable root and row elements.

  • CSV to SQL INSERT

    Generate INSERT statements from CSV rows for PostgreSQL, MySQL/MariaDB, and Microsoft SQL Server.

  • CSV to SQL UPDATE

    Generate UPDATE statements with required WHERE keys for PostgreSQL, MySQL/MariaDB, and Microsoft SQL Server.

  • CSV Column Mapper

    Rename, reorder, transform, and map CSV columns for export.