如何在动态查询中使用WITH
语句?例如,对于这样的事情,正确的语法是什么:
// begin function
DECLARE my_var INTEGER;
EXECUTE 'WITH a AS ( SELECT 4 )';
EXECUTE 'SELECT * from a' INTO my_var;
RETURN my_var;
答案 0 :(得分:1)
可能更像是:
EXECUTE 'WITH a AS ( SELECT 4 ) SELECT * from a' INTO my_var;
也不要忘记BEGIN
和END
。
create function foo() returns bar as $$
DECLARE
...
BEGIN
...
END; $$ language plpgsql;