Thread: ERROR: control reached end of function without RETURN

ERROR: control reached end of function without RETURN

From
"Ignacio Colmenero"
Date:

Hi all.

I created a function, using EMS:

CREATE OR REPLACE FUNCTION "geo_schema"."search_geo" () RETURNS SETOF varchar AS

$body$

declare x_longlat cursor for select long_lat from h2s ;

declare var_longlat public.geometry ;

declare x_id varchar ;

begin

     open x_longlat ;

     <<loop1>>

     loop

         fetch x_longlat into var_longlat ;

         if not found then

            close x_longlat ;

            exit ;

         end if ;

         select field_id from geo_table

         where within(var_longlat, geo_polygon) limit 1 into x_id ;

         if x_id <> '' then

            return next x_id ;

         end if ;

     end loop ;

end ;

$body$

LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;

When I debug it (using EMS tools), it works fine, and I get 73 rows, but when I run it like:

select * from search_geo() ;

I get the error: ERROR:  control reached end of function without RETURN

 

What can be wrong?

 

TIA

Ignacio.

 

-----------------------------------------------

Ignacio Colmenero

Software Development

Micotan Software Company Ltd.

 

Re: ERROR: control reached end of function without RETURN

From
Tom Lane
Date:
"Ignacio Colmenero" <ignacio.colmenero@micotan.com> writes:
> I get the error: ERROR:  control reached end of function without RETURN

> What can be wrong?

You don't have a RETURN statement.

            regards, tom lane

Re: ERROR: control reached end of function without RETURN

From
"Ignacio Colmenero"
Date:
Thanks Tom.
I didn't know I needed a RETURN statement at the end. I assumed that the
"return next" statement would be enough. It works fine now.

-----------------------------------------------
Ignacio Colmenero
Software Development
Micotan Software Company Ltd.

-----Original Message-----
From: pgsql-general-owner@postgresql.org
[mailto:pgsql-general-owner@postgresql.org] On Behalf Of Tom Lane
Sent: February 11, 2005 12:28 PM
To: Ignacio Colmenero
Cc: pgsql-general@postgresql.org
Subject: Re: [GENERAL] ERROR: control reached end of function without RETURN


"Ignacio Colmenero" <ignacio.colmenero@micotan.com> writes:
> I get the error: ERROR:  control reached end of function without RETURN

> What can be wrong?

You don't have a RETURN statement.

            regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faq