Issue in to_timestamp/to_date while handling the quoted literal string

From: Suraj Kharage <suraj(dot)kharage(at)enterprisedb(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Issue in to_timestamp/to_date while handling the quoted literal string
Date: 2019-07-24 11:38:15
Message-ID: CAF1DzPW_zT7BNqKxS87GF_RWRude2sJ8tJzOJ2HCOqtSaVuQCA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

I noticed the issue in to_timestamp()/to_date() while handling the double
quote literal string. If any double quote literal characters found in
format, we generate the NODE_TYPE_CHAR in parse format and store that
actual character in FormatNode->character. n DCH_from_char, we just
increment the input string by length of character for NODE_TYPE_CHAR.
We are actually not matching these characters in input string and because
of this, date values get changed if quoted literal string is not identical
in input and format string.

e.g:

postgres(at)78619=#select to_timestamp('2019-05-24T23:12:45',
'yyyy-mm-dd"TT"hh24:mi:ss');
to_timestamp
---------------------------
2019-05-24 03:12:45+05:30
(1 row)

In above example, the quoted string is 'TT', so it just increment the input
string by 2 while handling these characters and returned the wrong hour
value.

My suggestion is to match the exact characters from quoted literal string
in input string and if doesn't match then throw an error.

Attached is the POC patch which almost works for all scenarios except for
whitespace - as a quote character.

Suggestions?
--
--

Thanks & Regards,
Suraj kharage,
EnterpriseDB Corporation,
The Postgres Database Company.

Attachment Content-Type Size
to_timestamp_quoted_string_POC.patch application/octet-stream 1.2 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jesper Pedersen 2019-07-24 11:55:18 Re: pg_receivewal documentation
Previous Message Dave Cramer 2019-07-24 11:09:02 Re: Procedure support improvements