| From: | Alexander Korotkov <a(dot)korotkov(at)postgrespro(dot)ru> | 
|---|---|
| To: | amul sul <sulamul(at)gmail(dot)com> | 
| Cc: | prabhat(dot)sahu(at)enterprisedb(dot)com, "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Alex Ignatov <a(dot)ignatov(at)postgrespro(dot)ru>, Bruce Momjian <bruce(at)momjian(dot)us>, amul sul <sul_amul(at)yahoo(dot)co(dot)in>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org> | 
| Subject: | Re: [HACKERS] Bug in to_timestamp(). | 
| Date: | 2018-09-20 12:52:51 | 
| Message-ID: | CAPpHfdv4x3J0NOO2Qb7bv2JoBYRuKK11+v6zew_7yoerX0QRXA@mail.gmail.com | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-hackers | 
On Thu, Sep 20, 2018 at 6:09 AM amul sul <sulamul(at)gmail(dot)com> wrote:
> On Thu, Sep 20, 2018, 3:22 AM Alexander Korotkov <a(dot)korotkov(at)postgrespro(dot)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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tomas Vondra | 2018-09-20 13:04:57 | Re: fast default vs triggers | 
| Previous Message | Masahiko Sawada | 2018-09-20 12:51:34 | Re: when set track_commit_timestamp on, database system abort startup |