加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

postgresql – SQL子查询在检查约束

发布时间:2020-12-13 16:44:13 所属栏目:百科 来源:网络整理
导读:我可以在Check约束中创建SQL子查询吗? 我有一个post表与列id,所有者 我有另一个表操作与列user_id,post_id 表用户的列ID post_id – post.id和user_id – user.id also post.owner – 用户名 现在我想约束post(post_id).id!= user_id对表操作 这怎么可能
我可以在Check约束中创建SQL子查询吗?

我有一个post表与列id,所有者
我有另一个表操作与列user_id,post_id
表用户的列ID

post_id – > post.id和user_id – > user.id also post.owner – >用户名

现在我想约束post(post_id).id!= user_id对表操作

这怎么可能?

不支持在CHECK约束中超出当前行。

http://www.postgresql.org/docs/9.1/interactive/sql-createtable.html说:

A check constraint specified as a column constraint should reference
that column’s value only,while an expression appearing in a table
constraint can reference multiple columns.

Currently,CHECK expressions cannot contain subqueries nor refer to
variables other than columns of the current row.

有这个限制的好理由,但如果你喜欢在交通繁忙的独轮车骑车时,你可以颠覆使用功能的限制。这种情况下,不会回来咬你是罕见的;你可以更安全地在触发代码中强制使用不变量。

http://www.postgresql.org/docs/9.1/interactive/triggers.html

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读