Re: implicit vs. explicit RETURN when OUT is used - Mailing list pgsql-general

From Ivan Sergio Borgonovo
Subject Re: implicit vs. explicit RETURN when OUT is used
Date
Msg-id 20080106120858.53916c94@webthatworks.it
Whole thread Raw
In response to Re: implicit vs. explicit RETURN when OUT is used  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
On Sun, 06 Jan 2008 02:47:17 -0500
Tom Lane <tgl@sss.pgh.pa.us> wrote:

> Ivan Sergio Borgonovo <mail@webthatworks.it> writes:
> > But when I switch to
> > select into _BasketID1,_BasketID2 _BasketID1,_BasketID2 from
> > testA(); nothing get back from testB().
>
> I think you've forgotten that plpgsql variables will be substituted
> for, wherever they appear.  The above is just an extremely expensive
> form of
>     _BasketID1 := _BasketID1;
>     _BasketID2 := _BasketID2;
> ie, a big no-op.

> The general rule of thumb is not to name plpgsql parameters or
> variables the same as fields you'll need to reference in the
> queries in the function.

I've found a solution that is somehow elegant and unexpected:
"aliasing" the function name.

select a.field1, a.field2 into field1, field2 from testfunc() as a;

The online documentation doesn't give postgresql the honour it
deserves.

Things like this can't be found even on voluminous books as "The
Postgresql reference manual".
If you're not a Postgres guru you may think that pg doesn't shine for
anything other than things just "data paranoids" can appreciate but
force you to live with "strangeness" like "ILIKE" and no syntactical
sugar.
It's plenty of syntactical sugar. It is just hidden in poetry like
this:

"Except for the INTO clause, the SELECT statement is the same as a
normal SQL SELECT command and can use its full power."

http://www.postgresql.org/docs/8.1/static/plpgsql-statements.html#PLPGSQL-SELECT-INTO

--
Ivan Sergio Borgonovo
http://www.webthatworks.it


pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: implicit vs. explicit RETURN when OUT is used
Next
From: Clodoaldo
Date:
Subject: Re: Performance problem. Could it be related to 8.3-beta4?