pgsql: Prevent to_number() from losing data when template doesn'tmatch

Поиск
Список
Период
Сортировка
От Tom Lane
Тема pgsql: Prevent to_number() from losing data when template doesn'tmatch
Дата
Msg-id E1eFk42-0000Mh-7q@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Prevent to_number() from losing data when template doesn't match exactly.

Non-data template patterns would consume characters whether or not those
characters were what the pattern expected, for exampleSELECT TO_NUMBER('1234', '9,999');
produced 134 because the '2' got eaten by the comma pattern.  This seems
undesirable, not least because it doesn't happen in Oracle.  For the ','
and 'G' template patterns, we can fix this by consuming characters only
if they match what the pattern would output.  For non-data patterns such
as 'L' and 'TH', it seems impractical to tighten things up to the point of
consuming only exact matches to what the pattern would output; but we can
improve matters quite a lot by redefining the behavior as "consume only
characters that aren't digits, signs, decimal point, or comma".

Also, fix it so that the behavior is to consume the number of *characters*
the pattern would output, not the number of *bytes*.  The old coding would
do surprising things with non-ASCII currency symbols, for example.  (It
would be good to apply that rule for literal text as well, but this commit
only fixes it for non-data patterns.)

Oliver Ford, reviewed by Thomas Munro and Nathan Wagner, and whacked around
a bit more by me

Discussion: https://postgr.es/m/CAGMVOdvpbMqPf9XWNzOwBpzJfErkydr_fEGhmuDGa015z97mwg@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/e87d4965bd39e4d0d56346c1bbe9361d3eb9ff0a

Modified Files
--------------
doc/src/sgml/func.sgml                |  28 +++++--
src/backend/utils/adt/formatting.c    | 134 +++++++++++++++++++++++++++-------
src/test/regress/expected/numeric.out |  56 ++++++++++++++
src/test/regress/sql/numeric.sql      |  11 +++
4 files changed, 197 insertions(+), 32 deletions(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Robert Haas
Дата:
Сообщение: pgsql: Set proargmodes for satisfies_hash_partition.
Следующее
От: Tom Lane
Дата:
Сообщение: pgsql: Provide modern examples of how to auto-start Postgres on macOS.