最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plpgsql - What is wrong in this declare? - Stack Overflow

programmeradmin7浏览0评论

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 badge
Add a comment  | 

1 Answer 1

Reset to default 0

The 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.

发布评论

评论列表(0)

  1. 暂无评论