Re: Help making a plpgsql function?

From: Jan Wieck <JanWieck(at)Yahoo(dot)com>
To: Bjørn T Johansen <btj(at)havleik(dot)no>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Help making a plpgsql function?
Date: 2006-07-11 19:48:26
Message-ID: 44B4008A.7010205@Yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 7/5/2006 3:51 PM, Bjørn T Johansen wrote:

> Yes, but I need to return n fields from one table and n fiels from another, and n fields from yet another
> table, etc... and return this as some kind of record... How do I to this?

I wonder why your problem can't be solved by a simple join.

Jan

>
>
> BTJ
>
> On Wed, 5 Jul 2006 19:13:39 +0200
> Dany De Bontridder <dany(at)alchimerys(dot)be> wrote:
>
>> On Wednesday 05 July 2006 16:46, Bjørn T Johansen wrote:
>> > I need to make a funtion that take one parameter and then returns a
>> > "record" with x number of fields, collected from x no. of tables, i.e. I
>> > need to run several sql statemtents to collect all the needed values from x
>> > no. of fields and insert it into a "record" and return the "record" at the
>> > end...
>> From http://www.postgresql.org/docs/7.4/interactive/plpgsql-declarations.html
>>
>> Example for function having return type set of record
>>
>> create function testfunc(int) returns record as '
>> declare
>> output record;
>> begin
>> for output in select * from table1 where col1<$1 loop
>> return next output;
>> end loop;
>> return;
>> end;
>> ' language plpgsql
>>
>> executing through sql as:
>>
>> select * from testfunc(6) as (col1 int, col2 float, col3 char(20));
>>
>>
>> Regards,
>>
>> D.
>>
>> ---------------------------(end of broadcast)---------------------------
>> TIP 1: 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
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: explain analyze is your friend

--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck(at)Yahoo(dot)com #

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2006-07-11 20:18:55 Re: doesn't recognize "!=-" (not equal to a negative
Previous Message marcelo Cortez 2006-07-11 19:36:30 Re: encoding bug or feature?