aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/jsonb.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2016-01-09 17:39:45 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2016-01-09 17:39:45 -0500
commit57da416933db2aee75485eff67b732063c978a48 (patch)
tree460a313e2bee64abe902a4f9eb3bf968ad185e4d /src/backend/utils/adt/jsonb.c
parentaa7e04cb56373f2209d30c89cd41b20191f252f9 (diff)
downloadpostgresql-57da416933db2aee75485eff67b732063c978a48.tar.gz
postgresql-57da416933db2aee75485eff67b732063c978a48.zip
Remove a useless PG_GETARG_DATUM() call from jsonb_build_array.
This loop uselessly fetched the argument after the one it's currently looking at. No real harm is done since we couldn't possibly fetch off the end of memory, but it's confusing to the reader. Also remove a duplicate (and therefore confusing) PG_ARGISNULL check in jsonb_build_object. I happened to notice these things while trolling for missed null-arg checks earlier today. Back-patch to 9.5, not because there is any real bug, but just because 9.5 and HEAD are still in sync in this file and we might as well keep them so. In passing, re-pgindent.
Diffstat (limited to 'src/backend/utils/adt/jsonb.c')
-rw-r--r--src/backend/utils/adt/jsonb.c16
1 files changed, 5 insertions, 11 deletions
diff --git a/src/backend/utils/adt/jsonb.c b/src/backend/utils/adt/jsonb.c
index 5bebc952fa4..7e01432546d 100644
--- a/src/backend/utils/adt/jsonb.c
+++ b/src/backend/utils/adt/jsonb.c
@@ -721,7 +721,7 @@ datum_to_jsonb(Datum val, bool is_null, JsonbInState *result,
{
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("key value must be scalar, not array, composite, or json")));
+ errmsg("key value must be scalar, not array, composite, or json")));
}
else
{
@@ -1187,7 +1187,6 @@ jsonb_build_object(PG_FUNCTION_ARGS)
for (i = 0; i < nargs; i += 2)
{
-
/* process key */
if (PG_ARGISNULL(i))
@@ -1203,10 +1202,7 @@ jsonb_build_object(PG_FUNCTION_ARGS)
if (val_type == UNKNOWNOID && get_fn_expr_arg_stable(fcinfo->flinfo, i))
{
val_type = TEXTOID;
- if (PG_ARGISNULL(i))
- arg = (Datum) 0;
- else
- arg = CStringGetTextDatum(PG_GETARG_POINTER(i));
+ arg = CStringGetTextDatum(PG_GETARG_POINTER(i));
}
else
{
@@ -1215,7 +1211,7 @@ jsonb_build_object(PG_FUNCTION_ARGS)
if (val_type == InvalidOid || val_type == UNKNOWNOID)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("argument %d: could not determine data type", i + 1)));
+ errmsg("argument %d: could not determine data type", i + 1)));
add_jsonb(arg, false, &result, val_type, true);
@@ -1238,9 +1234,8 @@ jsonb_build_object(PG_FUNCTION_ARGS)
if (val_type == InvalidOid || val_type == UNKNOWNOID)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("argument %d: could not determine data type", i + 2)));
+ errmsg("argument %d: could not determine data type", i + 2)));
add_jsonb(arg, PG_ARGISNULL(i + 1), &result, val_type, false);
-
}
result.res = pushJsonbValue(&result.parseState, WJB_END_OBJECT, NULL);
@@ -1283,7 +1278,6 @@ jsonb_build_array(PG_FUNCTION_ARGS)
for (i = 0; i < nargs; i++)
{
val_type = get_fn_expr_argtype(fcinfo->flinfo, i);
- arg = PG_GETARG_DATUM(i + 1);
/* see comments in jsonb_build_object above */
if (val_type == UNKNOWNOID && get_fn_expr_arg_stable(fcinfo->flinfo, i))
{
@@ -1300,7 +1294,7 @@ jsonb_build_array(PG_FUNCTION_ARGS)
if (val_type == InvalidOid || val_type == UNKNOWNOID)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("argument %d: could not determine data type", i + 1)));
+ errmsg("argument %d: could not determine data type", i + 1)));
add_jsonb(arg, PG_ARGISNULL(i), &result, val_type, false);
}