Learn SQL/Intermediate/NULL Handling/SQL NULL vs Empty String

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

BUSINESS QUESTION

Product normalizes blank feedback comments while preserving meaningful comments.

iduser_idfeature_idratingnps_scorecommentcreated_at
1101159Clear and useful2024-01-25 12:15:00+00
210224NULLExport worked well2024-02-20 15:40:00+00
3103147Helpful setup flow2024-03-18 09:05:00+00
410433NULLNeeds clearer timing2024-04-08 17:30:00+00
EXAMPLE QUERY
SELECT
  id AS feedback_id,
  comment,
  NULLIF(TRIM(comment), '') AS normalized_comment
FROM product.feedback
ORDER BY feedback_id;
RESULT — exact output from the displayed Queryflo rows
feedback_idcommentnormalized_comment
1Clear and usefulClear and useful
2Export worked wellExport worked well
3Helpful setup flowHelpful setup flow
4Needs clearer timingNeeds clearer timing

Every displayed comment is meaningful, so NULLIF preserves each value.

Now You Try

Practice this concept

Product wants blank and whitespace-only feedback comments normalized to NULL.

Available schema
product

Prefix tables with product.table_name.

feedback_idcommentnormalized_comment
product.feedback
ColumnType
idinteger
user_idinteger
feature_idinteger
ratinginteger
nps_scoreinteger
commenttext
created_attimestamp with time zone
moderation_buckettext
query.sql
Intermediate business practice

Sign up free to try it on a real business scenario