Postgresql ss我的关键问题是,假设我们必须在规则中执行此操作,那么如何修改查询以使foobar中的_值列(在规则中的WITH中定义)对SELECT可见?现在_值似乎在规则中传递给SELECT为NULL或VOID。 BEGIN; CREATE OR REPLACE
ss我的关键问题是,假设我们必须在规则中执行此操作,那么如何修改查询以使foobar中的_值列(在规则中的WITH中定义)对SELECT可见?现在_值似乎在规则中传递给SELECT为NULL或VOID。Postgresql ss我的关键问题是,假设我们必须在规则中执行此操作,那么如何修改查询以使foobar中的_值列(在规则中的WITH中定义)对SELECT可见?现在_值似乎在规则中传递给SELECT为NULL或VOID。 BEGIN; CREATE OR REPLACE ,postgresql,subquery,rules,Postgresql,Subquery,Rules,ss我的关键问题是,假设我们必须在规则中执行此操作,那么如何修改查询以使foobar中的_值列(在规则中的WITH中定义)对SELECT可见?现在_值似乎在规则中传递给SELECT为NULL或VOID。 BEGIN; CREATE OR REPLACE FUNCTION debug(anyelement) RETURNS bool AS $$ pg_raise('notice', 'debug(): ' . json_encode($args[0])); RETURN TRUE; $$
BEGIN;
CREATE OR REPLACE FUNCTION debug(anyelement) RETURNS bool AS $$
pg_raise('notice', 'debug(): ' . json_encode($args[0]));
RETURN TRUE;
$$ LANGUAGE PLPHP IMMUTABLE STRICT;
CREATE TABLE foo_table (c1 text);
CREATE OR REPLACE RULE foo_update_rule AS ON UPDATE TO foo_table DO INSTEAD
(
WITH foobar_update AS
(
SELECT unnest('{a,b}'::text[]) AS _value, debug('update_inner'::text)
)
SELECT *, debug('update_outer_1'::text), debug('update_outer_2 -> '::text || _value::text) FROM foobar_update;
SELECT
( ROW(FALSE,FALSE) IN ( SELECT
debug('update2_outer_1'::text), debug('update2_outer_2 -> '::text || _value::text)
FROM ( SELECT unnest('{a,b}'::text[]) AS _value, debug('update_inner'::text) ) AS foobar_update2 ))
);
-----------------------------------------------
WITH foobar_select AS
(
SELECT unnest('{a,b}'::text[]) AS _value, debug('select_inner'::text)
)
SELECT *, debug('select_outer_1'::text), debug('select_outer_2 -> '::text || _value::text), debug('select_outer_3'::text) FROM foobar_select;
UPDATE foo_table SET c1 = NULL where c1 = 'aaa';
ROLLBACK;
NOTICE: plphp: debug(): "select_inner"
NOTICE: plphp: debug(): "select_outer_1"
NOTICE: plphp: debug(): "select_outer_3"
NOTICE: plphp: debug(): "select_outer_2 -> a"
NOTICE: plphp: debug(): "select_outer_2 -> b"
NOTICE: plphp: debug(): "update_inner"
NOTICE: plphp: debug(): "update_outer_1"
NOTICE: plphp: debug(): "update2_outer_1"
NOTICE: plphp: debug(): "update_inner"
NOTICE: plphp: debug(): "update_outer_2 -> a"
NOTICE: plphp: debug(): "update_outer_2 -> b"
NOTICE: plphp: debug(): "update2_outer_2 -> a"
NOTICE: plphp: debug(): "update2_outer_2 -> b"