Re: PL/PgSQL: stmt_fors and variable value after loop

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Marko Tiikkaja <marko(at)joh(dot)to>
Cc: PG Docs <pgsql-docs(at)postgresql(dot)org>
Subject: Re: PL/PgSQL: stmt_fors and variable value after loop
Date: 2015-01-19 15:44:06
Message-ID: 26441.1421682246@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

Marko Tiikkaja <marko(at)joh(dot)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

In response to

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message Marko Tiikkaja 2015-01-19 16:17:09 Re: PL/PgSQL: stmt_fors and variable value after loop
Previous Message Marko Tiikkaja 2015-01-19 15:37:37 PL/PgSQL: stmt_fors and variable value after loop