Unix Technical Forum

set-valued function difference in 8.1.0 vs 8.0.2

This is a discussion on set-valued function difference in 8.1.0 vs 8.0.2 within the Pgsql General forums, part of the PostgreSQL category; --> I just wanted to make sure this change in behavior is a feature and not a bug. This block ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-09-2008, 07:55 AM
rm_pg@cheapcomplexdevices.com
 
Posts: n/a
Default set-valued function difference in 8.1.0 vs 8.0.2

I just wanted to make sure this change in behavior is
a feature and not a bug.

This block of code with a (mis?)use of a set-valued function:

CREATE OR REPLACE FUNCTION foo() RETURNS SETOF varchar AS $$ {
my $res = [];
push @$res,'a';
push @$res,'b';
return $res;
} $$ LANGUAGE plperl STABLE;
select * from foo();
select foo();

worked "fine" in 8.0.2 but gives an

ERROR: set-valued function called in context that cannot accept a set

error in 8.1.0.




The 8.0.2 behavior of expanding the set-valued function when used
in the left part of the select clause was convenient in some
functions where I had used it like this:

select addr,geocode_alternatives(addr) from (
select addr from table where ambiguous=true
) as a;

where geocode_alternatives was a set-valued function that returned
all the alternatives for the ambiguous addresses.

Basically the results with 8.0.2 were something like:
addr | geocode_alternative
-----------+----------------
1 main st | 1 N main st
1 main st | 1 S main st
1 main st | 1 main ave
30 mlk dr | 2 Martin Luther King dr
30 mlk dr | 2 milk dr


And now I'm having a hard time coming up with a way of
re-writing it without a similar error. Is there an
easy way of rewriting this construct where the results
of a function can expand the result set that works
nicely in 8.1?

Thanks,
Ron

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-09-2008, 07:56 AM
Tom Lane
 
Posts: n/a
Default Re: set-valued function difference in 8.1.0 vs 8.0.2

rm_pg@cheapcomplexdevices.com writes:
> I just wanted to make sure this change in behavior is
> a feature and not a bug.


Afraid so --- the plperl SRF support was rewritten in 8.1, and
it probably behaves just like plpgsql now, which has also got
this restriction.

> Is there an easy way of rewriting this construct where the results of
> a function can expand the result set that works nicely in 8.1?


A kluge some people have used with plpgsql is to put a SQL-language
wrapper function around the PL function, ie

create function foo(...) returns ... as
'select * from pl_foo(...)'
language sql;

Should work for plperl too.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

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:21 AM.


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