Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YDFr6-0005n2-KU for pgsql-docs@arkaria.postgresql.org; Mon, 19 Jan 2015 17:11:12 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YDFr6-0002bE-0U for pgsql-docs@arkaria.postgresql.org; Mon, 19 Jan 2015 17:11:12 +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 1YDFr5-0002b4-Cj for pgsql-docs@postgresql.org; Mon, 19 Jan 2015 17:11:11 +0000 Received: from mail-la0-f41.google.com ([209.85.215.41]) by makus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1YDFqx-0004CI-Vg for pgsql-docs@postgresql.org; Mon, 19 Jan 2015 17:11:09 +0000 Received: by mail-la0-f41.google.com with SMTP id gm9so3896991lab.0 for ; Mon, 19 Jan 2015 09:11:01 -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=gZJF8AjHEydnlX03GC8jbF68J1HS6/j3TgcMO6y7Pig=; b=YEByRzVzOUQ5Ektp4As72nwOPUQmbnGefxUPs1/phQBxDkCg39JVKyMiwSRY5ze87L DTEmmFsamZX8yVkJI4DkbzPPfWqm4bmHdRmvoLW+a2XbHnf+OPFC4PffxM+Ch5sSFU9c 76UIURP+OHX3xv86uagO4v588oXjaZtVZun4YoNJt4iNdFjlPeGb6Ge4EBF7mlIBsY0M F9YFA9v2LY95pj1ksDY3Qn1iE2PyfPMPHz5nBf+4R1OwC2qFUFcisD5g6kZCvORVFrZ4 1R4hwKOusJxbyo6/Zolf3uiD6sfceJoz10Uqfco3PBmQGB418suzIjmqh/vMLOdoQrWj 8Y1w== X-Gm-Message-State: ALoCoQmiBHKjjF2kTT9aVbrGtlqr05WjMYcTqyHFQx2x8HDk36H/3L4AZ4OUTEdsn2NbEbLCV4Ft X-Received: by 10.112.26.135 with SMTP id l7mr32241053lbg.56.1421687461119; Mon, 19 Jan 2015 09:11:01 -0800 (PST) Received: from Markos-MacBook-Pro.local ([46.246.117.202]) by mx.google.com with ESMTPSA id 8sm3804496las.27.2015.01.19.09.11.00 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Jan 2015 09:11:00 -0800 (PST) Message-ID: <54BD3AA3.1020107@joh.to> Date: Mon, 19 Jan 2015 18:10: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> In-Reply-To: <54BD2E05.2090004@joh.to> 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 FWIW, I went with this method: On 1/19/15 5:17 PM, I wrote: > 3) Use a count(*) OVER () inside the query and EXIT if that count is 1 I guess defining this behavior wouldn't be such a big win, since the approach I showed would only work if the loop body keeps a count of the number of iterations somewhere; FOR doesn't appear to be setting row_count. I'm having a hard time imagining actual use cases where the count doesn't matter but you'd like to look at the last values anyway. If you think there's any chance that this would prevent us from changing the implementation for the better in the future, I think we should just drop this issue. .marko -- Sent via pgsql-docs mailing list (pgsql-docs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-docs