sparkle sparkle - 10 months ago 42
SQL Question

Is better use an empty value as a '' or as NULL?

Database schema

I have this fields:

  • title (string)

  • subtitle

  • description (string)

Is better set the default value as an empty string '' or a NULL?

For better reading/writing and size-storage performance


The usual contract is:

  • NULL means "no information available".
  • '' means "there is information available. It's just empty."

Beyond this point there is much philosophical discussion since the invention of NULL in any language, not just SQL.

The only technical point here is: In PostgreSQL NULL can be stored more efficiently than a string of length zero. If that really matters in your case ... we cannot know.