Re: returning setof varchar

From: Jeff Davis <pgsql(at)j-davis(dot)com>
To: Scott Schulthess <scott(at)topozone(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: returning setof varchar
Date: 2007-04-20 16:56:54
Message-ID: 1177088214.28383.8.camel@dogma.v10.wvs
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2007-04-20 17:00:50 Re: returning setof varchar
Previous Message RPK 2007-04-20 16:22:21 Schema relationship diagram