Re: SET variables

From: mlw <markw(at)mohawksoft(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Hackers List <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: SET variables
Date: 2001-05-13 12:31:25
Message-ID: 3AFE7E9C.1E28ECAE@mohawksoft.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Tom Lane wrote:

> mlw <markw(at)mohawksoft(dot)com> writes:
> > Would it be possible to allocate varibles that can be addressed with SET?
>
> And what would you do with them?
>
> There is a simple variable facility in psql these days, if that helps.g

I was thinking more like:

create variable fubar ;

set fubar = select max(column) from table;

select * from table where column = :fubar;

Obviously this is a very simple example. I guess I am asking for something
analogous to temporary tables, but on a single datum level.

I like the way psql does it, but it would be better to have this available in
the native query language.

This is similar to a feature which Oracle has. It is mainly to avoid hitting
the query planner. Oracle caches query execution instructions, and using a
variable is a way to reuse cached queries with different data.

Being able to set variables and use them in queries may help some people port
from Oracle to Postgres.

BTW I am also working on the impression that a view is more efficient than
reissuing a complex query. Or is there no difference?

>
>
> regards, tom lane
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://www.postgresql.org/search.mpl

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2001-05-13 15:03:54 Re: Why do we use Tcl's compiler and flags?
Previous Message Peter Eisentraut 2001-05-13 10:11:12 Re: Why do we use Tcl's compiler and flags?