Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UHdVT-00042s-Kd for pgsql-bugs@arkaria.postgresql.org; Mon, 18 Mar 2013 17:05:55 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UHdVT-00041M-4Z for pgsql-bugs@arkaria.postgresql.org; Mon, 18 Mar 2013 17:05:55 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UHdVS-00041G-JI for pgsql-bugs@postgresql.org; Mon, 18 Mar 2013 17:05:54 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UHdVO-0001kT-5e for pgsql-bugs@postgresql.org; Mon, 18 Mar 2013 17:05:54 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.5/8.14.5) with ESMTP id r2IH5kLp009605; Mon, 18 Mar 2013 13:05:46 -0400 (EDT) From: Tom Lane To: noose@noose.pl cc: pgsql-bugs@postgresql.org Subject: Re: BUG #7967: Wrong week number in extract function In-reply-to: References: Comments: In-reply-to noose@noose.pl message dated "Mon, 18 Mar 2013 08:23:16 -0000" Date: Mon, 18 Mar 2013 13:05:46 -0400 Message-ID: <9604.1363626346@sss.pgh.pa.us> X-Pg-Spam-Score: -4.4 (----) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org noose@noose.pl writes: > I'm running that query and result is ... unexpected for me... > Query: > select '2012-12-31', EXTRACT(year from '2012-12-31'::date), EXTRACT(week > from '2012-12-31'::date) It's correct, because "week" follows the ISO definition of week counting. According to that, 2012-12-31 falls in the first week of 2013. (I have no idea how ISO arrived at their definition, but this is what it says: weeks start on Mondays, and the first week of a year is the one containing January 4.) You should usually use isoyear when you are using week, so that the results sync up. This is all explained in http://www.postgresql.org/docs/9.1/static/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT although I notice that the explanation of "week" fails to show explicitly that late-December dates can be considered to fall into the next year. I'll go fix that. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs