I am new to PostgreSQL and am using the query tool in PGAdmin. I'm trying to run pgsql queries that use variables, but I can't seem to get the syntax right.
Here's a sample query that gives a syntax error:
DECLARE
num INTEGER;
BEGIN
num := 3;
PRINT num;
END;
Update:
Ok, let me try and explain. I come from a SQL server background. In the management studio, I can open a query window and play with (T)-SQL queries.
For example, I can write something like this:
DECLARE @num INT
SET @num = 3
SELECT @num
I know this is a dumb example, but I'm just trying to declare a variable and do something with it. I'm trying to familiarise myself with PL/PGSQL.
Update, again:
It's me again. I'm trying the script below and get a "[ERROR ] 7.0-2: syntax error, unexpected character". Is this meant to work in PGAdmin?
DECLARE
num INTEGER;
BEGIN
num := 3;
RAISE NOTICE '%', num;
END;