开发者

Nullable natural id?

Can I add a unique constraint 开发者_JS百科to natural id fields, so that only non-null values should be unique, but allow for multiple nulls?


Yes. It sounds like this is the default behavior, according to the docs

In general, a unique constraint is violated when there are two or more rows in the table where the values of all of the columns included in the constraint are equal. However, null values are not considered equal in this comparison. That means even in the presence of a unique constraint it is possible to store duplicate rows that contain a null value in at least one of the constrained columns. This behavior conforms to the SQL standard, but we have heard that other SQL databases may not follow this rule. So be careful when developing applications that are intended to be portable.

http://www.postgresql.org/docs/8.1/static/ddl-constraints.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜