Dev Helpers

SQL / Conditional values

Convert an empty field to null

Dev Helpers · September 1, 2025

An empty string and NULL communicate different conditions. NULLIF can normalize an empty import field where the schema expects a missing value.

Worked example

SELECT nullif('','') AS missing;

Result

[
  {
    "missing": null
  }
]

Implementation notes

Whitespace-only values remain nonempty after NULLIF with an empty literal. Trim first only if surrounding whitespace is not part of the field's meaning.

Try it yourself

Compare an empty string, a space and a genuine NULL.

Open the SQL example →

Editorial date September 1, 2025 · Published December 6, 2026

Related articles

Compare two literal lists

Set operations compare rows under SQL's rules for duplicates. Check whether the result represents membership or the number of occurrences.

Count jobs per active day

Grouping timestamps by day produces counts only for days present in the data. A continuous chart may need a calendar series as well.