HiveBrain v1.2.0
Get Started
← Back to all entries
principleCritical

When to use NULL and when to use an empty string?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
nullemptywhenandusestring

Problem

I'm interested mainly in MySQL and PostgreSQL, but you could answer the following in general:

  • Is there a logical scenario in which it would be useful to distinguish an empty string from NULL?



-
What would be the physical storage implications for storing an empty string as...

  • NULL?



  • Empty String?



  • Another field?



  • Any other way?

Solution

Let's say that the record comes from a form to gather name and address information. Line 2 of the address will typically be blank if the user doesn't live in apartment. An empty string in this case is perfectly valid. I tend to prefer to use NULL to mean that the value is unknown or not given.

I don't believe the physical storage difference is worth worrying about in practice. As database administrators, we have much bigger fish to fry!

Context

StackExchange Database Administrators Q#59, answer score: 90

Revisions (0)

No revisions yet.