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

When I am running codeDECLAREc int;BEGINexecute 'select count(1) from my_dwh.accounts' into

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744340375a4569365.html

相关推荐

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

    When I am running codeDECLAREc int;BEGINexecute 'select count(1) from my_dwh.accounts' into

    7天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信