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