最好使用一个空值作为一个“”或者为NULL?

问题描述:

数据库架构

我有以下字段:


  • title(string)

  • subtitle

  • description(string)

最好将默认值设置为空字符串 NULL

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

通常的合同是:


  • NULL 表示没有可用的信息。


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

超出这一点自从 NULL 在任何语言中发明而不仅仅是SQL之后,还有许多哲学讨论。

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

唯一的技术点这里是:在PostgreSQL NULL 可以比长度为零的字符串更有效地存储。如果这在你的情况真的很重要...我们不知道。

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.