Re: to_char function returning wrong data - Mailing list pgsql-bugs

From Andrew Gierth
Subject Re: to_char function returning wrong data
Date
Msg-id 87munb5v24.fsf@news-spur.riddles.org.uk
Whole thread Raw
In response to to_char function returning wrong data  (Sreeni Survi <sreenisurvi@gmail.com>)
List pgsql-bugs
>>>>> "Sreeni" == Sreeni Survi <sreenisurvi@gmail.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)


pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: BUG #15602: pg_dump archive items not in correct section order
Next
From: Tom Lane
Date:
Subject: Re: to_char function returning wrong data