'Where'条件多列组合为一条规则
'Where' condition on the combination of multiple columns for a rule
我是 postgres.I 的新手,需要在我的 table 之一的 postgres 中创建规则。我正在使用 postgres 11.4.
这是我为此使用的语法:
CREATE RULE flagrule AS ON insert TO ms
WHERE NEW.a = OLD.a and new.b = old.b and new.c = old.c and
new.d = old.d and new.e = old.e
DO instead
update ms set flag = 0 where
a = NEW.a and
b= new.b and
c = new.c and
d = new.d and
e = new.e;
并出现以下错误:
SQL Error [42P01]: ERROR: invalid reference to FROM-clause entry for
table "old"
Hint: There is an entry for table "old", but it cannot be referenced
from this part of the query.
Position: 76
我 google 对此有很多了解,但我在 'where' 子句中仅获得了单列条件的示例。如果有人对此有任何想法,请告诉我。任何帮助将不胜感激。
Within <strong>condition</strong>
and <strong>command</strong>
, the special table names NEW
and OLD
can be used to refer to values in the referenced table. NEW
is valid in ON INSERT
and ON UPDATE
rules to refer to the new row being inserted or updated. OLD
is valid in ON UPDATE
and ON DELETE
rules to refer to the existing row being updated or deleted.
由于您正在尝试创建 ON INSERT
规则,因此您不能使用 OLD
。这到底是什么意思?
我是 postgres.I 的新手,需要在我的 table 之一的 postgres 中创建规则。我正在使用 postgres 11.4.
这是我为此使用的语法:
CREATE RULE flagrule AS ON insert TO ms
WHERE NEW.a = OLD.a and new.b = old.b and new.c = old.c and
new.d = old.d and new.e = old.e
DO instead
update ms set flag = 0 where
a = NEW.a and
b= new.b and
c = new.c and
d = new.d and
e = new.e;
并出现以下错误:
SQL Error [42P01]: ERROR: invalid reference to FROM-clause entry for
table "old"
Hint: There is an entry for table "old", but it cannot be referenced
from this part of the query.
Position: 76
我 google 对此有很多了解,但我在 'where' 子句中仅获得了单列条件的示例。如果有人对此有任何想法,请告诉我。任何帮助将不胜感激。
Within
<strong>condition</strong>
and<strong>command</strong>
, the special table namesNEW
andOLD
can be used to refer to values in the referenced table.NEW
is valid inON INSERT
andON UPDATE
rules to refer to the new row being inserted or updated.OLD
is valid inON UPDATE
andON DELETE
rules to refer to the existing row being updated or deleted.
由于您正在尝试创建 ON INSERT
规则,因此您不能使用 OLD
。这到底是什么意思?