Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YDFHE-0004WJ-KU for pgsql-docs@arkaria.postgresql.org; Mon, 19 Jan 2015 16:34:08 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YDFHE-0004ur-3p for pgsql-docs@arkaria.postgresql.org; Mon, 19 Jan 2015 16:34:08 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YDFHD-0004rv-4L for pgsql-docs@postgresql.org; Mon, 19 Jan 2015 16:34:07 +0000 Received: from mail-wg0-f46.google.com ([74.125.82.46]) by magus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1YDFH9-0003MW-BE for pgsql-docs@postgresql.org; Mon, 19 Jan 2015 16:34:05 +0000 Received: by mail-wg0-f46.google.com with SMTP id x13so32687430wgg.5 for ; Mon, 19 Jan 2015 08:34:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-type :content-transfer-encoding; bh=VIy8blkI2UArJw9O7ZHQHM2gMce652EhiHhuIwsHQMg=; b=CqwPkwevVbabnGWKLEwErRUw15xlcr2jAX5SGCZiyFl7d+7kehS538fOQWx9mozfsz i9iTuy+v42r4GeSou+5qWdMU5JQgrMmZM9Kby/VyhijFVmzWGg7Ppg4XrMF5QedVjrWd GG9stNLWVEyClRHemzLqOYDUoxVQd7T2ltBCdI924AVsHo8mPV2OxI2pEazIOH7nWzN8 VqJovPMbtxmykyskvIAYy7QG3DhdUkbEFaICGX0my4HiE40tBU4GzoJot7Y75NA7C40/ 0mAt4v6QmCDlgkzCSwxd2x1zbfeGBE33G1THGBYhfe4NREY4qlz9RZK/DDpOdoB8m6dA 3PVw== X-Gm-Message-State: ALoCoQnAha2/xr7IJXin47FLPFBmRorYo0ZRha/SANMT267RyN/RYoqI9YUKfvROVg6v0oB21fnA X-Received: by 10.194.222.136 with SMTP id qm8mr17128484wjc.116.1421685240724; Mon, 19 Jan 2015 08:34:00 -0800 (PST) Received: from Markos-MacBook-Pro.local ([46.246.117.202]) by mx.google.com with ESMTPSA id u9sm17872843wjy.37.2015.01.19.08.34.00 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Jan 2015 08:34:00 -0800 (PST) Message-ID: <54BD31F7.3040505@joh.to> Date: Mon, 19 Jan 2015 17:33:59 +0100 From: Marko Tiikkaja User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: Tom Lane CC: PG Docs Subject: Re: PL/PgSQL: stmt_fors and variable value after loop References: <54BD24C1.4060601@joh.to> <26441.1421682246@sss.pgh.pa.us> <54BD2E05.2090004@joh.to> <27460.1421684644@sss.pgh.pa.us> In-Reply-To: <27460.1421684644@sss.pgh.pa.us> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-docs Precedence: bulk Sender: pgsql-docs-owner@postgresql.org On 1/19/15 5:24 PM, Tom Lane wrote: > Marko Tiikkaja 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 -- Sent via pgsql-docs mailing list (pgsql-docs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-docs