diff --git a/contrib/dolphin/expected/json_object.out b/contrib/dolphin/expected/json_object.out index e479bb62b586ae733b6c0d67ae6dee0f8c9cc4fd..a84954277f8d774d5d1bfe1fa39c6d74ee23f946 100644 --- a/contrib/dolphin/expected/json_object.out +++ b/contrib/dolphin/expected/json_object.out @@ -422,6 +422,14 @@ select json_object('{a,b,"a b c"}', '{a,1,1}'); {"a" : "a", "b" : "1", "a b c" : "1"} (1 row) +reset dolphin.b_compatibility_mode; +-- unknown 类型之外的null value +select json_object('City', 'Cairns', 'Population', DATE_FORMAT(null, '%Y-%m-%d')); + json_object +---------------------------------------- + {"City": "Cairns", "Population": null} +(1 row) + drop schema test_json_object cascade; NOTICE: drop cascades to 3 other objects DETAIL: drop cascades to table tab_json1 diff --git a/contrib/dolphin/plugin_utils/adt/json.cpp b/contrib/dolphin/plugin_utils/adt/json.cpp index 2783fe3aa2b01ae25b42bc3aa21e90d6494dde15..5d9f3b836697c978d4f0259c22288ecc47f004b2 100644 --- a/contrib/dolphin/plugin_utils/adt/json.cpp +++ b/contrib/dolphin/plugin_utils/adt/json.cpp @@ -2286,7 +2286,6 @@ Datum json_object_mysql(PG_FUNCTION_ARGS) Oid castfunc = InvalidOid; char *outputstr = NULL; StringInfo tempstr; - bool is_null = false; for (i = 0; i < cnt; i++) { if (PG_ARGISNULL(i * 2)) { ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("arg %d: key cannot be null", 2 * i + 1))); @@ -2355,7 +2354,6 @@ Datum json_object_mysql(PG_FUNCTION_ARGS) result = makeStringInfo(); appendStringInfoChar(result, '{'); for (i = 0; i < nargs; i += 2) { - is_null = false; order = i / 2; if (isValid[pos[order]] == false) { continue; @@ -2372,7 +2370,6 @@ Datum json_object_mysql(PG_FUNCTION_ARGS) val_type = TEXTOID; if (PG_ARGISNULL(2 * pos[order] + 1)) { arg = (Datum)0; - is_null = true; } else { arg = CStringGetTextDatum(PG_GETARG_POINTER(2 * pos[order] + 1)); } @@ -2383,7 +2380,7 @@ Datum json_object_mysql(PG_FUNCTION_ARGS) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("arg %d: could not determine data type", 2 * pos[order] + 2))); } - add_json(arg, is_null, result, val_type, false); + add_json(arg, PG_ARGISNULL(2 * pos[order] + 1), result, val_type, false); } appendStringInfoChar(result, '}'); for (int i = 0; i < cnt; i++) { diff --git a/contrib/dolphin/sql/json_object.sql b/contrib/dolphin/sql/json_object.sql index b68fbb64e1e1bcc22c44b2bc87b06ced0cab035d..75e6b60bc3a24aedb758a8d5e5ea8ddb231820b6 100644 --- a/contrib/dolphin/sql/json_object.sql +++ b/contrib/dolphin/sql/json_object.sql @@ -123,6 +123,9 @@ select json_object(data, my_text) from tab_json2; set dolphin.b_compatibility_mode = 0; select json_object('{a,1,b,2,3,NULL,"d e f","a b c"}'); select json_object('{a,b,"a b c"}', '{a,1,1}'); +reset dolphin.b_compatibility_mode; +-- unknown 类型之外的null value +select json_object('City', 'Cairns', 'Population', DATE_FORMAT(null, '%Y-%m-%d')); drop schema test_json_object cascade; reset current_schema; \ No newline at end of file