d_a*_*a_n 4 postgresql constraints
Postgres 9.3
我有两个整数类型列“a”和“b”。有效选项有:
我正在尝试添加一个检查/约束来防止无效选项:
我将不胜感激任何帮助。
预先感谢丹
create table t (
a int,
b int,
check (
a is null and b is null
or
a is not null and b is null
or
a is not null and b is not null
)
);
insert into t (a, b) values
(null, null),
(1, null),
(1, 1),
(null, 1);
ERROR: new row for relation "t" violates check constraint "t_check"
DETAIL: Failing row contains (null, 1).
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3611 次 |
| 最近记录: |