Re: Variables in PostgreSQL? [was: Is my MySQL Gaining?]

Bruno Wolff III <bruno@wolff.to>

From: Bruno Wolff III <bruno@wolff.to>
To: Casey Allen Shobe <cshobe@softhome.net>
Cc: pgsql-general@postgresql.org
Date: 2003-12-29T04:02:35Z
Lists: pgsql-hackers
On Sun, Dec 28, 2003 at 12:57:10 -0500,
  Casey Allen Shobe <cshobe@softhome.net> wrote:
> 
> Ahh, I have seen those...but they're specific to psql, and if memory serves me 
> correct I wasn't able to use the variables within queries, either.  I need 
> something I can use over ODBC (within a single transaction, of course).  
> These can sometimes solve problems that you can't seem to solve any other 
> way, and other times can improve query response time *greatly* (say, by 
> running a subquery once and assigning the result to a variable used 40 times 
> in the final statement instead of running 40 subqueries).

You should be handle to this case by using the subselect query in the from
clause and then doing a join to make the value available where needed.