Commit 31f403e9 authored by Tom Lane's avatar Tom Lane

Further tweaking of jsonb_set_lax().

Some buildfarm members were still warning about this, because in
9c679a08 I'd missed decorating one of the ereport() code paths
with a dummy return.

Also, adjust the error messages to be more in line with project
style guide.
parent cd23a201
...@@ -4415,7 +4415,7 @@ jsonb_set_lax(PG_FUNCTION_ARGS) ...@@ -4415,7 +4415,7 @@ jsonb_set_lax(PG_FUNCTION_ARGS)
if (PG_ARGISNULL(4)) if (PG_ARGISNULL(4))
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE), (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("need delete_key, return_target, use_json_null, or raise_exception"))); errmsg("null_value_treatment must be \"delete_key\", \"return_target\", \"use_json_null\", or \"raise_exception\"")));
/* if the new value isn't an SQL NULL just call jsonb_set */ /* if the new value isn't an SQL NULL just call jsonb_set */
if (! PG_ARGISNULL(2)) if (! PG_ARGISNULL(2))
...@@ -4428,9 +4428,10 @@ jsonb_set_lax(PG_FUNCTION_ARGS) ...@@ -4428,9 +4428,10 @@ jsonb_set_lax(PG_FUNCTION_ARGS)
{ {
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
errmsg("NULL is not allowed"), errmsg("JSON value must not be null"),
errdetail("exception raised due to \"null_value_treatment => 'raise_exception'\""), errdetail("Exception was raised because null_value_treatment is \"raise_exception\"."),
errhint("to avoid, either change the null_value_treatment argument or ensure that an SQL NULL is not used"))); errhint("To avoid, either change the null_value_treatment argument or ensure that an SQL NULL is not passed.")));
return (Datum) 0; /* silence stupider compilers */
} }
else if (strcmp(handle_val, "use_json_null") == 0) else if (strcmp(handle_val, "use_json_null") == 0)
{ {
...@@ -4455,7 +4456,7 @@ jsonb_set_lax(PG_FUNCTION_ARGS) ...@@ -4455,7 +4456,7 @@ jsonb_set_lax(PG_FUNCTION_ARGS)
{ {
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE), (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("need delete_key, return_target, use_json_null, or raise_exception"))); errmsg("null_value_treatment must be \"delete_key\", \"return_target\", \"use_json_null\", or \"raise_exception\"")));
return (Datum) 0; /* silence stupider compilers */ return (Datum) 0; /* silence stupider compilers */
} }
} }
......
...@@ -4541,14 +4541,14 @@ select jsonb_set_lax('{"a":1,"b":2}','{d}',null,true); ...@@ -4541,14 +4541,14 @@ select jsonb_set_lax('{"a":1,"b":2}','{d}',null,true);
-- errors -- errors
select jsonb_set_lax('{"a":1,"b":2}', '{b}', null, true, null); select jsonb_set_lax('{"a":1,"b":2}', '{b}', null, true, null);
ERROR: need delete_key, return_target, use_json_null, or raise_exception ERROR: null_value_treatment must be "delete_key", "return_target", "use_json_null", or "raise_exception"
select jsonb_set_lax('{"a":1,"b":2}', '{b}', null, true, 'no_such_treatment'); select jsonb_set_lax('{"a":1,"b":2}', '{b}', null, true, 'no_such_treatment');
ERROR: need delete_key, return_target, use_json_null, or raise_exception ERROR: null_value_treatment must be "delete_key", "return_target", "use_json_null", or "raise_exception"
-- explicit treatments -- explicit treatments
select jsonb_set_lax('{"a":1,"b":2}', '{b}', null, null_value_treatment => 'raise_exception') as raise_exception; select jsonb_set_lax('{"a":1,"b":2}', '{b}', null, null_value_treatment => 'raise_exception') as raise_exception;
ERROR: NULL is not allowed ERROR: JSON value must not be null
DETAIL: exception raised due to "null_value_treatment => 'raise_exception'" DETAIL: Exception was raised because null_value_treatment is "raise_exception".
HINT: to avoid, either change the null_value_treatment argument or ensure that an SQL NULL is not used HINT: To avoid, either change the null_value_treatment argument or ensure that an SQL NULL is not passed.
select jsonb_set_lax('{"a":1,"b":2}', '{b}', null, null_value_treatment => 'return_target') as return_target; select jsonb_set_lax('{"a":1,"b":2}', '{b}', null, null_value_treatment => 'return_target') as return_target;
return_target return_target
------------------ ------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment