pg.ddx.io  pgsql-docs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Marko Tiikkaja <marko@joh.to>
Cc: PG Docs <pgsql-docs@postgresql.org>
Subject: Re: PL/PgSQL: stmt_fors and variable value after loop
Date: Mon, 19 Jan 2015 10:44:06 -0500
Message-ID: <26441.1421682246@sss.pgh.pa.us> (raw)
In-Reply-To: <54BD24C1.4060601@joh.to>
References: <54BD24C1.4060601@joh.to>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-docs>

Marko Tiikkaja <marko@joh.to> 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



view thread (6+ messages)  latest in thread

Message-ID: <26441.1421682246@sss.pgh.pa.us>
Permalink:  ../26441.1421682246@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/26441.1421682246@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-docs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, marko@joh.to
  Subject: Re: PL/PgSQL: stmt_fors and variable value after loop
  In-Reply-To: <26441.1421682246@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox