SQL NULL vs Empty String
An empty string '' is a real, zero-length piece of text — a known value. NULL is the absence of any text value whatsoever. Postgres treats these as genuinely distinct.
What & Why
A text column holding '' (empty string) has an actual, known value — it's just zero characters long. A text column holding NULL has no value recorded at all. Postgres keeps these strictly separate: '' IS NULL evaluates to FALSE, and '' = NULL evaluates to NULL (unknown), never TRUE.
See How It Works
Product normalizes blank feedback comments while preserving meaningful comments.
| id | user_id | feature_id | rating | nps_score | comment | created_at |
|---|---|---|---|---|---|---|
| 1 | 101 | 1 | 5 | 9 | Clear and useful | 2024-01-25 12:15:00+00 |
| 2 | 102 | 2 | 4 | NULL | Export worked well | 2024-02-20 15:40:00+00 |
| 3 | 103 | 1 | 4 | 7 | Helpful setup flow | 2024-03-18 09:05:00+00 |
| 4 | 104 | 3 | 3 | NULL | Needs clearer timing | 2024-04-08 17:30:00+00 |
SELECT
id AS feedback_id,
comment,
NULLIF(TRIM(comment), '') AS normalized_comment
FROM product.feedback
ORDER BY feedback_id;| feedback_id | comment | normalized_comment |
|---|---|---|
| 1 | Clear and useful | Clear and useful |
| 2 | Export worked well | Export worked well |
| 3 | Helpful setup flow | Helpful setup flow |
| 4 | Needs clearer timing | Needs clearer timing |
Every displayed comment is meaningful, so NULLIF preserves each value.
Practice this concept
Product wants blank and whitespace-only feedback comments normalized to NULL.
productPrefix tables with product.table_name.
feedback_idcommentnormalized_commentproduct.feedback| Column | Type |
|---|---|
| id | integer |
| user_id | integer |
| feature_id | integer |
| rating | integer |
| nps_score | integer |
| comment | text |
| created_at | timestamp with time zone |
| moderation_bucket | text |
Sign up free to try it on a real business scenario