Skip to content

[P1][bug] CSV import turns every empty cell into NULL, which is a choice the file cannot express #578

Closed

Description

@EVWorth

What

generateBatchInsert writes an empty cell as SQL NULL:

if (value === "") {
  return "NULL";
}

CSV distinguishes ,, from ,"", — an absent value from an empty string — but csv-parser.ts returns string[][], so both arrive here as "" and the distinction is already gone by the time this decision is made.

Why it matters

Two different failures, depending on the column:

  • NOT NULL column — the import fails on a row the user considers valid, with an error naming NULL when their file contained an empty string.
  • Nullable column — the import succeeds and stores NULL where the file said "". Silent, and only visible later to whatever reads the column and distinguishes the two.

Neither is unreasonable as a default; both are unreasonable as a decision made invisibly.

Suggested fix

Two parts, and the first is required for the second to be possible:

  1. Keep the distinction in the parser. parseCSVLine knows whether a field was quoted; that information is discarded when it returns a plain string. Returning something that preserves "was quoted" (or a null for a bare empty field) puts the choice back in reach.
  2. Let the user pick, with a sensible default — the import dialog already has a CSV options block. The conventional default is bare empty → NULL, quoted empty → "", which is what mysqlimport and most ETL tools do.

Worth doing together with #366, which also wants changes in the parser.

Where it stands

Documented at the call site rather than left implicit, as part of the #364 work — the comment names this issue so the next reader knows it is a choice and not an oversight.

Activity

  1. added
    kind/bug
    area/import
    on Sep 9, 2026
  2. EVWorth commented on Sep 12, 2026

    @EVWorth
    OwnerAuthor

    Already fixed — recording the check rather than the change.

    parseCSVLine keeps whether each field was quoted (bareEmpty), parseCSV carries it through, and generateBatchInsert uses it:

    • ,, → NULL
    • ,"", → ''
    • a short row's missing cells → NULL, since an absent cell is absent

    That is mysqlimport's convention and the default this issue proposed. Tests in csv-parser.test.ts pin the flags, and sql-import.test.ts pins what each becomes in the INSERT.

    No option is exposed, and deliberately: this issue's own framing was "a choice the file cannot express", and the file can now express it. An override would only matter for a file that quotes every field including the empty ones, where the writer has said "empty string" and meant it — which is what we would then be overriding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/importkind/bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions