Re: [DOCS] PL/PgSQL: stmt_fors and variable value after loop

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: [DOCS] PL/PgSQL: stmt_fors and variable value after loop
Дата
Msg-id 27460.1421684644@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: PL/PgSQL: stmt_fors and variable value after loop  (Marko Tiikkaja <marko@joh.to>)
Ответы Re: [DOCS] PL/PgSQL: stmt_fors and variable value after loop  (Marko Tiikkaja <marko@joh.to>)
Список pgsql-docs
Marko Tiikkaja <marko@joh.to> writes:
> On 1/19/15 4:44 PM, Tom Lane wrote:
>> It seems to me that to do so would mostly be to encourage sloppy
>> programming practices, at the price of constraining future implementation
>> changes.  Can you give a compelling example of a non-kluge usage for
>> such an assumption?

> What I'm doing would look something like this:
> ...
> Available workarounds right now would be, as far as I can tell:

>    1) Have separate variables which I assign to inside the loop, and use
> those in case the loop found exactly one row
>    2) Aggregate the (currency, balance) pairs into an array first, and
> decide based on the array's cardinality what to do
>    3) Use a count(*) OVER () inside the query and EXIT if that count is 1
>    4) Extract the values back from the sole element in the
> _AvailableAccounts array

> I don't particularly like any of those.

I would have said that (4) would be the natural thing.  What have you
got against it?

            regards, tom lane


--
Sent via pgsql-docs mailing list (pgsql-docs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-docs


В списке pgsql-docs по дате отправления:

Предыдущее
От: Marko Tiikkaja
Дата:
Сообщение: Re: [DOCS] PL/PgSQL: stmt_fors and variable value after loop
Следующее
От: Marko Tiikkaja
Дата:
Сообщение: Re: [DOCS] PL/PgSQL: stmt_fors and variable value after loop