2000-01-19:修复 NULL 约束条件的处理
25年前的今天(PostgreSQL 7.0 开发周期),NULL 约束条件的处理得到了修复。
commit 6d1efd76fb9852b8bc242dcaf35916090d7c5899 Author: Tom Lane <tgl@sss.pgh.pa.us> Date: Wed Jan 19 23:55:03 2000 +0000 Fix handling of NULL constraint conditions: per SQL92 spec, a NULL result from a constraint condition does not violate the constraint (cf. discussion on pghackers 12/9/99). Implemented by adding a parameter to ExecQual, specifying whether to return TRUE or FALSE when the qual result is really NULL in three-valued boolean logic. Currently, ExecRelCheck is the only caller that asks for TRUE, but if we find any other places that have the wrong response to NULL, it'll be easy to fix them.
例如,给定以下表
postgres=# CREATE TABLE null_constr_cond ( id INT, CHECK (id > 0) ); CREATE TABLE
在此次提交之前,即使列定义允许 NULL
值,也不可能将 NULL
插入 id
列,并且操作会因类似以下的错误而失败:
postgres=# INSERT INTO null_constr_cond VALUES(NULL); ERROR: ExecAppend: rejected due to CHECK constraint $1
附注:直到 PostgreSQL 8.0,诸如约束之类的对象的默认名称是按顺序生成的,例如 $1
、$2
等。