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.