Re: to_char function returning wrong data

From: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
To: Sreeni Survi <sreenisurvi(at)gmail(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: to_char function returning wrong data
Date: 2019-02-04 17:25:19
Message-ID: 87munb5v24.fsf@news-spur.riddles.org.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

>>>>> "Sreeni" == Sreeni Survi <sreenisurvi(at)gmail(dot)com> writes:

Sreeni> Hi,
Sreeni> Below code has caused my data to be wiped off a table as my
Sreeni> where clause depends on the below returned value.

Sreeni> *select to_char(current_date - interval '5 weeks','IYYYWW') ;*
Sreeni> *201953*

That's because IYYY is intended for use with IW, not with WW. The output
is correct, it's the query that's wrong.

There are several different definitions of "week number", and IW is the
ISO week, with IYYY being the corresponding year. So 5 weeks ago, which
was Dec 31st 2018, was ISO week 1 of 2019, but in some other week
numbering systems, it was week 53 of 2018.

--
Andrew (irc:RhodiumToad)

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2019-02-04 17:31:59 Re: to_char function returning wrong data
Previous Message Tom Lane 2019-02-04 17:24:32 Re: BUG #15602: pg_dump archive items not in correct section order