Re: [HACKERS] Bug in to_timestamp().
Alexander Korotkov <a.korotkov@postgrespro.ru>
From: Alexander Korotkov <a.korotkov@postgrespro.ru>
To: amul sul <sulamul@gmail.com>
Cc: prabhat.sahu@enterprisedb.com, "David G. Johnston" <david.g.johnston@gmail.com>,
Artur Zakirov <a.zakirov@postgrespro.ru>, Tom Lane <tgl@sss.pgh.pa.us>, Dmitry Dolgov <9erthalion6@gmail.com>, Robert Haas <robertmhaas@gmail.com>,
Thomas Munro <thomas.munro@enterprisedb.com>, Pavel Stehule <pavel.stehule@gmail.com>,
Alex Ignatov <a.ignatov@postgrespro.ru>, Bruce Momjian <bruce@momjian.us>, amul sul <sul_amul@yahoo.co.in>, pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2018-09-20T12:52:51Z
Lists: pgsql-hackers
On Thu, Sep 20, 2018 at 6:09 AM amul sul <sulamul@gmail.com> wrote:
> On Thu, Sep 20, 2018, 3:22 AM Alexander Korotkov <a.korotkov@postgrespro.ru> wrote:
>> It's hard to understand whether it was expected, because it wasn't
>> properly documented. More important that it's the same behavior we
>> have before cf984672, and purpose of cf984672 was not to change this.
>>
>> But from the code comments, it's intentional. If you put digits or
>> text characters into format string, you can skip non-separator input
>> string characters. For instance you may do.
>>
>> # SELECT to_date('y18y12y2011', 'xDDxMMxYYYY');
>> to_date
>> ------------
>> 2011-12-18
>> (1 row)
>>
>> It's even more interesting that letters and digits are handled in
>> different manner.
>>
>> # SELECT to_date('01801202011', 'xDDxMMxYYYY');
>> ERROR: date/time field value out of range: "01801202011"
>> Time: 0,453 ms
>>
>> # SELECT to_date('01801202011', '9DD9MM9YYYY');
>> to_date
>> ------------
>> 2011-12-18
>> (1 row)
>>
>> So, letters in format string doesn't allow you to extract fields at
>> particular positions of digit sequence, but digits in format string
>> allows you to. That's rather undocumented, but from the code you can
>> get that it's intentional. Thus, I think it would be nice to improve
>> the documentation here. But I still propose to commit the patch I
>> propose to bring back unintentional behavior change in cf984672.
>
> Agreed, thanks for working on this.
Pushed, thanks.
------
Alexander Korotkov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company
Commits
-
Improve behavior of to_timestamp()/to_date() functions
- cf984672427e 12.0 landed
-
Implement TZH and TZM timestamp format patterns
- 11b623dd0a2c 11.0 cited
-
as attache of this mail is patch (to the main tree) with to_char's
- b866d2e2d794 7.1.1 cited