Search Postgresql Archives

Re: returning setof varchar

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 2007-04-20 at 12:00 -0400, Scott Schulthess wrote:
> create or replace function getquadalphabet(text) returns setof varchar
> as $$
> 
> declare r varchar;
> 
> begin
> 
> for r in SELECT distinct(substring(drgtitle, 1, 1)) as text from
> stockdrgmeta where state ilike  '%' || $1 || '%' 
> 
> LOOP
> 
> return next r;
> 
> END LOOP;
> 
> end;
> 
> $$ language plpgsql;
> 
>  
> 
> loop variable of loop over rows must be record or row variable at or
> near "LOOP" at character 218
> 

What you need to do is make "r" a record type, and then return an
attribute of the record in the "return next". 

So, something like this:
FOR r IN SELECT ... AS text ... LOOP
  RETURN NEXT r.text;
END LOOP;


Regards,
    Jeff Davis



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux