I am fairly new to Postgres and I cannot believe how difficult I am finding just to declare a variable. I did come across other SO posts, but none of them helped in my situation. All I want is to write the a script like below in postgres:
declare @age int = 10;
select * from person p where p.age > @age;
Based on the SO post here, I tried:
DO
$$
DECLARE
overTheAgeOf int := 15;
BEGIN
select *
from person
where age > overTheAgeOf;
END
$$;
This gives me error: [42601] ERROR: query has no destination for result data
Then I tried returning the result of the script:
return (select *
from person
where age > overTheAgeOf);
That gave me another error: ERROR: RETURN cannot have a parameter in function returning void
How do declare a variable and use it in script(s) that follows?