pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: noose@noose.pl
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #7967: Wrong week number in extract function
Date: Mon, 18 Mar 2013 13:05:46 -0400
Message-ID: <9604.1363626346@sss.pgh.pa.us> (raw)
In-Reply-To: <E1UHVLg-0003bi-Uj@wrigleys.postgresql.org>
References: <E1UHVLg-0003bi-Uj@wrigleys.postgresql.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

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



view thread (3+ messages)

Message-ID: <9604.1363626346@sss.pgh.pa.us>
Permalink:  ../9604.1363626346@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/9604.1363626346@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, noose@noose.pl
  Subject: Re: BUG #7967: Wrong week number in extract function
  In-Reply-To: <9604.1363626346@sss.pgh.pa.us>
  References: <E1UHVLg-0003bi-Uj@wrigleys.postgresql.org> <9604.1363626346@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox