How to declare a variable in a postgresql query in sql language ?

From: Sara Harris <sarah(at)ips(dot)gov(dot)il>
To: "pgsql-novice(at)postgresql(dot)org" <pgsql-novice(at)postgresql(dot)org>
Subject: How to declare a variable in a postgresql query in sql language ?
Date: 2012-01-01 10:56:14
Message-ID: 5FB88A6E864A254D8E81C2CB9707E8E88E355A54@RMLMB2.ips.gov.il
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

In MS SQL Server I can do this:

DECLARE @myvar INT
SET @myvar = 5

SELECT *
FROM somewhere
WHERE something = @myvar

How do I do the same in PostgreSQL in sql language? According to the documentation are declared simply as "name type;", but this gives me a syntax error:

myvar INTEGER;

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Andreas Kretschmer 2012-01-01 11:52:04 Re: is it normal behavior of index?
Previous Message Jean-Yves F. Barbier 2012-01-01 05:08:39 is it normal behavior of index?