cursors and function question

Поиск
Список
Период
Сортировка
Искать
От
armand pirvu
Тема
cursors and function question
Дата
Msg-id
149EBC11-E33E-4DBA-9130-8C93BE4B1B43@gmail.com
Список
Дерево обсуждения
cursors and function question armand pirvu <armand.pirvu@gmail.com>
Re: cursors and function question Adrian Klaver <adrian.klaver@aklaver.com>
Re: cursors and function question armand pirvu <armand.pirvu@gmail.com>
Re: cursors and function question Adrian Klaver <adrian.klaver@aklaver.com>
Re: cursors and function question armand pirvu <armand.pirvu@gmail.com>
Re: cursors and function question Adrian Klaver <adrian.klaver@aklaver.com>
Re: cursors and function question "David G. Johnston" <david.g.johnston@gmail.com>
Re: cursors and function question armand pirvu <armand.pirvu@gmail.com>
Re: cursors and function question "David G. Johnston" <david.g.johnston@gmail.com>
Re: cursors and function question armand pirvu <armand.pirvu@gmail.com>
Re: cursors and function question "David G. Johnston" <david.g.johnston@gmail.com>
Hi 

Is there any elegant way not a two steps way I can output the cursor value at each step?


testtbl table has this content

    col1    |    col2    | col3 
------------+------------+------
 E1         | CAT1       |    0
 E1         | CAT2       |    0
 E1         | CAT3       |    0
 E4         | CAT1       |    0
 E5         | CAT1       |    0
 E6         | CAT1       |    0
 E7         | CAT1       |    0


This works
BEGIN WORK;
DECLARE fooc  CURSOR FOR SELECT * FROM testtbl;
FETCH ALL FROM fooc;
CLOSE fooc;
COMMIT WORK;

    col1    |    col2    | col3 
------------+------------+------
 E1         | CAT1       |    0
 E1         | CAT2       |    0
 E1         | CAT3       |    0
 E4         | CAT1       |    0
 E5         | CAT1       |    0
 E6         | CAT1       |    0
 E7         | CAT1       |    0


But 
CREATE OR REPLACE FUNCTION foofunc()
   RETURNS text AS $$
DECLARE 
 var2   RECORD;
 cur CURSOR FOR SELECT * from testtbl;
BEGIN
   OPEN cur;
    LOOP
      FETCH cur INTO var2;
      return var2;
   END LOOP;
   CLOSE cur;
END; $$
LANGUAGE plpgsql;


select foofunc();
            foofunc            
-------------------------------
 ("E1        ","CAT1      ",0)

But I am looking to get 

            foofunc            
-------------------------------
 ("E1        ","CAT1      ",0)
 ("E1        ","CATs      ",0)
etc 



Many thanks
— Armand
В списке pgsql-general по дате отправления
От: Tom Lane
Дата:
От: David G. Johnston
Дата:
FAQ