Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Re: sql wrapped plpgsql set returning function



Richard Albright <ralbright(at)insiderscore(dot)com> writes:
> I have figured out my looping issue, but am having difficulty wrapping
> my set returning plpgsql function getmovavgset with a getmovavg sql func
> when i run the following:

Hm, worksforme (see attached trivial example).  What PG version are you
using?

			regards, tom lane


regression=# create function foo() returns setof int8_tbl as $$
regression$# declare r record;
regression$# begin
regression$#   for r in select * from int8_tbl loop
regression$#     return next r;
regression$#   end loop;
regression$# end$$ language plpgsql;
CREATE FUNCTION
regression=# select * from foo();
        q1        |        q2
------------------+-------------------
              123 |               456
              123 |  4567890123456789
 4567890123456789 |               123
 4567890123456789 |  4567890123456789
 4567890123456789 | -4567890123456789
(5 rows)

regression=# select foo();
ERROR:  set-valued function called in context that cannot accept a set
CONTEXT:  PL/pgSQL function "foo" line 4 at return next
regression=# create function foowrap() returns setof int8_tbl as $$
regression$# select * from foo();
regression$# $$ language sql;
CREATE FUNCTION
regression=# select foowrap();
               foowrap
--------------------------------------
 (123,456)
 (123,4567890123456789)
 (4567890123456789,123)
 (4567890123456789,4567890123456789)
 (4567890123456789,-4567890123456789)
(5 rows)

regression=#



Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group