Re: [HACKERS] Bug in to_timestamp().
Amul Sul <sulamul@gmail.com>
From: amul sul <sulamul@gmail.com>
To: Alexander Korotkov <a.korotkov@postgrespro.ru>
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>, PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2018-09-19T10:21:37Z
Lists: pgsql-hackers
On Wed, Sep 19, 2018 at 2:57 PM Alexander Korotkov
<a.korotkov@postgrespro.ru> wrote:
>
> On Tue, Sep 18, 2018 at 4:42 PM Alexander Korotkov
> <a.korotkov@postgrespro.ru> wrote:
> > But, I found related issue in cf9846724. Before it was:
> >
> > # select to_timestamp('2018 01 01', 'YYYY9MM9DD');
> > to_timestamp
> > ------------------------
> > 2018-01-01 00:00:00+03
> > (1 row)
> >
> > But after it becomes so.
> >
> > # select to_timestamp('2018 01 01', 'YYYY9MM9DD');
> > ERROR: invalid value "1 " for "MM"
> > DETAIL: Field requires 2 characters, but only 1 could be parsed.
> > HINT: If your source string is not fixed-width, try using the "FM" modifier.
> >
> > That happens because we've already skipped space "for free", and then
> > NODE_TYPE_CHAR eats digit. I've checked that Oracle doesn't allow
> > random charaters/digits to appear in format string.
> >
> > select to_timestamp('2018 01 01', 'YYYY9MM9DD') from dual
> > ORA-01821: date format not recognized
> >
> > So, Oracle compatibility isn't argument here. Therefore I'm going to
> > propose following fix for that: let NODE_TYPE_CHAR eat characters only
> > if we didn't skip input string characters more than it was in format
> > string. I'm sorry for vague explanation. I'll come up with patch
> > later, and it should be clear then.
>
> Please find attached patch for fixing this issue. It makes handling
> of format string text characters be similar to pre cf984672 behavior.
> See the examples in regression tests and explanation in the commit
> message. I'm going to commit this if no objections.
>
With this patch, to_date and to_timestamp behaving differently, see this:
edb=# SELECT to_date('18 12 2011', 'xDDxMMxYYYY');
to_date
--------------------
18-DEC-11 00:00:00
(1 row)
edb=# SELECT to_timestamp('18 12 2011', 'xDDxMMxYYYY');
to_timestamp
---------------------------
08-DEC-11 00:00:00 -05:00 <=========== Incorrect output.
(1 row)
Regards,
Amul
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