Skip to content

Fix incorrect parsing of timestamps in cast from varchar#14166

Merged
martint merged 1 commit intotrinodb:masterfrom
martint:varchar-to-timestamp-cast
Sep 17, 2022
Merged

Fix incorrect parsing of timestamps in cast from varchar#14166
martint merged 1 commit intotrinodb:masterfrom
martint:varchar-to-timestamp-cast

Conversation

@martint
Copy link
Copy Markdown
Member

@martint martint commented Sep 16, 2022

Trailing characters were incorrectly being treated as a timezone and ignored.

Fixes #14164

Release notes

(x) Release notes are required, with the following suggested text:

# General
* Fix incorrect parsing of invalid values in cast from `varchar` to `timestamp` ({issue}`14164`)

@cla-bot cla-bot bot added the cla-signed label Sep 16, 2022
@martint
Copy link
Copy Markdown
Member Author

martint commented Sep 16, 2022

There's some additional work needed. Per the SQL spec:

  1. If the rules for <literal> or for <unquoted timestamp string> in Subclause 5.3, “<literal>”, can be applied to SV to determine a valid value of the data type TD, then let TV be that value.
  2. If the rules for <literal> or for <unquoted timestamp string> in Subclause 5.3, “<literal>”, can be applied to SV to determine a valid value of the data type TIMESTAMP(TSP) WITH TIME ZONE, then let TV be the value of:
    CAST ( CAST ( VE AS TIMESTAMP(TSP) WITH TIME ZONE ) AS TIMESTAMP(TSP) WITHOUT TIME ZONE )

Therefore, if the string is a valid timestamp with time zone value, it needs to be parsed as such first and then converted to timestamp without time zone according to the rules of the cast operation between those types.

@martint martint force-pushed the varchar-to-timestamp-cast branch 2 times, most recently from 0d751f4 to 26b6a95 Compare September 16, 2022 19:35
Trailing characters were incorrectly being treated as a timezone and ignored.
@martint martint force-pushed the varchar-to-timestamp-cast branch from 26b6a95 to d5d1e7a Compare September 16, 2022 21:10
@martint martint merged commit cfc12aa into trinodb:master Sep 17, 2022
@github-actions github-actions bot added this to the 397 milestone Sep 17, 2022
@martint martint deleted the varchar-to-timestamp-cast branch November 1, 2022 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

Cast to timestamp ignores trailing content it does not recognize

3 participants