PL/PgSQL: stmt_fors and variable value after loop

Поиск
Список
Период
Сортировка
От Marko Tiikkaja
Тема PL/PgSQL: stmt_fors and variable value after loop
Дата
Msg-id 54BD24C1.4060601@joh.to
обсуждение исходный текст
Ответы Re: PL/PgSQL: stmt_fors and variable value after loop  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: [DOCS] PL/PgSQL: stmt_fors and variable value after loop  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-docs
Hi,

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?


.marko

[1]:
http://www.postgresql.org/docs/9.4/static/plpgsql-control-structures.html#PLPGSQL-RECORDS-ITERATING


--
Sent via pgsql-docs mailing list (pgsql-docs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-docs


В списке pgsql-docs по дате отправления:

Предыдущее
От: David Johnston
Дата:
Сообщение: [DOCS] Suggest adding reference to pg_db_role_setting in chapter 18; expandcatalog page
Следующее
От: Tom Lane
Дата:
Сообщение: Re: PL/PgSQL: stmt_fors and variable value after loop