Re: [HACKERS] Bug in to_timestamp().
Artur Zakirov <a.zakirov@postgrespro.ru>
From: Arthur Zakirov <a.zakirov@postgrespro.ru>
To: "David G. Johnston" <david.g.johnston@gmail.com>
Cc: Alexander Korotkov <a.korotkov@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>, amul sul <sulamul@gmail.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-07-23T14:12:55Z
Lists: pgsql-hackers
On Mon, Jul 23, 2018 at 04:30:43PM +0300, Arthur Zakirov wrote:
> I looked for some tradeoffs of the patch. I think it could be parsing
> strings like the following input strings:
>
> SELECT TO_TIMESTAMP('2011年5月1日', 'yyyy-MM-DD');
> SELECT TO_TIMESTAMP('2011y5m1d', 'yyyy-MM-DD');
>
> HEAD extracts year, month and day from the string. But patched
> to_timestamp() raises an error. Someone could rely on such behaviour.
> The patch divides separator characters from letters and digits. And
> '年' or 'y' are letters here. And so the format string doesn't match the
> input string.
Sorry, I forgot to mention that the patch can handle this by using
different format string. You can execute:
=# SELECT TO_TIMESTAMP('2011年5月1日', 'yyyy年MM月DD日');
to_timestamp
------------------------
2011-05-01 00:00:00+04
=# SELECT TO_TIMESTAMP('2011y5m1d', 'yyyy"y"MM"m"DD"d"');
to_timestamp
------------------------
2011-05-01 00:00:00+04
or:
=# SELECT TO_TIMESTAMP('2011y5m1d', 'yyyytMMtDDt');
to_timestamp
------------------------
2011-05-01 00:00:00+04
--
Arthur Zakirov
Postgres Professional: http://www.postgrespro.com
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