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 A25EE5E46D1 for ; Fri, 6 Aug 2004 19:53:12 -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 43628-08 for ; Fri, 6 Aug 2004 22:53:07 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id 77FEE5E46C8 for ; Fri, 6 Aug 2004 19:53:02 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i76Mqw7M024170; Fri, 6 Aug 2004 18:52:58 -0400 (EDT) To: olly@lfix.co.uk Cc: Caleb Simonyi-Gindele , pgsql-sql@postgresql.org Subject: Re: Grouping by week In-reply-to: <1091830111.13140.1.camel@linda> References: <000001c47bfc$69d79e50$c201a8c0@borderveygqj37> <1091830111.13140.1.camel@linda> Comments: In-reply-to Oliver Elphick message dated "Fri, 06 Aug 2004 23:08:31 +0100" Date: Fri, 06 Aug 2004 18:52:57 -0400 Message-ID: <24169.1091832777@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200408/45 X-Sequence-Number: 18542 Oliver Elphick writes: > How about: > SELECT EXTRACT(WEEK FROM trans_date + '1 day'::INTERVAL) Note that if trans_date is actually a date, you are much better off just adding an integer to it: SELECT EXTRACT(WEEK FROM trans_date + 1) If you add an interval then the date will be promoted to a timestamp, and all of a sudden you have possible issues with funny behavior at DST boundaries. I think since 7.3 the DST issue is only serious if trans_date is actually stored as timestamp with time zone, but it has been able to bite you in the past. regards, tom lane