admin管理员组文章数量:1401921
When I am running code
DECLARE
c int;
BEGIN
execute 'select count(1) from my_dwh.accounts' into c;
raise notice c;
END;
I am getting error
SQL Error [42601]: ERROR: syntax error at or near "int" in context " c int", at line 3, column 4 Position: 13
Error position: line: 42 pos: 12
What is wrong in that "c int;" ?
When I am running code
DECLARE
c int;
BEGIN
execute 'select count(1) from my_dwh.accounts' into c;
raise notice c;
END;
I am getting error
SQL Error [42601]: ERROR: syntax error at or near "int" in context " c int", at line 3, column 4 Position: 13
Error position: line: 42 pos: 12
What is wrong in that "c int;" ?
Share Improve this question asked Mar 21 at 18:06 AndroidJokerAndroidJoker 411 bronze badge1 Answer
Reset to default 0The declaration of an anonymous block is wrong, you should use DO $$ and END $$. In sql use INTEGER, plpgsql only accepts the integer keyword. This is how you should write.
DO $$
DECLARE
c INTEGER;
BEGIN
EXECUTE 'SELECT count(1) FROM my_dwh.accounts' INTO c;
RAISE NOTICE 'Count: %', c;
END $$;
I hope this is the answer you are looking for.
本文标签: plpgsqlWhat is wrong in this declareStack Overflow
版权声明:本文标题:plpgsql - What is wrong in this declare? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744340374a2601439.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论