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$
B
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
On 1/19/15 4:44 PM, Tom Lane wrote:
Marko Tiikkaja writes:
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 th
Marko Tiikkaja writes:
> On 1/19/15 4:44 PM, Tom Lane wrote:
>> 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 assumptio
On 1/19/15 5:24 PM, Tom Lane wrote:
Marko Tiikkaja writes:
What I'm doing would look something like this:
...
Available workarounds right now would be, as far as I can tell:
1) Have separate variables which I assign to inside the loop, and use
those in case the loop found exactly one row
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 itera