Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 29DF89F9F49 for ; Mon, 11 Dec 2006 13:38:24 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-new, port 10024) with ESMTP id 92883-01 for ; Mon, 11 Dec 2006 13:38:23 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id A176C9F9F46 for ; Mon, 11 Dec 2006 13:38:23 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id kBBHcK8m013947; Mon, 11 Dec 2006 12:38:20 -0500 (EST) To: Josh Berkus cc: pgsql-docs@postgresql.org Subject: Re: More missing docs (aggs) In-reply-to: <200612110929.07744.josh@agliodbs.com> References: <45765819.20804@agliodbs.com> <18695.1165384231@sss.pgh.pa.us> <200612110929.07744.josh@agliodbs.com> Comments: In-reply-to Josh Berkus message dated "Mon, 11 Dec 2006 09:29:07 -0800" Date: Mon, 11 Dec 2006 12:38:20 -0500 Message-ID: <13946.1165858700@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200612/111 X-Sequence-Number: 4034 Josh Berkus writes: >> Uh, why do you think that's significant? The stype is whatever you >> need to use. > Right, but do you have two stypes for a multi-col, a single stype, or a > composite stype? The docs don't say and it's not obvious. There is only one transition state variable, as I should think would be reasonably obvious from the wording: An aggregate function is made from one or two ordinary functions: a state transition function sfunc, and an optional final calculation function ffunc. These are used as follows: sfunc( internal-state, next-data-values ) ---> next-internal-state ffunc( internal-state ) ---> aggregate-value PostgreSQL creates a temporary variable of data type stype to hold the current internal state of the aggregate. At each input row, the aggregate argument value(s) are calculated and the state transition function is invoked with the current state value and the new argument value(s) to calculate a new internal state value. Whether the state value is a composite type or not is up to the aggregate author. There aren't any examples of using a composite type in the docs, but there are examples of using an array as stype, so I would hope that our users are bright enough to think of composites when they need one. regards, tom lane