Re: SET variables - Mailing list pgsql-hackers

From mlw
Subject Re: SET variables
Date
Msg-id 3AFE7E9C.1E28ECAE@mohawksoft.com
Whole thread Raw
In response to SET variables  (mlw <markw@mohawksoft.com>)
Responses Re: SET variables
List pgsql-hackers
Tom Lane wrote:

> mlw <markw@mohawksoft.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



pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: Why do we use Tcl's compiler and flags?
Next
From: Tom Lane
Date:
Subject: Re: Why do we use Tcl's compiler and flags?