0001-apply-number-v4.patch
application/octet-stream
Filename: 0001-apply-number-v4.patch
Type: application/octet-stream
Part: 0
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: unified
Series: patch v4-0001
| File | + | − |
|---|---|---|
| src/backend/utils/adt/formatting.c | 10 | 5 |
| src/test/regress/expected/numeric.out | 33 | 0 |
| src/test/regress/sql/numeric.sql | 10 | 0 |
diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c
index 50254f2388..fec6d85f6a 100644
--- a/src/backend/utils/adt/formatting.c
+++ b/src/backend/utils/adt/formatting.c
@@ -4649,6 +4649,7 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout,
FormatNode *n;
NUMProc _Np,
*Np = &_Np;
+ int separator_len;
MemSet(Np, 0, sizeof(NUMProc));
@@ -4802,6 +4803,7 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout,
* Locale
*/
NUM_prepare_locale(Np);
+ separator_len = strlen(Np->L_thousands_sep);
/*
* Processor direct cycle
@@ -4872,6 +4874,8 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout,
if (IS_FILLMODE(Np->Num))
continue;
}
+ if (*Np->inout_p != ',')
+ continue;
}
break;
@@ -4884,10 +4888,8 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout,
continue;
else
{
- int x = strlen(Np->L_thousands_sep);
-
- memset(Np->inout_p, ' ', x);
- Np->inout_p += x - 1;
+ memset(Np->inout_p, ' ', separator_len);
+ Np->inout_p += separator_len - 1;
}
}
else
@@ -4903,7 +4905,10 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout,
if (IS_FILLMODE(Np->Num))
continue;
}
- Np->inout_p += strlen(Np->L_thousands_sep) - 1;
+ if (strncmp(Np->inout_p, Np->L_thousands_sep, separator_len) == 0)
+ Np->inout_p += separator_len - 1;
+ else
+ continue;
}
break;
diff --git a/src/test/regress/expected/numeric.out b/src/test/regress/expected/numeric.out
index 7e55b0e293..5a365bf7e7 100644
--- a/src/test/regress/expected/numeric.out
+++ b/src/test/regress/expected/numeric.out
@@ -1946,3 +1946,36 @@ SELECT SUM((-9999)::numeric) FROM generate_series(1, 100000);
-999900000
(1 row)
+--
+-- Tests to regression test TODO item 'Fix to_number() handling for values not matching the format string'
+--
+select to_number('34,50','999,99');
+ to_number
+-----------
+ 3450
+(1 row)
+
+select to_number('34,50','999G99');
+ to_number
+-----------
+ 3450
+(1 row)
+
+select to_number('12,34','999G99');
+ to_number
+-----------
+ 1234
+(1 row)
+
+select to_number('123,000','999G');
+ to_number
+-----------
+ 123
+(1 row)
+
+select to_number('123456','999G999');
+ to_number
+-----------
+ 123456
+(1 row)
+
diff --git a/src/test/regress/sql/numeric.sql b/src/test/regress/sql/numeric.sql
index 9675b6eabf..9106812b97 100644
--- a/src/test/regress/sql/numeric.sql
+++ b/src/test/regress/sql/numeric.sql
@@ -1013,3 +1013,13 @@ select scale(-13.000000000000000);
-- cases that need carry propagation
SELECT SUM(9999::numeric) FROM generate_series(1, 100000);
SELECT SUM((-9999)::numeric) FROM generate_series(1, 100000);
+
+--
+-- Tests to regression test TODO item 'Fix to_number() handling for values not matching the format string'
+--
+
+select to_number('34,50','999,99');
+select to_number('34,50','999G99');
+select to_number('12,34','999G99');
+select to_number('123,000','999G');
+select to_number('123456','999G999');