Re: Using aggregate functions with SELECT INTO or FOR .. - Mailing list pgsql-general

From Darren Ferguson
Subject Re: Using aggregate functions with SELECT INTO or FOR ..
Date
Msg-id Pine.LNX.4.44.0210241904190.31810-100000@thread.crystalballinc.com
Whole thread Raw
In response to Using aggregate functions with SELECT INTO or FOR .. LOOP?  (Frank Miles <fpm@u.washington.edu>)
Responses Re: Using aggregate functions .. (a BUG?)  (Frank Miles <fpm@u.washington.edu>)
List 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


pgsql-general by date:

Previous
From: Frank Miles
Date:
Subject: Using aggregate functions with SELECT INTO or FOR .. LOOP?
Next
From: Zuhra.Sanusi@seagate.com
Date:
Subject: A way to link oracle DB to postgres DB for data transfer