Re: implicit vs. explicit RETURN when OUT is used

From: Ivan Sergio Borgonovo <mail(at)webthatworks(dot)it>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: implicit vs. explicit RETURN when OUT is used
Date: 2008-01-06 11:08:58
Message-ID: 20080106120858.53916c94@webthatworks.it
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sun, 06 Jan 2008 02:47:17 -0500
Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> Ivan Sergio Borgonovo <mail(at)webthatworks(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Clodoaldo 2008-01-06 11:26:07 8.3-beta4, analyze and db owner
Previous Message Clodoaldo 2008-01-06 11:06:38 Re: Performance problem. Could it be related to 8.3-beta4?