dbTalk Databases Forums  

[BUGS] set returning function

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss [BUGS] set returning function in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Dennis Bjorklund
 
Posts: n/a

Default [BUGS] set returning function - 05-09-2005 , 05:22 AM






An issue came up on irc. How come that this work:

SELECT generate_series(0,1);

but

SELECT foo(0,1);

does not, where foo is my own set returning function, like this example:

CREATE FUNCTION foo(a int, b int)
RETURNS setof int
AS 'BEGIN RETURN NEXT a;
RETURN NEXT b;
RETURN;
END'
LANGUAGE plpgsql;

As far as I can tell the generate_series() example is not supposed to
work either.

Kris Jurka showed me another example that do work in the same way as
generate_series:

CREATE FUNCTION bar(int, int)
RETURNS setof int
AS 'SELECT $1 UNION ALL SELECT $2;'
LANGUAGE sql;

So it seems that it's not just the type that decide how the function can
be used, it's also the language the function is defined in.

Bug?

--
/Dennis Björklund


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

Reply With Quote
  #2  
Old   
Kris Jurka
 
Posts: n/a

Default Re: [BUGS] set returning function - 05-09-2005 , 05:56 AM








On Mon, 9 May 2005, Dennis Bjorklund wrote:

Quote:
[ I can call sql or C SRFs without FROM, but not plpgsql.]
Trying this in pltcl (while knowing nothing about tcl and the docs not
mentioning any srf support) shows:

CREATE FUNCTION tclset() RETURNS SETOF int AS 'return 0' LANGUAGE pltcl;

SELECT * FROM tclset(); -- works

SELECT tclset(); -- goes into an infinite loop

Kris Jurka

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo (AT) postgresql (DOT) org


Reply With Quote
  #3  
Old   
Tom Lane
 
Posts: n/a

Default Re: [BUGS] set returning function - 05-09-2005 , 09:31 AM



Dennis Bjorklund <db (AT) zigo (DOT) dhs.org> writes:
Quote:
So it seems that it's not just the type that decide how the function can
be used, it's also the language the function is defined in.
Yup.

Quote:
Bug?
Unimplemented feature.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo (AT) postgresql (DOT) org)


Reply With Quote
  #4  
Old   
Dennis Bjorklund
 
Posts: n/a

Default Re: [BUGS] set returning function - 05-09-2005 , 11:59 AM



On Mon, 9 May 2005, Tom Lane wrote:

Quote:
Bug?

Unimplemented feature.
Is

SELECT 42, srf();

the same as

SELECT 42, * FROM srf();

?

In my view the first version is an error. It's not like you can put a
normal table in the select list, so why can we put a set returning
function there? Ie, is it really a feature?

--
/Dennis Björklund


---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend


Reply With Quote
  #5  
Old   
Tom Lane
 
Posts: n/a

Default Re: [BUGS] set returning function - 05-09-2005 , 12:03 PM



Dennis Bjorklund <db (AT) zigo (DOT) dhs.org> writes:
Quote:
Is
SELECT 42, srf();
the same as
SELECT 42, * FROM srf();
?
No.

Quote:
In my view the first version is an error. It's not like you can put a
normal table in the select list, so why can we put a set returning
function there? Ie, is it really a feature?
To some extent it's a hangover from PostQUEL ... but there are things
you can do with it that you can't currently do with SRFs in FROM.
See for instance the "listchildren" example in the manual:
http://www.postgresql.org/docs/8.0/s....html#AEN29503

regards, tom lane

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


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



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.