X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 9D87753CAD for ; Fri, 15 Apr 2005 06:22:35 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 30631-03 for ; Fri, 15 Apr 2005 09:22:30 +0000 (GMT) Received: from tx1.mail.ox.ac.uk (tx1.mail.ox.ac.uk [129.67.1.167]) by svr1.postgresql.org (Postfix) with ESMTP id 3F10D53B91 for ; Fri, 15 Apr 2005 06:22:27 -0300 (ADT) Received: from scan1.mail.ox.ac.uk ([129.67.1.166] helo=localhost) by tx1.mail.ox.ac.uk with esmtp (Exim 4.42) id 1DMN1v-00019T-60 for pgsql-sql@postgresql.org; Fri, 15 Apr 2005 10:22:27 +0100 Received: from rx1.mail.ox.ac.uk ([129.67.1.165]) by localhost (scan1.mail.ox.ac.uk [129.67.1.166]) (amavisd-new, port 25) with ESMTP id 04327-02 for ; Fri, 15 Apr 2005 10:22:27 +0100 (BST) Received: from smtp2.herald.ox.ac.uk ([163.1.0.235]) by rx1.mail.ox.ac.uk with esmtp (Exim 4.42) id 1DMN1v-00019Q-5a for pgsql-sql@postgresql.org; Fri, 15 Apr 2005 10:22:27 +0100 Received: from mizar.oucs.ox.ac.uk ([129.67.101.107] helo=localhost) by smtp2.herald.ox.ac.uk with esmtp (Exim 3.35 #1) id 1DMN1v-00031M-3n for pgsql-sql@postgresql.org; Fri, 15 Apr 2005 10:22:27 +0100 Date: Fri, 15 Apr 2005 10:22:27 +0100 From: Stephen Quinney To: pgsql-sql@postgresql.org Subject: Combining values in a column Message-ID: <20050415092227.GA24135@computing-services.oxford.ac.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Operating-System: Linux mizar 2.6.10 x-gpg-fingerprint: F934 244D 4E26 DBDE C9EF BFB7 2131 9B94 4C1A 5BE5 x-gpg-key: wwwkeys.uk.pgp.net User-Agent: Mutt/1.5.6+20040907i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200504/221 X-Sequence-Number: 21114 I have a query which returns a single column of integers which I want to combine together with &, "bitwise AND". Basically it's a simple list of access levels that a user might have and I want to merge the list into one value. There can be zero, one or more values in the list so I have to be able to cope with the no-results . For example access -------- 31 511 Would lead to 31 & 511 which gives 31. I guess really this can lead to the more generic question. How do I apply a general function to combine the values, if I, for example, wanted to write my own aggregate function like sum? Thanks in advance, Stephen Quinney