Skip to content

Commit 31f403e

Browse files
committed
Further tweaking of jsonb_set_lax().
Some buildfarm members were still warning about this, because in 9c679a0 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.
1 parent cd23a20 commit 31f403e

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("need delete_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
else if (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("need delete_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: need delete_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: need delete_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 is not allowed
4550-
DETAIL: exception raised due to "null_value_treatment => 'raise_exception'"
4551-
HINT: to avoid, either change the null_value_treatment argument or ensure that an SQL NULL is not used
4549+
ERROR: JSON value must not be null
4550+
DETAIL: Exception was raised because null_value_treatment is "raise_exception".
4551+
HINT: To avoid, either change the null_value_treatment argument or ensure that an SQL NULL is not passed.
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy