Unix Technical Forum

Return type for procedure

This is a discussion on Return type for procedure within the pgsql Novice forums, part of the PostgreSQL category; --> Hi, I'm writing a procedure, where I'm trying to save writing other procedures by combining all of them in ...


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

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-17-2008, 11:06 PM
ben sewell
 
Posts: n/a
Default Return type for procedure

Hi,
I'm writing a procedure, where I'm trying to save writing other procedures
by combining all of them in one procedure. All procdures take the same input
parameters so I would imagine this is possible.

What I was wondering was if it was possible for me to return different user
defined types. To try to illustrate what I mean, here's some example code
which I think is allowed:

if id="1" then
processing code
return usertype3;
elseif id="2" then
processing code
return usertype3;
elseif id="3" then
processing code
return usertype3;
endif;

Is this possible?

Cheers,
Ben

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-17-2008, 11:06 PM
Jaime Casanova
 
Posts: n/a
Default Re: Return type for procedure

>
> What I was wondering was if it was possible for me to return different user
> defined types. To try to illustrate what I mean, here's some example code
> which I think is allowed:
>


yes.

just create your functions as:

CREATE FUNCTION test() RETURNS record as $$
$$ language 'your-language';

then execute the function as

select * from test() as (field1 type1, field2 type2...);

--
regards,
Jaime Casanova

"Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs and the universe trying
to produce bigger and better idiots.
So far, the universe is winning."
Richard Cook

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-17-2008, 11:07 PM
ben sewell
 
Posts: n/a
Default Re: Return type for procedure

Hi Jaime,
thanks for your reply.

Could anyone check if this is correct for what I'm trying to do


CREATE FUNCTION test(id integer,name varchar,date_start date date_end date)
RETURNS record as $$
$$ language 'your-language';

if id="1" then
select * from tblemployee;
elseif id="2" then
select client_name,address
from tblclients;
endif

and then execute the function as

select * from test() as (report1, report2)

would this work? This is just example code for select statements which are
far much longer

Cheers,
Ben



On 8/16/06, Jaime Casanova <systemguards@gmail.com> wrote:
>
> >
> > What I was wondering was if it was possible for me to return different

> user
> > defined types. To try to illustrate what I mean, here's some example

> code
> > which I think is allowed:
> >

>
> yes.
>
> just create your functions as:
>
> CREATE FUNCTION test() RETURNS record as $$
> $$ language 'your-language';
>
> then execute the function as
>
> select * from test() as (field1 type1, field2 type2...);
>
> --
> regards,
> Jaime Casanova
>
> "Programming today is a race between software engineers striving to
> build bigger and better idiot-proof programs and the universe trying
> to produce bigger and better idiots.
> So far, the universe is winning."
> Richard Cook
>


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 03:56 PM.


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