Skip to content

Commit 537da8a

Browse files
author
Nikita Glukhov
committed
Fix json_/jsonb_ prefix in error messages
1 parent aa2e9dc commit 537da8a

File tree

4 files changed

+28
-18
lines changed

4 files changed

+28
-18
lines changed

src/backend/utils/adt/json.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*/
1414

1515
#define JSON_C
16+
#define JSONB "json"
1617

1718
#define JSONXOID JSONOID
1819

src/backend/utils/adt/jsonb.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,7 @@ jsonb_build_object(PG_FUNCTION_ARGS)
11771177
errmsg("argument list must have even number of elements"),
11781178
/* translator: %s is a SQL function name */
11791179
errhint("The arguments of %s must consist of alternating keys and values.",
1180-
"jsonb_build_object()")));
1180+
JSONB"_build_object()")));
11811181

11821182
memset(&result, 0, sizeof(JsonbInState));
11831183

@@ -1189,7 +1189,12 @@ jsonb_build_object(PG_FUNCTION_ARGS)
11891189
if (nulls[i])
11901190
ereport(ERROR,
11911191
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1192+
#ifdef JSON_C
1193+
errmsg("argument %d cannot be null", i + 1),
1194+
errhint("Object keys should be text.")));
1195+
#else
11921196
errmsg("argument %d: key must not be null", i + 1)));
1197+
#endif
11931198

11941199
add_jsonb(args[i], false, &result, types[i], true);
11951200

@@ -1488,7 +1493,7 @@ jsonb_agg_transfn(PG_FUNCTION_ARGS)
14881493
if (!AggCheckCallContext(fcinfo, &aggcontext))
14891494
{
14901495
/* cannot be called directly because of internal-type argument */
1491-
elog(ERROR, "jsonb_agg_transfn called in non-aggregate context");
1496+
elog(ERROR, JSONB"_agg_transfn called in non-aggregate context");
14921497
}
14931498

14941499
/* set up the accumulator on the first go round */
@@ -1642,7 +1647,7 @@ jsonb_object_agg_transfn(PG_FUNCTION_ARGS)
16421647
if (!AggCheckCallContext(fcinfo, &aggcontext))
16431648
{
16441649
/* cannot be called directly because of internal-type argument */
1645-
elog(ERROR, "jsonb_object_agg_transfn called in non-aggregate context");
1650+
elog(ERROR, JSONB"_object_agg_transfn called in non-aggregate context");
16461651
}
16471652

16481653
/* set up the accumulator on the first go round */

src/backend/utils/adt/jsonfuncs.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -589,12 +589,12 @@ jsonb_object_keys(PG_FUNCTION_ARGS)
589589
ereport(ERROR,
590590
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
591591
errmsg("cannot call %s on a scalar",
592-
"jsonb_object_keys")));
592+
JSONB"_object_keys")));
593593
else if (JB_ROOT_IS_ARRAY(jb))
594594
ereport(ERROR,
595595
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
596596
errmsg("cannot call %s on an array",
597-
"jsonb_object_keys")));
597+
JSONB"_object_keys")));
598598

599599
funcctx = SRF_FIRSTCALL_INIT();
600600
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
@@ -1601,7 +1601,7 @@ get_jsonb_path_all(FunctionCallInfo fcinfo, bool as_text)
16011601
/* Container must be array, but make sure */
16021602

16031603
if (!JsonContainerIsArray(container))
1604-
elog(ERROR, "not a jsonb array");
1604+
elog(ERROR, "not a "JSONB" array");
16051605

16061606
nelements = JsonContainerSize(container) >= 0 ?
16071607
JsonContainerSize(container) :
@@ -1815,7 +1815,7 @@ json_each(PG_FUNCTION_ARGS)
18151815
Datum
18161816
jsonb_each(PG_FUNCTION_ARGS)
18171817
{
1818-
return each_worker_jsonb(fcinfo, "jsonb_each", false);
1818+
return each_worker_jsonb(fcinfo, JSONB"_each", false);
18191819
}
18201820

18211821
#ifndef JSON_GENERIC
@@ -1829,7 +1829,7 @@ json_each_text(PG_FUNCTION_ARGS)
18291829
Datum
18301830
jsonb_each_text(PG_FUNCTION_ARGS)
18311831
{
1832-
return each_worker_jsonb(fcinfo, "jsonb_each_text", true);
1832+
return each_worker_jsonb(fcinfo, JSONB"_each_text", true);
18331833
}
18341834

18351835
static Datum
@@ -1882,7 +1882,7 @@ each_worker_jsonb(FunctionCallInfo fcinfo, const char *funcname, bool as_text)
18821882
MemoryContextSwitchTo(old_cxt);
18831883

18841884
tmp_cxt = AllocSetContextCreate(CurrentMemoryContext,
1885-
"jsonb_each temporary cxt",
1885+
JSONB"_each temporary cxt",
18861886
ALLOCSET_DEFAULT_SIZES);
18871887

18881888
it = JsonbIteratorInit(JsonbRoot(jb));
@@ -2121,13 +2121,13 @@ each_scalar(void *state, char *token, JsonTokenType tokentype)
21212121
Datum
21222122
jsonb_array_elements(PG_FUNCTION_ARGS)
21232123
{
2124-
return elements_worker_jsonb(fcinfo, "jsonb_array_elements", false);
2124+
return elements_worker_jsonb(fcinfo, JSONB"_array_elements", false);
21252125
}
21262126

21272127
Datum
21282128
jsonb_array_elements_text(PG_FUNCTION_ARGS)
21292129
{
2130-
return elements_worker_jsonb(fcinfo, "jsonb_array_elements_text", true);
2130+
return elements_worker_jsonb(fcinfo, JSONB"_array_elements_text", true);
21312131
}
21322132

21332133
static Datum
@@ -2181,7 +2181,7 @@ elements_worker_jsonb(FunctionCallInfo fcinfo, const char *funcname,
21812181
MemoryContextSwitchTo(old_cxt);
21822182

21832183
tmp_cxt = AllocSetContextCreate(CurrentMemoryContext,
2184-
"jsonb_array_elements temporary cxt",
2184+
JSONB"_array_elements temporary cxt",
21852185
ALLOCSET_DEFAULT_SIZES);
21862186

21872187
it = JsonbIteratorInit(JsonbRoot(jb));
@@ -2425,14 +2425,14 @@ elements_scalar(void *state, char *token, JsonTokenType tokentype)
24252425
Datum
24262426
jsonb_populate_record(PG_FUNCTION_ARGS)
24272427
{
2428-
return populate_record_worker(fcinfo, "jsonb_populate_record",
2428+
return populate_record_worker(fcinfo, JSONB"_populate_record",
24292429
JSONXOID == JSONOID, true);
24302430
}
24312431

24322432
Datum
24332433
jsonb_to_record(PG_FUNCTION_ARGS)
24342434
{
2435-
return populate_record_worker(fcinfo, "jsonb_to_record",
2435+
return populate_record_worker(fcinfo, JSONB"_to_record",
24362436
JSONXOID == JSONOID, false);
24372437
}
24382438

@@ -3673,14 +3673,14 @@ hash_scalar(void *state, char *token, JsonTokenType tokentype)
36733673
Datum
36743674
jsonb_populate_recordset(PG_FUNCTION_ARGS)
36753675
{
3676-
return populate_recordset_worker(fcinfo, "jsonb_populate_recordset",
3676+
return populate_recordset_worker(fcinfo, JSONB"_populate_recordset",
36773677
false, true);
36783678
}
36793679

36803680
Datum
36813681
jsonb_to_recordset(PG_FUNCTION_ARGS)
36823682
{
3683-
return populate_recordset_worker(fcinfo, "jsonb_to_recordset",
3683+
return populate_recordset_worker(fcinfo, JSONB"_to_recordset",
36843684
false, false);
36853685
}
36863686

@@ -4883,7 +4883,7 @@ IteratorConcat(JsonbIterator **it1, JsonbIterator **it2,
48834883
*/
48844884
ereport(ERROR,
48854885
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4886-
errmsg("invalid concatenation of jsonb objects")));
4886+
errmsg("invalid concatenation of "JSONB" objects")));
48874887
}
48884888

48894889
return res;
@@ -4986,7 +4986,7 @@ setPathObject(JsonbIterator **it, Datum *path_elems, bool *path_nulls,
49864986
ereport(ERROR,
49874987
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
49884988
errmsg("cannot replace existing key"),
4989-
errhint("Try using the function jsonb_set "
4989+
errhint("Try using the function "JSONB"_set "
49904990
"to replace key value.")));
49914991

49924992
r = JsonbIteratorNext(it, &v, true); /* skip value */

src/include/utils/jsonb.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
#include "utils/array.h"
1717
#include "utils/numeric.h"
1818

19+
#ifndef JSONB
20+
#define JSONB "jsonb"
21+
#endif
22+
1923
/* Tokens used when sequentially processing a jsonb value */
2024
typedef enum
2125
{

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