我试着在下面的代码示例中模拟我的问题.在下面的代码中,我正在执行select * from test一个过程.我们知道,我们必须使用perform关键字.这非常有效:
perform * from test;
Run Code Online (Sandbox Code Playgroud)
但是,如果我尝试将该简单查询重写为CTE,我无法使其正常工作.我收到语法错误.
with test_as_cte as(select * from test) perform * from test_as_cte;
Run Code Online (Sandbox Code Playgroud)
这可能吗?什么是正确的语法?我尝试了几种替代方案并通过文档,但到目前为止没有任何成功.
(请注意,这只是解释我的问题的一个例子.我知道查询没有任何意义.)
create table test
(
key int primary key
);
create function test() returns trigger as
$$
begin
raise notice 'hello there';
-- this does work
perform * from test;
-- this doesn't work
with test_as_cte as(select * from test) perform * from test_as_cte;
return new;
end;
$$
language plpgsql;
create trigger test after insert on …Run Code Online (Sandbox Code Playgroud)