From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | pgsql-committers(at)postgresql(dot)org |
Subject: | pgsql: Fix quoted-substring handling in format parsing for to_char/to_n |
Date: | 2017-11-18 17:16:46 |
Message-ID: | E1eG6jW-00039I-Iv@gemulon.postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-committers |
Fix quoted-substring handling in format parsing for to_char/to_number/etc.
This code evidently intended to treat backslash as an escape character
within double-quoted substrings, but it was sufficiently confused that
cases like ..."foo\\"... did not work right: the second backslash
managed to quote the double-quote after it, despite being quoted itself.
Rewrite to get that right, while preserving the existing behavior
outside double-quoted substrings, which is that backslash isn't special
except in the combination \".
Comparing to Oracle, it seems that their version of to_char() for
timestamps allows literal alphanumerics only within double quotes, while
non-alphanumerics are allowed outside quotes; backslashes aren't special
anywhere; there is no way at all to emit a literal double quote.
(Bizarrely, their to_char() for numbers is different; it doesn't allow
literal text at all AFAICT.) The fact that they don't treat backslash
as special justifies our existing behavior for backslash outside double
quotes. I considered making backslash inside double quotes act the same
way (ie, special only if before "), which in a green field would be a
more consistent behavior. But that would likely break more existing SQL
code than what this patch does.
Add some test cases illustrating this behavior. (Only the last new
case actually changes behavior in this commit.)
Little of this behavior was documented, either, so fix that.
Discussion: https://postgr.es/m/3626.1510949486@sss.pgh.pa.us
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/63ca86318dc3d6a768eed78efbc6ca014a0622a8
Modified Files
--------------
doc/src/sgml/func.sgml | 5 +++
src/backend/utils/adt/formatting.c | 70 +++++++++++++----------------------
src/test/regress/expected/numeric.out | 61 ++++++++++++++++++++++++++++++
src/test/regress/sql/numeric.sql | 12 ++++++
4 files changed, 104 insertions(+), 44 deletions(-)
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2017-11-18 17:43:00 | pgsql: Improve to_date/to_number/to_timestamp behavior with multibyte c |
Previous Message | Peter Eisentraut | 2017-11-18 15:52:59 | pgsql: Support channel binding 'tls-unique' in SCRAM |