Unix Technical Forum

Joining with result of a plpgsql function

This is a discussion on Joining with result of a plpgsql function within the pgsql Sql forums, part of the PostgreSQL category; --> Hello, I have a pl/pgsql function, defined as: CREATE FUNCTION tms.get_tms_summary(id integer) RETURNS tms.tms_summary get_tms_summary returns a composite type, ...


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

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-10-2008, 03:06 PM
Matthew T. O'Connor
 
Posts: n/a
Default Joining with result of a plpgsql function

Hello,

I have a pl/pgsql function, defined as:

CREATE FUNCTION tms.get_tms_summary(id integer)
RETURNS tms.tms_summary

get_tms_summary returns a composite type, tms_summary, which is
comprised of several numerics.

What I would like to do is something like:

select f.id, f.name, tms.get_tms_summary(f.id) from foo f;

However this returns only three columns, the third of which is the
entire complex data type in one column.

I can do: select * from tms.get_tms_summary(99);

But I would really like to be able to combine it with other data and get
a result set that looked like:

f.id, f.name, tms_summary.col1, tms_summary.col2 ...


Any thoughts or suggestions?


Thank you,

Matthew O'Connor


--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 05-10-2008, 03:06 PM
Stephan Szabo
 
Posts: n/a
Default Re: Joining with result of a plpgsql function


On Wed, 7 May 2008, Matthew T. O'Connor wrote:

> I have a pl/pgsql function, defined as:
>
> CREATE FUNCTION tms.get_tms_summary(id integer)
> RETURNS tms.tms_summary
>
> get_tms_summary returns a composite type, tms_summary, which is
> comprised of several numerics.
>
> What I would like to do is something like:
>
> select f.id, f.name, tms.get_tms_summary(f.id) from foo f;
>
> However this returns only three columns, the third of which is the
> entire complex data type in one column.
>
> I can do: select * from tms.get_tms_summary(99);
>
> But I would really like to be able to combine it with other data and get
> a result set that looked like:
>
> f.id, f.name, tms_summary.col1, tms_summary.col2 ...


Well I think
select f.id, f.name, (tms.get_tms_summary(f.id)).* from foo f;
would expand it out into separate columns, but I think that might also
call it multiple times. You might have better luck combining that with a
subquery like
select id, name, (summary).col1, (summary).col2, ... from
(select id, name, tms.get_tms_summary(f.id) as summary from foo) f;


--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-10-2008, 03:06 PM
Matthew T. O'Connor
 
Posts: n/a
Default Re: Joining with result of a plpgsql function

Stephan Szabo wrote:
> On Wed, 7 May 2008, Matthew T. O'Connor wrote:
>
>> But I would really like to be able to combine it with other data and get
>> a result set that looked like:
>>
>> f.id, f.name, tms_summary.col1, tms_summary.col2 ...
>>

>
> Well I think
> select f.id, f.name, (tms.get_tms_summary(f.id)).* from foo f;
> would expand it out into separate columns, but I think that might also
> call it multiple times. You might have better luck combining that with a
> subquery like
> select id, name, (summary).col1, (summary).col2, ... from
> (select id, name, tms.get_tms_summary(f.id) as summary from foo) f;


Ah, I knew there was an easy way to do it, I totally forgot / missed /
didn't know about the (composite type).* syntax.

Thank you!


--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql

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 05:47 PM.


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