Re: Using a multi-valued function in a view

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Radcon Entec <radconentec(at)yahoo(dot)com>
Cc: PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Using a multi-valued function in a view
Date: 2009-06-04 20:58:21
Message-ID: b42b73150906041358x4479975fo6977c5216faa42a4@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Jun 4, 2009 at 4:40 PM, Radcon Entec <radconentec(at)yahoo(dot)com> wrote:
> Merlin,
>
> Thank you for your reply.  Unfortunately, I was not able to get it to work.
> The SQL statements you gave me generated syntax errors.
>
> I tried to follow your thoughts, though.  I created the following type:
>
> CREATE TYPE chargeneedstype AS
>    (needsfs int2,
>     needsdrygas int2,
>     needsbigbase int2);
> ALTER TYPE chargeneedstype OWNER TO postgres;
> Then, I created a test function:
>
> CREATE OR REPLACE FUNCTION chargeneeds2(chargenumber int4)
>   RETURNS chargeneedstype AS
> $BODY$
> declare
>    CoilID varchar;
>    InventoryRec record;
>    result chargeneedstype;
> begin
>  result.needsFS := 1;
>  result.needsBigBase := 2;
>  result.needsDryGas := 3;
>  return result;
> end;
> $BODY$
>   LANGUAGE 'plpgsql' VOLATILE;

I made a typo. try:
select charge, (cn).* from (select chargeneeds(charge) as cn from charge) q;

I think usually it's better to use 'out' parameters to functions than
to create a composite type.

merlin

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Oliver Kohll - Mailing Lists 2009-06-04 21:12:44 Re: Division by zero
Previous Message Brandon Metcalf 2009-06-04 20:35:27 Re: limit table to one row