X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id E67C0D1E95F for ; Tue, 13 Apr 2004 13:41:37 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 83725-10 for ; Tue, 13 Apr 2004 13:41:36 -0300 (ADT) Received: from wolff.to (wolff.to [66.93.249.74]) by svr1.postgresql.org (Postfix) with SMTP id D7146D1E951 for ; Tue, 13 Apr 2004 13:41:35 -0300 (ADT) Received: (qmail 19133 invoked by uid 500); 13 Apr 2004 16:45:18 -0000 Date: Tue, 13 Apr 2004 11:45:18 -0500 From: Bruno Wolff III To: Terry Brick Cc: pgsql-sql@postgresql.org Subject: Re: Formatting Functions and Group By Message-ID: <20040413164518.GA18956@wolff.to> Mail-Followup-To: Terry Brick , pgsql-sql@postgresql.org References: <20040413161305.22857.qmail@web11502.mail.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20040413161305.22857.qmail@web11502.mail.yahoo.com> User-Agent: Mutt/1.5.6i X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200404/118 X-Sequence-Number: 17493 On Tue, Apr 13, 2004 at 09:13:05 -0700, Terry Brick wrote: > Hi, > I'm porting a bunch of queries from MySQL to Postgres 7.4 and am having a problem with one > particular area. For example, a query like this works in MySQL: > > select > to_char(myCol,'Mon YY') > from > myTable > group by > to_char(myCol,'MM YYYY') > order by > to_char(myCol,'MM YYYY') > > Postgres will give me an error saying that "to_char(myCol,'Mon YY')" must be in the 'group by'. I > understand why that normally needs to be the case, but in theory, it would be ok here because they > are actually the same values (in the select and group by) but just formatted differently. I just > want the query to be grouped and ordered by month and year, but to be formatted differently in the > output. > > Any ideas? You could do something like the following. It works in 7.4, but I am not sure if it is completely standard. area=> select to_char(date_trunc('month',current_date), 'MM YYYY') area-> group by date_trunc('month',current_date); to_char --------- 04 2004 (1 row)