Re: [HACKERS] variables in psql - Mailing list pgsql-hackers

From Tom Lane
Subject Re: [HACKERS] variables in psql
Date
Msg-id 23775.928272369@sss.pgh.pa.us
Whole thread Raw
In response to variables in psql  (Keala Jacobs <keala_jacobs@itd.sterling.com>)
List pgsql-hackers
Keala Jacobs <keala_jacobs@itd.sterling.com> writes:
> Does postgres support the use of variables as in the example below?

> update table1 set column1=@variable
> where column2='text4column2'
> and @variable=(select column3 from table2 where column4='text4column4');

> If not, how do I execute a statement like this in postgres?

That isn't a particularly compelling example, since it looks like what
you mean is the same as

update table1 set column1 = table2.column3
where table1.column2 = 'text4column2' and table2.column4 = 'text4column4';

I have seen examples where it'd be nice to have an SQL variable that
could hold a value from one statement to the next; currently you have
to do that with a temporary table, which seems rather cumbersome...

BTW, I think this'd be more appropriate in pgsql-sql.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Peter T Mount
Date:
Subject: Re: [HACKERS] Re: [SQL] Column name's length
Next
From: Tom Lane
Date:
Subject: Re: [HACKERS] Re: [SQL] Column name's length