Re: Using aggregate functions with SELECT INTO or FOR ..

From: Darren Ferguson <darren(at)crystalballinc(dot)com>
To: Frank Miles <fpm(at)u(dot)washington(dot)edu>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Using aggregate functions with SELECT INTO or FOR ..
Date: 2002-10-24 23:06:48
Message-ID: Pine.LNX.4.44.0210241904190.31810-100000@thread.crystalballinc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

You should alias the Aggregate function such as

CREATE OR REPLACE FUNCTION sp_test() RETURNS BOOLEAN AS '
DECLARE
rec RECORD;
BEGIN
SELECT SUM(a) AS asum,foo,bar INTO rec FROM test WHERE id = 1;

IF NOT FOUND THEN
RETURN FALSE;
END IF;

RAISE NOTICE ''%'',rec.asum;

RETURN TRUE;
END;' LANGUAGE 'plpgsql';

This should do what you wanted

HTH

On Thu, 24 Oct 2002, Frank Miles wrote:

> I would like to be able to use aggregate functions (e.g. sum(..))
> in a pl/pgsql functions through SELECT INTO and FOR record IN SELECT ...
> lines. The obvious (record.sum(..)) doesn't work when attempting to
> recover the values. Is there a simple way of getting this information?
>
> TIA!
>
> -frank
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html
>

--
Darren Ferguson

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Zuhra.Sanusi 2002-10-24 23:42:30 A way to link oracle DB to postgres DB for data transfer
Previous Message Frank Miles 2002-10-24 23:00:39 Using aggregate functions with SELECT INTO or FOR .. LOOP?