Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YDEUu-0002US-Vx for pgsql-docs@arkaria.postgresql.org; Mon, 19 Jan 2015 15:44:13 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YDEUt-00069z-SU for pgsql-docs@arkaria.postgresql.org; Mon, 19 Jan 2015 15:44: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 1YDEUt-00069p-97 for pgsql-docs@postgresql.org; Mon, 19 Jan 2015 15:44:11 +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 1YDEUq-0002Sp-Cy for pgsql-docs@postgresql.org; Mon, 19 Jan 2015 15:44:09 +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 t0JFi6vd026442; Mon, 19 Jan 2015 10:44:06 -0500 From: Tom Lane To: Marko Tiikkaja cc: PG Docs Subject: Re: PL/PgSQL: stmt_fors and variable value after loop In-reply-to: <54BD24C1.4060601@joh.to> References: <54BD24C1.4060601@joh.to> Comments: In-reply-to Marko Tiikkaja message dated "Mon, 19 Jan 2015 16:37:37 +0100" Date: Mon, 19 Jan 2015 10:44:06 -0500 Message-ID: <26441.1421682246@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: > As far as I can tell, according to the documentation[1] the return value > of this PL/PgSQL function is undefined: > CREATE OR REPLACE FUNCTION public.foof() > RETURNS integer > LANGUAGE plpgsql > AS $function$ > declare > _f1 int; > begin > for _f1 in select 1 loop > end loop; > return _f1; > end > $function$ > But at least based on my understanding of exec_for_query() in pl_exec.c, > a FOR loop over query results will always terminate with the values from > the last row if at least one was found, regardless of whether EXIT was > used or not. Is there a reason this detail has been left undefined in > the documentation? If not, can we change the documentation? 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? The above certainly isn't one. 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