Database schema
I have this fields:
Is better set the default value as an empty string '' or a NULL?
For better reading/writing and size-storage performance
The value null represents the absence of any object, while the empty string is an object of type String with zero characters. If you try to compare the two, they are not the same.
NULL values are used to indicate that you could have a value, but you don't know what that value should be yet. They are placeholders until you finally collect the data needed to fill the table field with a real value. You should never confuse NULL values for zeros or blank strings.
They should be avoided to avoid the complexity in select & update queries and also because columns which have constraints like primary or foreign key constraints cannot contain a NULL value.
A NOT NULL constraint in SQL is used to prevent inserting NULL values into the specified column, considering it as a not accepted value for that column. This means that you should provide a valid SQL NOT NULL value to that column in the INSERT or UPDATE statements, as the column will always contain data.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With