小编use*_*071的帖子

到底什么时候检查 IMMEDIATE 约束以及 Postgres 中的“语句”到底是什么?

我目前对立即约束检查的确切时间感到困惑。希望下面的例子能解决我的困惑:

create table a (
  id int primary key
);

create table b (
  id int primary key,
  a_id int not null references a
);

/* violates foreign key constraint "b_a_id_fkey" */
with t1 as (insert into b values (100, 200) returning id, a_id)
  select * from t1;

/* ERROR: expensive_exception_thrower */
with t1 as (insert into b values (100, 200) returning id, a_id)
  select * from t1 where expensive_exception_thrower(t1.a_id) = true;
Run Code Online (Sandbox Code Playgroud)

在第二个查询中,尽管引用了 t1,但expensive_exception_thrower仍会首先抛出其异常,这会导致 fkey 异常被吞没。当然,有解决方法,但是当 Postgres …

postgresql constraint

4
推荐指数
1
解决办法
626
查看次数

标签 统计

constraint ×1

postgresql ×1