Subject: summing numerical fields in a class

From: Brian Holman <[email-masked]>
Date: Tue, 7 Dec 1993 08:13:53 +119303928 (MST)

I am writing a program that executes a child process and monitors the number
of real time seconds the child is "active".  After the child has terminated
it then records the following in the TIMESTAT class:

appl = text
time = reltime
status = char
date = abstime

where a typical entry would be:

append (
   appl = "BYLINE", time = "@ 1251 seconds", status = 'O', date = "Dec 7 1993"
)

I would like to do the following query:

retrieve (
   total = sum {TIMESTAT.time where TIMESTAT.date >= "Dec 01 1993" 
   and TIMESTAT.date <= "Dec 31 1993"}
)

I am using Postgres 4.1 on a DECStation running Ultrix 4.2A.  The above
mentioned query would be considered an aggregate and therefore is not yet a
supported feature.  Does anyone have any ideas how I can get around this
limitation.  Any thoughts on the subject would be greatly appreciated.
-- 
+--------------------------+-------------------------------------+
| BRIAN K. HOLMAN          | E-Mail:        [email-masked] |
| Programmer/Analyst       | Mail:    2330 HBLL, Provo, UT 84602 |
| Library Automations      | Phone:               (801) 378-8162 |
| Brigham Young University | Fax:                 (801) 378-3221 |
+--------------------------+-------------------------------------+

---

From: [email-masked] (Paul M. Aoki)
Date: Tue, 07 Dec 1993 09:55:01 -0800

>    and TIMESTAT.date <= "Dec 31 1993"}

actually, this is one of the very few types of aggregate queries
that DOES work somewhat reliably (aggregate with one variable in
the target list).

the only kicker here is that a sum aggregate for reltime is not
installed by default, so you would have to either use int4 or
define one yourself.
--
  Paul M. Aoki  |  CS Div., Dept. of EECS, UCB  |  [email-masked]
                |  Berkeley, CA 94720           |  ...!uunet!ucbvax!aoki