diff --git a/contrib/dolphin/expected/json_extract.out b/contrib/dolphin/expected/json_extract.out index b11b3bf935c95334cfcc606368b64ebdf8286343..02c8aabc907825dd6606dfffdc2bcd11e49007f1 100644 --- a/contrib/dolphin/expected/json_extract.out +++ b/contrib/dolphin/expected/json_extract.out @@ -175,9 +175,9 @@ select json_extract(1, null); ERROR: Invalid data type for JSON data in argument 1 to function json_extract CONTEXT: referenced column: json_extract select json_extract('{"a": 341522654875451.12345678901234567890123456789012345678901234567}', '$.a'); - json_extract --------------------- - 341522654875451.12 + json_extract +----------------------------------------------------------------- + 341522654875451.12345678901234567890123456789012345678901234567 (1 row) create temp table test ( @@ -218,5 +218,53 @@ select * from test; {"c": true} (5 rows) +select json_extract('{"id": "7", "name": 9223372036854775805}', '$.name'); + json_extract +--------------------- + 9223372036854775805 +(1 row) + +select json_extract('{"id": "7", "name": 9223372036854775806}', '$.name'); + json_extract +--------------------- + 9223372036854775806 +(1 row) + +select json_extract('{"id": "7", "name": 9223372036854775807}', '$.name'); + json_extract +--------------------- + 9223372036854775807 +(1 row) + +select json_extract('{"id": "7", "name": 9223372036854776000}', '$.name'); + json_extract +--------------------- + 9223372036854776000 +(1 row) + +select json_extract('{"id": "7", "name": 9223372036854776001}', '$.name'); + json_extract +--------------------- + 9223372036854776001 +(1 row) + +select json_extract('{"id": "7", "name": 9.223372036854776e18}', '$.name'); + json_extract +---------------------- + 9.223372036854776e18 +(1 row) + +select json_extract('{"id": "7", "name": 9223372036854775805}', '$.name') < json_extract('{"id": "7", "name": 9223372036854775806}', '$.name'); + ?column? +---------- + t +(1 row) + +select json_extract('{"id": "7", "name": 9223372036854775805}', '$.name') = json_extract('{"id": "7", "name": 9223372036854775806}', '$.name'); + ?column? +---------- + f +(1 row) + drop schema test_json_extract cascade; reset current_schema; diff --git a/contrib/dolphin/expected/json_merge_patch.out b/contrib/dolphin/expected/json_merge_patch.out index 995a22c28cd80618f619b44d594b1ae4390beba1..520d02486916df45a2b6e8afb368fb914f5705bf 100644 --- a/contrib/dolphin/expected/json_merge_patch.out +++ b/contrib/dolphin/expected/json_merge_patch.out @@ -316,9 +316,9 @@ select json_merge_patch(1,null,'1'); ERROR: Invalid data type for JSON data in argument 1 to function json_merge_patch CONTEXT: referenced column: json_merge_patch select json_merge_patch('["a",1,{"a":"abc"}]','["b",341522654875451.12345678901234567890123456789012345678901234567,{"b":"bcd"}]'); - json_merge_patch ------------------------------------------ - ["b", 341522654875451.12, {"b": "bcd"}] + json_merge_patch +-------------------------------------------------------------------------------------- + ["b", 341522654875451.12345678901234567890123456789012345678901234567, {"b": "bcd"}] (1 row) create table test ( diff --git a/contrib/dolphin/expected/json_merge_preserve.out b/contrib/dolphin/expected/json_merge_preserve.out index 49cdfbf2a5d23039a5e0eb449b8957d2f610f2e5..dcf93760368c2d3f6a6ef38cd89f7f51d0eb8f12 100644 --- a/contrib/dolphin/expected/json_merge_preserve.out +++ b/contrib/dolphin/expected/json_merge_preserve.out @@ -316,9 +316,9 @@ select json_merge_preserve(1,null,'1'); ERROR: Invalid data type for JSON data in argument 1 to function json_merge_preserve CONTEXT: referenced column: json_merge_preserve select json_merge_preserve('["a",1,{"a":"abc"}]','["b",341522654875451.12345678901234567890123456789012345678901234567,{"b":"bcd"}]'); - json_merge_preserve ---------------------------------------------------------------- - ["a", 1, {"a": "abc"}, "b", 341522654875451.12, {"b": "bcd"}] + json_merge_preserve +------------------------------------------------------------------------------------------------------------ + ["a", 1, {"a": "abc"}, "b", 341522654875451.12345678901234567890123456789012345678901234567, {"b": "bcd"}] (1 row) create table test ( diff --git a/contrib/dolphin/plugin_utils/adt/jsonfuncs.cpp b/contrib/dolphin/plugin_utils/adt/jsonfuncs.cpp index 9549f40d5e4d38425217ee514f5a7cd29189c122..7c4345661215dd1ad95a61dfb1bb5a88a8d7e701 100644 --- a/contrib/dolphin/plugin_utils/adt/jsonfuncs.cpp +++ b/contrib/dolphin/plugin_utils/adt/jsonfuncs.cpp @@ -4298,6 +4298,28 @@ Datum json_textcontains(PG_FUNCTION_ARGS) } #ifdef DOLPHIN + + + +void replace_json_double_to_numeric(cJSON *root) +{ + cJSON *item = NULL; + if (root == NULL) { + return; + } + if (root->type == cJSON_Number && root->valuestring != NULL) { + root->type = cJSON_Raw; + } + cJSON_ArrayForEach(item, root) { + const char *key = item->string; + cJSON *value = item; + if (item->type == cJSON_Number && item->valuestring != NULL) { + item->type = cJSON_Raw; + } + } +} + + static cJSON *input_to_cjson(Oid valtype, const char *funcName, int pos, Datum arg) { Oid typOutput; @@ -5482,6 +5504,7 @@ Datum json_extract(PG_FUNCTION_ARGS) valtype = get_fn_expr_argtype(fcinfo->flinfo, 0); arg = PG_GETARG_DATUM(0); root = input_to_cjson(valtype, "json_extract", 1, arg); + replace_json_double_to_numeric(root); cJSON_SortObject(root); deconstruct_array(in_array, TEXTOID, -1, false, 'i', &in_datums, &in_nulls, &in_count); @@ -6398,6 +6421,10 @@ static void json_regular_format(StringInfo result, cJSON *json) escape_json(result, json->valuestring); break; } + case cJSON_Raw :{ + appendStringInfoString(result, json->valuestring); + break; + } default: elog(ERROR, "unexpected json type: %d", (json->type & 0xFF)); } @@ -7680,6 +7707,7 @@ static cJSON *input_to_cjson_cmp(Oid valtype, Datum arg, bool& jsontype) { } else { jsontype = false; } + replace_json_double_to_numeric(root); return root; } diff --git a/contrib/dolphin/sql/json_extract.sql b/contrib/dolphin/sql/json_extract.sql index aeb103bf4d1ccb5c15cd54eb950d5358b88505d5..0b0b1d33ffd212667c067609ba7d1c9d2460f3b0 100644 --- a/contrib/dolphin/sql/json_extract.sql +++ b/contrib/dolphin/sql/json_extract.sql @@ -54,5 +54,16 @@ insert into test values (json_extract('{"a": 43, "b": {"c": true}}', '$.b')); select * from test; + +select json_extract('{"id": "7", "name": 9223372036854775805}', '$.name'); +select json_extract('{"id": "7", "name": 9223372036854775806}', '$.name'); +select json_extract('{"id": "7", "name": 9223372036854775807}', '$.name'); +select json_extract('{"id": "7", "name": 9223372036854776000}', '$.name'); +select json_extract('{"id": "7", "name": 9223372036854776001}', '$.name'); +select json_extract('{"id": "7", "name": 9.223372036854776e18}', '$.name'); + +select json_extract('{"id": "7", "name": 9223372036854775805}', '$.name') < json_extract('{"id": "7", "name": 9223372036854775806}', '$.name'); +select json_extract('{"id": "7", "name": 9223372036854775805}', '$.name') = json_extract('{"id": "7", "name": 9223372036854775806}', '$.name'); + drop schema test_json_extract cascade; reset current_schema; \ No newline at end of file