How do I declare a variable for use in a PostgreSQL 8.3 query?
In MS SQL Server I can do this:
DECLARE @myvar INT SET @myvar = 5 SELECT * FROM somew
You could also try this in PLPGSQL:
DO $$ DECLARE myvar integer; BEGIN SELECT 5 INTO myvar; DROP TABLE IF EXISTS tmp_table; CREATE TABLE tmp_table AS SELECT * FROM yourtable WHERE id = myvar; END $$; SELECT * FROM tmp_table;
The above requires Postgres 9.0 or later.