Re: Question about functions - Mailing list pgsql-sql

From Stewart Ben (RBAU/EQS4) *
Subject Re: Question about functions
Date
Msg-id E253BDD7F008244585AEE87AF8F0224F116C7AE2@cl-mail01.au.bosch.com
Whole thread Raw
In response to Question about functions  (Mike Plemmons <mikeplemmons@gmail.com>)
List pgsql-sql
Mike,

> I am trying to run this function but the return is not
> correct.  If I run the select statement from the psql command
> line it works.  My guess is that the WHERE clause could be
> causing the problem.  Then again, it may be how I am using
> the FOR loop.  The ides column is of type TEXT.
>
> CREATE OR REPLACE FUNCTION sp_description_search(varchar)
> RETURNS varchar AS $$         -- <== Problem is here
> DECLARE
> myrec record;
> BEGIN
> FOR myrec IN SELECT * FROM tblStuff WHERE ides LIKE '%$1%' LOOP
> RETURN NEXT myrec;            -- <== Problem is here
> END LOOP;
> RETURN;
> END;
> $$ LANGUAGE 'plpgsql';

You need to declare this as a set-returning function if you're using
RETURN NEXT.

Best regards,

Ben Stewart

--
Robert Bosch (Australia) Pty. Ltd.
Engineering Quality Services, Student Software Engineer (RBAU/EQS4)
Locked Bag 66 - Clayton South, VIC 3169 - AUSTRALIA
mailto:ben.stewart@au.bosch.com
http://www.bosch.com.au/


pgsql-sql by date:

Previous
From: Mike Plemmons
Date:
Subject: Question about functions
Next
From: Richard Huxton
Date:
Subject: Re: Question about functions