How to declare a variable in a postgresql query in sql language ?
How to declare a variable in a postgresql query in sql language ?
От:
Sara Harris <sarah@ips.gov.il>
Дата:
In MS SQL Server I can do this: DECLARE @myvar INT 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; |
Re: How to declare a variable in a postgresql query in sql language ?
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Sara Harris writes: > 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? You don't. You need to use plpgsql if you need declared variables. In practice, if you're coding in a style that would require local variables, you're almost certainly going to need plpgsql anyway, since plain SQL hasn't got any control structures either. regards, tom lane