Re: implicit vs. explicit RETURN when OUT is used

Поиск
Список
Период
Сортировка
От Ivan Sergio Borgonovo
Тема Re: implicit vs. explicit RETURN when OUT is used
Дата
Msg-id 20080106120858.53916c94@webthatworks.it
обсуждение исходный текст
Ответ на Re: implicit vs. explicit RETURN when OUT is used  (Tom Lane <tgl@sss.pgh.pa.us>)
Список 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 по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: implicit vs. explicit RETURN when OUT is used
Следующее
От: Clodoaldo
Дата:
Сообщение: Re: Performance problem. Could it be related to 8.3-beta4?