Unix Technical Forum

plpgsql SET OF functions in field list of select

This is a discussion on plpgsql SET OF functions in field list of select within the pgsql Hackers forums, part of the PostgreSQL category; --> Hello. Why pgplsql setof ... function cannot be used in field list of select? It is possible to use ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Hackers

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-11-2008, 04:45 AM
falcon
 
Posts: n/a
Default plpgsql SET OF functions in field list of select

Hello.

Why pgplsql setof ... function cannot be used in field list of select?
It is possible to use C functions, plperl functions and sql functions,
but pgplsql returns:

ERROR: set-valued function called in context that cannot accept a set
CONTEXT: PL/pgSQL function "my_gen_ser" line 6 at return next

One can use sql function wrapper like this:

create or replace function my_gen_ser(int,int) returns setof int as '
declare
i int;
begin
i:=$1;
while i<=$2 loop
return next i;
i:=i+1;
end loop;
return;
end;
'
language plpgsql immutable;

/*
select t,my_gen_ser(t,t+t) from generate_series(2,5) as t;
fails with
ERROR: set-valued function called in context that cannot accept a set
CONTEXT: PL/pgSQL function "my_gen_ser" line 6 at return next
*/

create or replace function get_setint(int,int) returns setof int as '
select * from my_gen_ser($1,$2)
'
language sql immutable;

/* but this works good */
select t,get_setint(t,t+t) from generate_series(2,5) as t;

But I think it's awful, don't you?

Sokolov Yura mailto:falcon@intercable.ru



---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 04:25 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com