Re: help..postgresql mulyiple return values

From: "Tony Wasson" <ajwasson(at)gmail(dot)com>
To: "Michael Joseph Tan" <josephtan2k(at)yahoo(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: help..postgresql mulyiple return values
Date: 2006-05-18 17:53:58
Message-ID: 6d8daee30605181053g29ffbeccy2f4e13b9aedccaf5@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On 5/12/06, Michael Joseph Tan <josephtan2k(at)yahoo(dot)com> wrote:
>
> hi,
> im new in postgresql, generally new in databases.
>
> im trying to make a function using PGAdminIII which returns several types,
> example, my query is:
>
> "select count(id) as requests, organization from connection_requests group
> by organization"
>
> id is of type int8, organization is of type varchar(50).
>
> basically the query would return coun(id), and a varchar(50) which is
> organization.
>
> i really dont know what to put on the return type.
>
> what would be the best solution?

If you are in 8.1 you can follow this example from the documentation.
http://www.postgresql.org/docs/8.1/interactive/plpgsql-declarations.html

CREATE FUNCTION sum_n_product(x int, y int, OUT sum int, OUT prod int) AS $$
BEGIN
sum := x + y;
prod := x * y;
END;
$$ LANGUAGE plpgsql;

Then run it like:

SELECT sum, prod FROM sum_n_product(1,2);

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Andreas Joseph Krogh 2006-05-18 19:05:55 Re: Constraint question
Previous Message Guillaume Lelarge 2006-05-18 16:54:46 Re: Add column and specify the column position in a table