gpt4 book ai didi

postgresql - 可空的自然 id?

转载 作者:行者123 更新时间:2023-11-29 13:06:58 25 4
gpt4 key购买 nike

我能否向自然 ID 字段添加唯一约束,以便只有非空值应该是唯一的,但允许多个空值?

最佳答案

。根据文档,这听起来像是默认行为

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

关于postgresql - 可空的自然 id?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6906754/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com