pgsql: Improve to_date/to_number/to_timestamp behavior with multibytec - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Improve to_date/to_number/to_timestamp behavior with multibytec
Date
Msg-id E1eG78u-0003f6-OA@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Improve to_date/to_number/to_timestamp behavior with multibyte characters.

The documentation says that these functions skip one input character
per literal (non-pattern) format character.  Actually, though, they
skipped one input *byte* per literal *byte*, which could be hugely
confusing if either data or format contained multibyte characters.

To fix, adjust the FormatNode representation and parse_format() so
that multibyte format characters are stored as one FormatNode not
several, and adjust the data-skipping bits to advance by pg_mblen()
not necessarily one byte.  There's no user-visible behavior change
on the to_char() side, although the internal representation changes.

Commit e87d4965b had already fixed most places where we skip characters
on the basis of non-literal format patterns to advance by characters
not bytes, but this gets one more place, the SKIP_THth macro.  I think
everything in formatting.c gets that right now.

It'd be nice to have some regression test cases covering this behavior;
but of course there's no way to do so in an encoding-agnostic way, and
many of the interesting aspects would also require unportable locale
selections.  So I've not bothered here.

Discussion: https://postgr.es/m/28186.1510957703@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/976a1a48fc35cde3c750982be64f872c4de4d343

Modified Files
--------------
src/backend/utils/adt/formatting.c | 68 +++++++++++++++++++++++---------------
1 file changed, 41 insertions(+), 27 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: Fix quoted-substring handling in format parsing forto_char/to_n
Next
From: Peter Eisentraut
Date:
Subject: pgsql: Consistently catch errors from Python _New() functions