Received: from hotmail.com (f4.law3.hotmail.com [209.185.241.4]) by postgresql.org (Postfix) with ESMTP id 69C22476036 for ; Mon, 18 Mar 2002 08:14:47 -0500 (EST) Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Mon, 18 Mar 2002 05:14:47 -0800 Received: from 24.79.100.181 by lw3fd.law3.hotmail.msn.com with HTTP; Mon, 18 Mar 2002 13:14:46 GMT X-Originating-IP: [24.79.100.181] From: "Dorian Taylor" To: pgsql-sql@postgresql.org Subject: Creative use of CASE in a GROUP BY clause Date: Mon, 18 Mar 2002 13:14:46 Mime-Version: 1.0 Content-Type: text/plain; format=flowed Message-ID: X-OriginalArrivalTime: 18 Mar 2002 13:14:47.0061 (UTC) FILETIME=[E07D8C50:01C1CE7E] X-Archive-Number: 200203/223 X-Sequence-Number: 7102 Greets, I'm trying to figure out how to craft a query that I can embed into a piece of code that can be passed a bind value in order to dictate how it should behave on GROUP BY, sparing me from having to write separate queries for N functions and/or columns I may want to group my query by. e.g. SELECT COUNT(foo) FROM bar GROUP BY CASE (? IS NOT NULL) THEN thiscol ELSE thatcol END If thiscol and thatcol aren't the same type, the CASE bombs out. I suppose ultimately it would be a matter of reducing each column definition in the CASE to a boolean expression, but I'm not sure what that would syntactically look like, as simply declaring a column in GROUP BY is obviously shorthand for something. Thanks Dorian _________________________________________________________________ Send and receive Hotmail on your mobile device: http://mobile.msn.com