Re: PL/PgSQL: stmt_fors and variable value after loop

From: Marko Tiikkaja <marko(at)joh(dot)to>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PG Docs <pgsql-docs(at)postgresql(dot)org>
Subject: Re: PL/PgSQL: stmt_fors and variable value after loop
Date: 2015-01-19 16:33:59
Message-ID: 54BD31F7.3040505@joh.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

On 1/19/15 5:24 PM, Tom Lane wrote:
> Marko Tiikkaja <marko(at)joh(dot)to> writes:
>> 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?

The balance is in a string meant for human consumption, so I'd have to
not only dig into the JSON but also extract the relevant portion of that
string using string manipulation. Even worse, in the future these
values might be encrypted, so option #4 isn't even available.

.marko

In response to

Browse pgsql-docs by date

  From Date Subject
Next Message Marko Tiikkaja 2015-01-19 17:10:59 Re: PL/PgSQL: stmt_fors and variable value after loop
Previous Message Tom Lane 2015-01-19 16:24:04 Re: PL/PgSQL: stmt_fors and variable value after loop