0

I am trying to declare a variable in PostgreSQL. No matter what I do, it's always a syntax error.

declare x integer := 1;
x := 1;
declare x := 1;
@declare x := 1;

Yes, I know variables only work in queries written in plpgsql. I've read this answer everywhere, but no explanation whatsoever on how to switch to it. Can please someone explain it to me in very simple terms?

1 Answer 1

1

What do you plan to do with x?

do language plpgsql
$$
declare x int := 1;
begin
  raise notice '%', x;
end
$$
;

NOTICE:  1
DO

Sign up to request clarification or add additional context in comments.

2 Comments

Now I got it, I have to declare a function. Thank you, sir!
@TamásPolgár This is not a function. It is a do block.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.