相关疑难解决方法(0)

对一组列的NOT NULL约束

我在Postgres有一个表,它目前NOT NULL对它的email列有一个约束.该表还有一个phone可选的列.我想系统接受一些没有记录email,但只有当这些都phoneNOT NULL.换句话说,我需要一个NOT NULL数据库约束,使得CREATE或者UPDATE如果一方或双方的查询没有任何错误成功emailphone字段存在.

进一步扩展上述内容,是否可以在Postgres中指定一组列名,其中一个或多个应该是NOT NULL为了成功更新或创建记录?

sql database postgresql constraints postgresql-9.2

5
推荐指数
2
解决办法
1408
查看次数

设置变量时,记录的IS NOT NULL测试不返回TRUE

使用plpgsql过程提取记录(如果存在),如果存在,则使用它执行某些操作.

变量是一个rowtype:

my_var my_table%rowtype;
Run Code Online (Sandbox Code Playgroud)

我用SQL语句填充它:

select * from my_table where owner_id = 6 into my_var;
Run Code Online (Sandbox Code Playgroud)

我知道它肯定有一行:

raise notice 'my_var is %', my_var;
Run Code Online (Sandbox Code Playgroud)

返回:

NOTICE:  my_var is (383,6,10)
Run Code Online (Sandbox Code Playgroud)

但是现在我想测试一下,如果条件失败,它会得到记录和两者:

if my_var is null then
  raise notice 'IT IS NULL';
end if;
if my_var is not null then
  raise notice 'IT IS NOT NULL';
end if;
Run Code Online (Sandbox Code Playgroud)

这些加注都没有出现在我的消息日志中 - 它只是从不进入块.如果你从一个行收到一行,测试的正确方法是SELECT * INTO什么?

sql postgresql null row plpgsql

3
推荐指数
1
解决办法
800
查看次数

标签 统计

postgresql ×2

sql ×2

constraints ×1

database ×1

null ×1

plpgsql ×1

postgresql-9.2 ×1

row ×1