Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit31f403e

Browse files
committed
Further tweaking of jsonb_set_lax().
Some buildfarm members were still warning about this, because in9c679a0 I'd missed decorating one of the ereport() code pathswith a dummy return.Also, adjust the error messages to be more in line with projectstyle guide.
1 parentcd23a20 commit31f403e

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

‎src/backend/utils/adt/jsonfuncs.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4415,7 +4415,7 @@ jsonb_set_lax(PG_FUNCTION_ARGS)
44154415
if (PG_ARGISNULL(4))
44164416
ereport(ERROR,
44174417
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4418-
errmsg("needdelete_key,return_target,use_json_null, or raise_exception")));
4418+
errmsg("null_value_treatment must be \"delete_key\", \"return_target\", \"use_json_null\", or\"raise_exception\"")));
44194419

44204420
/* if the new value isn't an SQL NULL just call jsonb_set */
44214421
if (!PG_ARGISNULL(2))
@@ -4428,9 +4428,10 @@ jsonb_set_lax(PG_FUNCTION_ARGS)
44284428
{
44294429
ereport(ERROR,
44304430
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
4431-
errmsg("NULL is not allowed"),
4432-
errdetail("exception raised due to \"null_value_treatment => 'raise_exception'\""),
4433-
errhint("to avoid, either change the null_value_treatment argument or ensure that an SQL NULL is not used")));
4431+
errmsg("JSON value must not be null"),
4432+
errdetail("Exception was raised because null_value_treatment is \"raise_exception\"."),
4433+
errhint("To avoid, either change the null_value_treatment argument or ensure that an SQL NULL is not passed.")));
4434+
return (Datum)0;/* silence stupider compilers */
44344435
}
44354436
elseif (strcmp(handle_val,"use_json_null")==0)
44364437
{
@@ -4455,7 +4456,7 @@ jsonb_set_lax(PG_FUNCTION_ARGS)
44554456
{
44564457
ereport(ERROR,
44574458
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4458-
errmsg("needdelete_key,return_target,use_json_null, or raise_exception")));
4459+
errmsg("null_value_treatment must be \"delete_key\", \"return_target\", \"use_json_null\", or\"raise_exception\"")));
44594460
return (Datum)0;/* silence stupider compilers */
44604461
}
44614462
}

‎src/test/regress/expected/jsonb.out

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4541,14 +4541,14 @@ select jsonb_set_lax('{"a":1,"b":2}','{d}',null,true);
45414541

45424542
-- errors
45434543
select jsonb_set_lax('{"a":1,"b":2}', '{b}', null, true, null);
4544-
ERROR:needdelete_key,return_target,use_json_null, or raise_exception
4544+
ERROR:null_value_treatment must be "delete_key", "return_target", "use_json_null", or"raise_exception"
45454545
select jsonb_set_lax('{"a":1,"b":2}', '{b}', null, true, 'no_such_treatment');
4546-
ERROR:needdelete_key,return_target,use_json_null, or raise_exception
4546+
ERROR:null_value_treatment must be "delete_key", "return_target", "use_json_null", or"raise_exception"
45474547
-- explicit treatments
45484548
select jsonb_set_lax('{"a":1,"b":2}', '{b}', null, null_value_treatment => 'raise_exception') as raise_exception;
4549-
ERROR:NULL isnotallowed
4550-
DETAIL:exceptionraiseddue to "null_value_treatment=> 'raise_exception'"
4551-
HINT:to avoid, either change the null_value_treatment argument or ensure that an SQL NULL is notused
4549+
ERROR:JSON value mustnotbe null
4550+
DETAIL:Exception wasraisedbecausenull_value_treatmentis "raise_exception".
4551+
HINT:To avoid, either change the null_value_treatment argument or ensure that an SQL NULL is notpassed.
45524552
select jsonb_set_lax('{"a":1,"b":2}', '{b}', null, null_value_treatment => 'return_target') as return_target;
45534553
return_target
45544554
------------------

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp