Pl/Pgsql function troubles

Поиск
Список
Период
Сортировка
Искать

Pl/Pgsql function troubles

От:
Jeff Post <postjeff@uwm.edu>
Дата:
I am hoping that I can write a function that will return a comma seperated list 
of memberships in a given type ($2) of organiztions for a given userid ($1).
Memberships are available in a view called org_details where all groups list 
all there members and types.

I would think that the following should work.  This is the first time that I 
have had to use a dynamic query so that could be the source of the problem 
(like of understanding) but in the following the function never goes into the 
FOR LOOP. 

anybody now what I am doing wrong?

maybe a record cannot be returned that points to a view relation?????
 
all I am trying to do with the raise notice is spit out the Select statment 
that the function is using (earlier source of trouble)

CREATE or replace FUNCTION list_of_membership(integer,CHAR) RETURNS TEXT AS '
DECLARE
   membership_rec record;
   membership text := NULL;
   count integer := 0;
BEGIN
   FOR membership_rec IN EXECUTE select name from org_details where person_id = 
$1 and type = $2 order by name  LOOP
     RAISE NOTICE ''select name from org_details where person_id = '' || $1 
|| '' and type = \''' || $2 || ''\' order by name'' ;
      count := count + 1;
      IF count = 1 THEN
        membership := membership_rec.name;
      ELSE
        membership := membership || '', '' || membership_rec.name;
      END IF;
   END LOOP;
   RETURN membership;
END;
' LANGUAGE 'plpgsql';

Thanks,

Jeff Post
FAQ