aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/formatting.c
diff options
context:
space:
mode:
authorAlexander Korotkov <akorotkov@postgresql.org>2018-09-20 15:48:04 +0300
committerAlexander Korotkov <akorotkov@postgresql.org>2018-09-20 15:48:04 +0300
commit09e99ce86e3dfb4716618b1dda4074b45ba56a09 (patch)
treebf7a09a79b1a1076f657280e268e19662f5ee9c1 /src/backend/utils/adt/formatting.c
parent38763d67784c6563d08dbea5c9f913fa174779b8 (diff)
downloadpostgresql-09e99ce86e3dfb4716618b1dda4074b45ba56a09.tar.gz
postgresql-09e99ce86e3dfb4716618b1dda4074b45ba56a09.zip
Fix handling of format string text characters in to_timestamp()/to_date()
cf984672 introduced improvement of handling of spaces and separators in to_timestamp()/to_date() functions. In particular, now we're skipping spaces both before and after fields. That may cause format string text character to consume part of field in the situations, when it didn't happen before cf984672. This commit cause format string text character consume input string characters only when since previous field (or string beginning) number of skipped input string characters is not greater than number of corresponding format string characters (that is we didn't skip any extra characters in input string).
Diffstat (limited to 'src/backend/utils/adt/formatting.c')
-rw-r--r--src/backend/utils/adt/formatting.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c
index 2ed8ca675bd..0ed59f1c347 100644
--- a/src/backend/utils/adt/formatting.c
+++ b/src/backend/utils/adt/formatting.c
@@ -3061,9 +3061,24 @@ DCH_from_char(FormatNode *node, char *in, TmFromChar *out)
* Text character, so consume one character from input string.
* Notice we don't insist that the consumed character match the
* format's character.
- * Text field ignores FX mode.
*/
- s += pg_mblen(s);
+ if (!fx_mode)
+ {
+ /*
+ * In non FX mode we might have skipped some extra characters
+ * (more than specified in format string) before. In this
+ * case we don't skip input string character, because it might
+ * be part of field.
+ */
+ if (extra_skip > 0)
+ extra_skip--;
+ else
+ s += pg_mblen(s);
+ }
+ else
+ {
+ s += pg_mblen(s);
+ }
continue;
}