Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YDF7c-00047V-00 for pgsql-docs@arkaria.postgresql.org; Mon, 19 Jan 2015 16:24:12 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YDF7b-0004FO-1O for pgsql-docs@arkaria.postgresql.org; Mon, 19 Jan 2015 16:24:11 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YDF7Z-0004FD-Uu for pgsql-docs@postgresql.org; Mon, 19 Jan 2015 16:24:10 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YDF7W-0003FX-RZ for pgsql-docs@postgresql.org; Mon, 19 Jan 2015 16:24:08 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id t0JGO4VL027461; Mon, 19 Jan 2015 11:24:04 -0500 From: Tom Lane To: Marko Tiikkaja cc: PG Docs Subject: Re: PL/PgSQL: stmt_fors and variable value after loop In-reply-to: <54BD2E05.2090004@joh.to> References: <54BD24C1.4060601@joh.to> <26441.1421682246@sss.pgh.pa.us> <54BD2E05.2090004@joh.to> Comments: In-reply-to Marko Tiikkaja message dated "Mon, 19 Jan 2015 17:17:09 +0100" Date: Mon, 19 Jan 2015 11:24:04 -0500 Message-ID: <27460.1421684644@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) 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 Marko Tiikkaja 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