#include "utils/jsonb.h"
static inline Datum deserialize_json_text(char *json, int len);
-static void jsonb_put_escaped_value(StringInfo out, JsonbValue *v);
+static void jsonb_put_escaped_value(StringInfo out, JsonbValue * v);
static void jsonb_in_scalar(void *state, char *token, JsonTokenType tokentype);
typedef struct JsonbInState
}
static void
-jsonb_put_escaped_value(StringInfo out, JsonbValue *v)
+jsonb_put_escaped_value(StringInfo out, JsonbValue * v)
{
switch (v->type)
{
jsonb_recv(PG_FUNCTION_ARGS)
{
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
- int version = pq_getmsgint(buf, 1);
- char *str;
- int nbytes;
+ int version = pq_getmsgint(buf, 1);
+ char *str;
+ int nbytes;
if (version == 1)
str = pq_getmsgtext(buf, buf->len - buf->cursor, &nbytes);
else
- elog(ERROR,"Unsupported jsonb version number %d",version);
+ elog(ERROR, "Unsupported jsonb version number %d", version);
return deserialize_json_text(str, nbytes);
}
v.type = jbvNumeric;
v.numeric = DatumGetNumeric(DirectFunctionCall3(numeric_in, CStringGetDatum(token), 0, -1));
- v.size += VARSIZE_ANY(v.numeric) + sizeof(JEntry) /* alignment */ ;
+ v.size += VARSIZE_ANY(v.numeric) +sizeof(JEntry) /* alignment */ ;
break;
case JSON_TOKEN_TRUE:
v.type = jbvBool;
/*
* JsonbToCString
- * Converts jsonb value in C-string. If out argument is not null
+ * Converts jsonb value in C-string. If out argument is not null
* then resulting C-string is placed in it. Return pointer to string.
* A typical case for passing the StringInfo in rather than NULL is where
* the caller wants access to the len attribute without having to call
int type = 0;
JsonbValue v;
int level = 0;
- bool redo_switch = false;
+ bool redo_switch = false;
if (out == NULL)
out = makeStringInfo();
else
{
Assert(type == WJB_BEGIN_OBJECT || type == WJB_BEGIN_ARRAY);
+
/*
* We need to rerun the current switch() since we need to
* output the object which we just got from the iterator
Jsonb *jb = PG_GETARG_JSONB(0);
StringInfoData buf;
StringInfo jtext = makeStringInfo();
- int version = 1;
+ int version = 1;
(void) JsonbToCString(jtext, (JB_ISEMPTY(jb)) ? NULL : VARDATA(jb),
VARSIZE(jb));
}
static text *
-makeitemFromValue(JsonbValue *v, char flag)
+makeitemFromValue(JsonbValue * v, char flag)
{
- text *item;
- char *cstr;
+ text *item;
+ char *cstr;
- switch(v->type)
+ switch (v->type)
{
case jbvNull:
item = makeitem(NULL, 0, NULLFLAG);
item = makeitem((v->boolean) ? " t" : " f", 2, flag);
break;
case jbvNumeric:
+
/*
- * It's needed to get some text representaion of numeric independed
- * from locale setting and preciosion. We use hashed value - it's
- * safe because recheck flag will be set anyway.
+ * It's needed to get some text representaion of numeric
+ * independed from locale setting and preciosion. We use hashed
+ * value - it's safe because recheck flag will be set anyway.
*/
- cstr = palloc(8 /* hex numbers */ + 1 /* \0 */);
- snprintf(cstr, 9, "%08x", DatumGetInt32(DirectFunctionCall1(hash_numeric,
- NumericGetDatum(v->numeric))));
+ cstr = palloc(8 /* hex numbers */ + 1 /* \0 */ );
+ snprintf(cstr, 9, "%08x", DatumGetInt32(DirectFunctionCall1(hash_numeric,
+ NumericGetDatum(v->numeric))));
item = makeitem(cstr, 8, flag);
pfree(cstr);
break;
Datum
gin_extract_jsonb(PG_FUNCTION_ARGS)
{
- Jsonb *jb = (Jsonb*) PG_GETARG_JSONB(0);
- int32 *nentries = (int32 *) PG_GETARG_POINTER(1);
- Datum *entries = NULL;
- int total = 2 * JB_ROOT_COUNT(jb);
- int i = 0, r;
- JsonbIterator *it;
- JsonbValue v;
+ Jsonb *jb = (Jsonb *) PG_GETARG_JSONB(0);
+ int32 *nentries = (int32 *) PG_GETARG_POINTER(1);
+ Datum *entries = NULL;
+ int total = 2 * JB_ROOT_COUNT(jb);
+ int i = 0,
+ r;
+ JsonbIterator *it;
+ JsonbValue v;
if (total == 0)
{
it = JsonbIteratorInit(VARDATA(jb));
- while((r = JsonbIteratorGet(&it, &v, false)) != 0)
+ while ((r = JsonbIteratorGet(&it, &v, false)) != 0)
{
if (i >= total)
{
entries = (Datum *) repalloc(entries, sizeof(Datum) * total);
}
- switch(r)
+ switch (r)
{
case WJB_KEY:
entries[i++] = PointerGetDatum(makeitemFromValue(&v, KEYFLAG));
typedef struct PathHashStack
{
- pg_crc32 hash_state;
+ pg_crc32 hash_state;
struct PathHashStack *next;
-} PathHashStack;
+} PathHashStack;
#define PATH_SEPARATOR ("\0")
static void
-hash_value(JsonbValue *v, PathHashStack *stack)
+hash_value(JsonbValue * v, PathHashStack * stack)
{
- switch(v->type)
+ switch (v->type)
{
case jbvNull:
- COMP_CRC32(stack->hash_state, "NULL", 5 /* include trailing \0 */);
+ COMP_CRC32(stack->hash_state, "NULL", 5 /* include trailing \0 */ );
break;
case jbvBool:
- COMP_CRC32(stack->hash_state, (v->boolean) ? " t" : " f", 2 /* include trailing \0 */);
+ COMP_CRC32(stack->hash_state, (v->boolean) ? " t" : " f", 2 /* include trailing \0 */ );
break;
case jbvNumeric:
stack->hash_state ^= DatumGetInt32(DirectFunctionCall1(hash_numeric,
- NumericGetDatum(v->numeric)));
+ NumericGetDatum(v->numeric)));
break;
case jbvString:
COMP_CRC32(stack->hash_state, v->string.val, v->string.len);
Datum
gin_extract_jsonb_hash(PG_FUNCTION_ARGS)
{
- Jsonb *jb = PG_GETARG_JSONB(0);
- int32 *nentries = (int32 *) PG_GETARG_POINTER(1);
- Datum *entries = NULL;
- int total = 2 * JB_ROOT_COUNT(jb);
- int i = 0, r;
- JsonbIterator *it;
- JsonbValue v;
- PathHashStack tail;
- PathHashStack *stack, *tmp;
- pg_crc32 path_crc32;
+ Jsonb *jb = PG_GETARG_JSONB(0);
+ int32 *nentries = (int32 *) PG_GETARG_POINTER(1);
+ Datum *entries = NULL;
+ int total = 2 * JB_ROOT_COUNT(jb);
+ int i = 0,
+ r;
+ JsonbIterator *it;
+ JsonbValue v;
+ PathHashStack tail;
+ PathHashStack *stack,
+ *tmp;
+ pg_crc32 path_crc32;
if (total == 0)
{
/*
* Calculate hashes of all key_1.key_2. ... .key_n.value paths as entries.
* Order of array elements doesn't matter so array keys are empty in path.
- * For faster calculation of hashes use stack for precalculated hashes
- * of prefixes.
+ * For faster calculation of hashes use stack for precalculated hashes of
+ * prefixes.
*/
- while((r = JsonbIteratorGet(&it, &v, false)) != 0)
+ while ((r = JsonbIteratorGet(&it, &v, false)) != 0)
{
if (i >= total)
{
entries = (Datum *) repalloc(entries, sizeof(Datum) * total);
}
- switch(r)
+ switch (r)
{
case WJB_BEGIN_ARRAY:
tmp = stack;
- stack = (PathHashStack *)palloc(sizeof(PathHashStack));
+ stack = (PathHashStack *) palloc(sizeof(PathHashStack));
stack->next = tmp;
stack->hash_state = tmp->hash_state;
COMP_CRC32(stack->hash_state, PATH_SEPARATOR, 1);
case WJB_BEGIN_OBJECT:
/* Preserve stack item for key */
tmp = stack;
- stack = (PathHashStack *)palloc(sizeof(PathHashStack));
+ stack = (PathHashStack *) palloc(sizeof(PathHashStack));
stack->next = tmp;
break;
case WJB_KEY:
#define WISH_F(a,b,c) (double)( -(double)(((a)-(b))*((a)-(b))*((a)-(b)))*(c) )
static int
-crc32_JsonbValue(JsonbValue *v, uint32 r)
+crc32_JsonbValue(JsonbValue * v, uint32 r)
{
- int crc;
- char flag = '\0';
+ int crc;
+ char flag = '\0';
INIT_CRC32(crc);
- switch(r)
+ switch (r)
{
case WJB_KEY:
flag = KEYFLAG;
COMP_CRC32(crc, &flag, 1);
- switch(v->type)
+ switch (v->type)
{
case jbvString:
COMP_CRC32(crc, v->string.val, v->string.len);
break;
case jbvNumeric:
crc = DatumGetInt32(DirectFunctionCall1(hash_numeric,
- NumericGetDatum(v->numeric)));
+ NumericGetDatum(v->numeric)));
break;
default:
elog(ERROR, "wrong jsonb scalar type");
static int
crc32_Key(char *buf, int sz)
{
- int crc;
- char flag = KEYFLAG;
+ int crc;
+ char flag = KEYFLAG;
INIT_CRC32(crc);
qe = fcinfo->flinfo->fn_extra;
if (qe == NULL)
{
- Jsonb *query = PG_GETARG_JSONB(1);
+ Jsonb *query = PG_GETARG_JSONB(1);
qe = MemoryContextAlloc(fcinfo->flinfo->fn_mcxt, sizeof(BITVEC));
memset(qe, 0, sizeof(BITVEC));
if (!JB_ISEMPTY(query))
{
- int r;
- JsonbIterator *it = JsonbIteratorInit(VARDATA(query));
- JsonbValue v;
+ int r;
+ JsonbIterator *it = JsonbIteratorInit(VARDATA(query));
+ JsonbValue v;
- while((r = JsonbIteratorGet(&it, &v, false)) != 0)
+ while ((r = JsonbIteratorGet(&it, &v, false)) != 0)
{
if ((r == WJB_ELEM || r == WJB_KEY || r == WJB_VALUE) && v.type != jbvNull)
{
- int crc = crc32_JsonbValue(&v, r);
+ int crc = crc32_JsonbValue(&v, r);
HASH(qe, crc);
}
}
else if (strategy == JsonbExistsStrategyNumber)
{
- int *qval;
+ int *qval;
qval = fcinfo->flinfo->fn_extra;
if (qval == NULL)
else if (strategy == JsonbExistsAllStrategyNumber ||
strategy == JsonbExistsAnyStrategyNumber)
{
- BITVECP arrentry;
- int i;
+ BITVECP arrentry;
+ int i;
arrentry = fcinfo->flinfo->fn_extra;
if (arrentry == NULL)
}
}
}
- else /* JsonbExistsAnyStrategyNumber */
+ else /* JsonbExistsAnyStrategyNumber */
{
res = false;
if (entry->leafkey)
{
- GISTTYPE *res = (GISTTYPE *) palloc0(CALCGTSIZE(0));
- Jsonb *val = (Jsonb*) PG_DETOAST_DATUM(entry->key);
+ GISTTYPE *res = (GISTTYPE *) palloc0(CALCGTSIZE(0));
+ Jsonb *val = (Jsonb *) PG_DETOAST_DATUM(entry->key);
SET_VARSIZE(res, CALCGTSIZE(0));
if (!JB_ISEMPTY(val))
{
- JsonbIterator *it = JsonbIteratorInit(VARDATA(val));
- JsonbValue v;
- int r;
+ JsonbIterator *it = JsonbIteratorInit(VARDATA(val));
+ JsonbValue v;
+ int r;
- while((r = JsonbIteratorGet(&it, &v, false)) != 0)
+ while ((r = JsonbIteratorGet(&it, &v, false)) != 0)
{
if ((r == WJB_ELEM || r == WJB_KEY || r == WJB_VALUE) &&
v.type != jbvNull)
{
- int h = crc32_JsonbValue(&v, r);
+ int h = crc32_JsonbValue(&v, r);
HASH(GETSIGN(res), h);
}
#include "utils/memutils.h"
#include "utils/pg_crc.h"
-static JsonbValue*
+static JsonbValue *
arrayToJsonbSortedArray(ArrayType *a)
{
- Datum *key_datums;
- bool *key_nulls;
- int key_count;
- JsonbValue *v;
- int i,
- j;
- bool hasNonUniq = false;
+ Datum *key_datums;
+ bool *key_nulls;
+ int key_count;
+ JsonbValue *v;
+ int i,
+ j;
+ bool hasNonUniq = false;
deconstruct_array(a,
TEXTOID, -1, false, 'i',
if (v->array.nelems > 1)
qsort_arg(v->array.elems, v->array.nelems, sizeof(*v->array.elems),
- compareJsonbStringValue /* compareJsonbStringValue */, &hasNonUniq);
+ compareJsonbStringValue /* compareJsonbStringValue */ , &hasNonUniq);
if (hasNonUniq)
{
- JsonbValue *ptr = v->array.elems + 1,
- *res = v->array.elems;
+ JsonbValue *ptr = v->array.elems + 1,
+ *res = v->array.elems;
while (ptr - v->array.elems < v->array.nelems)
{
if (!(ptr->string.len == res->string.len &&
- memcmp(ptr->string.val, res->string.val, ptr->string.len) == 0))
+ memcmp(ptr->string.val, res->string.val, ptr->string.len) == 0))
{
res++;
*res = *ptr;
Datum
jsonb_exists(PG_FUNCTION_ARGS)
{
- Jsonb *jb = PG_GETARG_JSONB(0);
- text *key = PG_GETARG_TEXT_PP(1);
- JsonbValue *v = NULL;
+ Jsonb *jb = PG_GETARG_JSONB(0);
+ text *key = PG_GETARG_TEXT_PP(1);
+ JsonbValue *v = NULL;
if (!JB_ISEMPTY(jb))
v = findUncompressedJsonbValue(VARDATA(jb),
- JB_FLAG_OBJECT | JB_FLAG_ARRAY,
- NULL,
- VARDATA_ANY(key),
- VARSIZE_ANY_EXHDR(key));
+ JB_FLAG_OBJECT | JB_FLAG_ARRAY,
+ NULL,
+ VARDATA_ANY(key),
+ VARSIZE_ANY_EXHDR(key));
PG_RETURN_BOOL(v != NULL);
}
Datum
jsonb_exists_any(PG_FUNCTION_ARGS)
{
- Jsonb *jb = PG_GETARG_JSONB(0);
- ArrayType *keys = PG_GETARG_ARRAYTYPE_P(1);
- JsonbValue *v = arrayToJsonbSortedArray(keys);
- int i;
- uint32 *plowbound = NULL, lowbound = 0;
- bool res = false;
+ Jsonb *jb = PG_GETARG_JSONB(0);
+ ArrayType *keys = PG_GETARG_ARRAYTYPE_P(1);
+ JsonbValue *v = arrayToJsonbSortedArray(keys);
+ int i;
+ uint32 *plowbound = NULL,
+ lowbound = 0;
+ bool res = false;
if (JB_ISEMPTY(jb) || v == NULL || v->object.npairs == 0)
PG_RETURN_BOOL(false);
if (JB_ROOT_IS_OBJECT(jb))
plowbound = &lowbound;
+
/*
* we exploit the fact that the pairs list is already sorted into strictly
- * increasing order to narrow the findUncompressedJsonbValue search; each search can
- * start one entry past the previous "found" entry, or at the lower bound
- * of the last search.
+ * increasing order to narrow the findUncompressedJsonbValue search; each
+ * search can start one entry past the previous "found" entry, or at the
+ * lower bound of the last search.
*/
for (i = 0; i < v->array.nelems; i++)
{
if (findUncompressedJsonbValueByValue(VARDATA(jb), JB_FLAG_OBJECT | JB_FLAG_ARRAY, plowbound,
- v->array.elems + i) != NULL)
+ v->array.elems + i) != NULL)
{
res = true;
break;
Datum
jsonb_exists_all(PG_FUNCTION_ARGS)
{
- Jsonb *js = PG_GETARG_JSONB(0);
- ArrayType *keys = PG_GETARG_ARRAYTYPE_P(1);
- JsonbValue *v = arrayToJsonbSortedArray(keys);
- uint32 *plowbound = NULL;
- uint32 lowbound = 0;
- bool res = true;
- int i;
+ Jsonb *js = PG_GETARG_JSONB(0);
+ ArrayType *keys = PG_GETARG_ARRAYTYPE_P(1);
+ JsonbValue *v = arrayToJsonbSortedArray(keys);
+ uint32 *plowbound = NULL;
+ uint32 lowbound = 0;
+ bool res = true;
+ int i;
if (JB_ISEMPTY(js) || v == NULL || v->array.nelems == 0)
{
if (v == NULL || v->array.nelems == 0)
- PG_RETURN_BOOL(true); /* compatibility */
+ PG_RETURN_BOOL(true); /* compatibility */
else
PG_RETURN_BOOL(false);
}
}
static bool
-deepContains(JsonbIterator **it1, JsonbIterator **it2)
+deepContains(JsonbIterator ** it1, JsonbIterator ** it2)
{
- uint32 r1, r2;
- JsonbValue v1, v2;
- bool res = true;
+ uint32 r1,
+ r2;
+ JsonbValue v1,
+ v2;
+ bool res = true;
r1 = JsonbIteratorGet(it1, &v1, false);
r2 = JsonbIteratorGet(it2, &v2, false);
else if (r1 == WJB_BEGIN_OBJECT)
{
uint32 lowbound = 0;
- JsonbValue *v;
+ JsonbValue *v;
- for(;;) {
+ for (;;)
+ {
r2 = JsonbIteratorGet(it2, &v2, false);
if (r2 == WJB_END_OBJECT)
break;
Assert(r2 == WJB_KEY);
v = findUncompressedJsonbValueByValue((*it1)->buffer,
- JB_FLAG_OBJECT,
- &lowbound, &v2);
+ JB_FLAG_OBJECT,
+ &lowbound, &v2);
if (v == NULL)
{
}
else
{
- JsonbIterator *it1a, *it2a;
+ JsonbIterator *it1a,
+ *it2a;
Assert(v2.type == jbvBinary);
Assert(v->type == jbvBinary);
}
else if (r1 == WJB_BEGIN_ARRAY)
{
- JsonbValue *v;
- JsonbValue *av = NULL;
- uint32 nelems = v1.array.nelems;
+ JsonbValue *v;
+ JsonbValue *av = NULL;
+ uint32 nelems = v1.array.nelems;
- for(;;) {
+ for (;;)
+ {
r2 = JsonbIteratorGet(it2, &v2, true);
if (r2 == WJB_END_ARRAY)
break;
v2.type == jbvBool || v2.type == jbvNumeric)
{
v = findUncompressedJsonbValueByValue((*it1)->buffer,
- JB_FLAG_ARRAY, NULL,
- &v2);
+ JB_FLAG_ARRAY, NULL,
+ &v2);
if (v == NULL)
{
res = false;
}
else
{
- uint32 i;
+ uint32 i;
if (av == NULL)
{
- uint32 j = 0;
+ uint32 j = 0;
av = palloc(sizeof(*av) * nelems);
- for(i=0; i<nelems; i++)
+ for (i = 0; i < nelems; i++)
{
r2 = JsonbIteratorGet(it1, &v1, true);
Assert(r2 == WJB_ELEM);
}
res = false;
- for(i = 0; res == false && i<nelems; i++)
+ for (i = 0; res == false && i < nelems; i++)
{
- JsonbIterator *it1a, *it2a;
+ JsonbIterator *it1a,
+ *it2a;
it1a = JsonbIteratorInit(av[i].binary.data);
it2a = JsonbIteratorInit(v2.binary.data);
Datum
jsonb_contains(PG_FUNCTION_ARGS)
{
- Jsonb *val = PG_GETARG_JSONB(0);
- Jsonb *tmpl = PG_GETARG_JSONB(1);
+ Jsonb *val = PG_GETARG_JSONB(0);
+ Jsonb *tmpl = PG_GETARG_JSONB(1);
- bool res = true;
- JsonbIterator *it1, *it2;
+ bool res = true;
+ JsonbIterator *it1,
+ *it2;
if (JB_ROOT_COUNT(val) < JB_ROOT_COUNT(tmpl) ||
JB_ROOT_IS_OBJECT(val) != JB_ROOT_IS_OBJECT(tmpl))
Datum
jsonb_cmp(PG_FUNCTION_ARGS)
{
- Jsonb *jb1 = PG_GETARG_JSONB(0);
- Jsonb *jb2 = PG_GETARG_JSONB(1);
+ Jsonb *jb1 = PG_GETARG_JSONB(0);
+ Jsonb *jb2 = PG_GETARG_JSONB(1);
- int res;
+ int res;
if (JB_ISEMPTY(jb1) || JB_ISEMPTY(jb2))
{
Datum
jsonb_hash(PG_FUNCTION_ARGS)
{
- Jsonb *jb = PG_GETARG_JSONB(0);
- JsonbIterator *it;
- int32 r;
- JsonbValue v;
- int crc;
+ Jsonb *jb = PG_GETARG_JSONB(0);
+ JsonbIterator *it;
+ int32 r;
+ JsonbValue v;
+ int crc;
if (JB_ROOT_COUNT(jb) == 0)
PG_RETURN_INT32(0x1EEE);
it = JsonbIteratorInit(VARDATA(jb));
INIT_CRC32(crc);
- while((r = JsonbIteratorGet(&it, &v, false)) != 0)
+ while ((r = JsonbIteratorGet(&it, &v, false)) != 0)
{
- switch(r)
+ switch (r)
{
case WJB_BEGIN_ARRAY:
COMP_CRC32(crc, "ab", 3);
COMP_CRC32(crc, "k", 2);
case WJB_VALUE:
case WJB_ELEM:
- switch(v.type)
+ switch (v.type)
{
case jbvString:
COMP_CRC32(crc, v.string.val, v.string.len);
break;
case jbvNumeric:
crc ^= DatumGetInt32(DirectFunctionCall1(hash_numeric,
- NumericGetDatum(v.numeric)));
+ NumericGetDatum(v.numeric)));
break;
default:
elog(ERROR, "unexpected state of jsonb iterator");
typedef void (*walk_jsonb_cb) (void * /* arg */ , JsonbValue * /* value */ ,
uint32 /* flags */ , uint32 /* level */ );
-static void walkUncompressedJsonb(JsonbValue *v, walk_jsonb_cb cb, void *cb_arg);
-static uint32 compressJsonb(JsonbValue *v, char *buffer);
-static void uniqueJsonbValue(JsonbValue *v);
+static void walkUncompressedJsonb(JsonbValue * v, walk_jsonb_cb cb, void *cb_arg);
+static uint32 compressJsonb(JsonbValue * v, char *buffer);
+static void uniqueJsonbValue(JsonbValue * v);
/*
* Turn a JsonbValue into a Jsonb
*/
Jsonb *
-JsonbValueToJsonb(JsonbValue *v)
+JsonbValueToJsonb(JsonbValue * v)
{
Jsonb *out;
* some constant order of JsonbValue
*/
int
-compareJsonbValue(JsonbValue *a, JsonbValue *b)
+compareJsonbValue(JsonbValue * a, JsonbValue * b)
{
-
check_stack_depth();
if (a->type == b->type)
for (i = 0; i < a->object.npairs; i++)
{
if ((r = compareJsonbStringValue(&a->object.pairs[i].key,
- &b->object.pairs[i].key,
+ &b->object.pairs[i].key,
NULL)) != 0)
return r;
if ((r = compareJsonbValue(&a->object.pairs[i].value,
- &b->object.pairs[i].value)) != 0)
+ &b->object.pairs[i].value)) != 0)
return r;
}
*/
JsonbValue *
findUncompressedJsonbValueByValue(char *buffer, uint32 flags,
- uint32 *lowbound, JsonbValue *key)
+ uint32 *lowbound, JsonbValue * key)
{
- uint32 header = *(uint32 *) buffer;
- static JsonbValue r;
+ uint32 header = *(uint32 *) buffer;
+ static JsonbValue r;
Assert((header & (JB_FLAG_ARRAY | JB_FLAG_OBJECT)) !=
(JB_FLAG_ARRAY | JB_FLAG_OBJECT));
* Walk on tree representation of jsonb *
****************************************************************************/
static void
-walkUncompressedJsonbDo(JsonbValue *v, walk_jsonb_cb cb, void *cb_arg, uint32 level)
+walkUncompressedJsonbDo(JsonbValue * v, walk_jsonb_cb cb, void *cb_arg, uint32 level)
{
int i;
}
static void
-walkUncompressedJsonb(JsonbValue *v, walk_jsonb_cb cb, void *cb_arg)
+walkUncompressedJsonb(JsonbValue * v, walk_jsonb_cb cb, void *cb_arg)
{
if (v)
walkUncompressedJsonbDo(v, cb, cb_arg, 0);
* Iteration over binary jsonb *
****************************************************************************/
static void
-parseBuffer(JsonbIterator *it, char *buffer)
+parseBuffer(JsonbIterator * it, char *buffer)
{
uint32 header = *(uint32 *) buffer;
}
static bool
-formAnswer(JsonbIterator **it, JsonbValue *v, JEntry * e, bool skipNested)
+formAnswer(JsonbIterator ** it, JsonbValue * v, JEntry * e, bool skipNested)
{
if (JBE_ISSTRING(*e))
{
}
static JsonbIterator *
-up(JsonbIterator *it)
+up(JsonbIterator * it)
{
JsonbIterator *v = it->next;
}
int
-JsonbIteratorGet(JsonbIterator **it, JsonbValue *v, bool skipNested)
+JsonbIteratorGet(JsonbIterator ** it, JsonbValue * v, bool skipNested)
{
int res;
#define prevLevelState state->pptr
static void
-putJEntryString(CompressState * state, JsonbValue *value, uint32 level, uint32 i)
+putJEntryString(CompressState * state, JsonbValue * value, uint32 level, uint32 i)
{
curLevelState = state->levelstate + level;
}
static void
-compressCallback(void *arg, JsonbValue *value, uint32 flags, uint32 level)
+compressCallback(void *arg, JsonbValue * value, uint32 flags, uint32 level)
{
CompressState *state = arg;
* puts JsonbValue tree into preallocated buffer
*/
static uint32
-compressJsonb(JsonbValue *v, char *buffer)
+compressJsonb(JsonbValue * v, char *buffer)
{
uint32 l = 0;
CompressState state;
}
static void
-appendArray(ToJsonbState * state, JsonbValue *v)
+appendArray(ToJsonbState * state, JsonbValue * v)
{
JsonbValue *a = &state->v;
}
static void
-appendKey(ToJsonbState * state, JsonbValue *v)
+appendKey(ToJsonbState * state, JsonbValue * v)
{
JsonbValue *h = &state->v;
{
state->size *= 2;
h->object.pairs = repalloc(h->object.pairs,
- sizeof(*h->object.pairs) * state->size);
+ sizeof(*h->object.pairs) * state->size);
}
h->object.pairs[h->object.npairs].key = *v;
}
static void
-appendValue(ToJsonbState * state, JsonbValue *v)
+appendValue(ToJsonbState * state, JsonbValue * v)
{
JsonbValue *h = &state->v;
* Sort and unique pairs in JsonbValue (associative data structure)
*/
static void
-uniqueJsonbValue(JsonbValue *v)
+uniqueJsonbValue(JsonbValue * v)
{
bool hasNonUniq = false;
* Initial state of ToJsonbState is NULL.
*/
JsonbValue *
-pushJsonbValue(ToJsonbState **state, int r /* WJB_* */, JsonbValue *v)
+pushJsonbValue(ToJsonbState ** state, int r /* WJB_* */ , JsonbValue * v)
{
- JsonbValue *h = NULL;
+ JsonbValue *h = NULL;
switch (r)
{
(*state)->size = (v && v->type == jbvObject && v->object.npairs > 0) ?
v->object.npairs : 4;
(*state)->v.object.pairs = palloc(sizeof(*(*state)->v.object.pairs) *
- (*state)->size);
+ (*state)->size);
break;
case WJB_ELEM:
Assert(v->type == jbvNull || v->type == jbvString ||
} PopulateRecordsetState;
/* turn a jsonb object into a record */
-static inline void make_row_from_rec_and_jsonb(Jsonb *element, PopulateRecordsetState *state);
+static inline void make_row_from_rec_and_jsonb(Jsonb * element, PopulateRecordsetState *state);
/*
* SQL function json_object-keys
/* use the tmp context so we can clean up after each tuple is done */
old_cxt = MemoryContextSwitchTo(tmp_cxt);
- if (! as_text)
+ if (!as_text)
{
- Jsonb *val = JsonbValueToJsonb(&v);
+ Jsonb *val = JsonbValueToJsonb(&v);
+
values[0] = PointerGetDatum(val);
}
else
}
static inline void
-make_row_from_rec_and_jsonb(Jsonb *element, PopulateRecordsetState *state)
+make_row_from_rec_and_jsonb(Jsonb * element, PopulateRecordsetState *state)
{
Datum *values;
bool *nulls;
DESCR("get value from jsonb with path elements");
DATA(insert OID = 3206 ( "#>>" PGNSP PGUID b f f 3802 1009 25 0 0 jsonb_extract_path_text_op - - ));
DESCR("get value from jsonb as text with path elements");
-DATA(insert OID = 3240 ( "=" PGNSP PGUID b t t 3802 3802 16 3240 3241 jsonb_eq eqsel eqjoinsel ));
+DATA(insert OID = 3240 ( "=" PGNSP PGUID b t t 3802 3802 16 3240 3241 jsonb_eq eqsel eqjoinsel ));
DESCR("equal");
-DATA(insert OID = 3241 ( "<>" PGNSP PGUID b f f 3802 3802 16 3241 3240 jsonb_ne neqsel neqjoinsel ));
+DATA(insert OID = 3241 ( "<>" PGNSP PGUID b f f 3802 3802 16 3241 3240 jsonb_ne neqsel neqjoinsel ));
DESCR("not equal");
-DATA(insert OID = 3242 ( "<" PGNSP PGUID b f f 3802 3802 16 3243 3245 jsonb_lt scalarltsel scalarltjoinsel ));
+DATA(insert OID = 3242 ( "<" PGNSP PGUID b f f 3802 3802 16 3243 3245 jsonb_lt scalarltsel scalarltjoinsel ));
DESCR("less than");
-DATA(insert OID = 3243 ( ">" PGNSP PGUID b f f 3802 3802 16 3242 3244 jsonb_gt scalargtsel scalargtjoinsel ));
+DATA(insert OID = 3243 ( ">" PGNSP PGUID b f f 3802 3802 16 3242 3244 jsonb_gt scalargtsel scalargtjoinsel ));
DESCR("greater than");
-DATA(insert OID = 3244 ( "<=" PGNSP PGUID b f f 3802 3802 16 3245 3243 jsonb_le scalarltsel scalarltjoinsel ));
+DATA(insert OID = 3244 ( "<=" PGNSP PGUID b f f 3802 3802 16 3245 3243 jsonb_le scalarltsel scalarltjoinsel ));
DESCR("less than or equal to");
-DATA(insert OID = 3245 ( ">=" PGNSP PGUID b f f 3802 3802 16 3244 3242 jsonb_ge scalargtsel scalargtjoinsel ));
+DATA(insert OID = 3245 ( ">=" PGNSP PGUID b f f 3802 3802 16 3244 3242 jsonb_ge scalargtsel scalargtjoinsel ));
DESCR("greater than or equal to");
/* No commutator? */
DATA(insert OID = 3246 ( "@>" PGNSP PGUID b f f 3802 3802 16 0 0 jsonb_contains contsel contjoinsel ));
DESCR("build a json array from any inputs");
DATA(insert OID = 3199 ( json_build_array PGNSP PGUID 12 1 0 0 0 f f f f f f i 0 0 114 "" _null_ _null_ _null_ _null_ json_build_array_noargs _null_ _null_ _null_ ));
DESCR("build an empty json array");
-DATA(insert OID = 3200 ( json_build_object PGNSP PGUID 12 1 0 2276 0 f f f f f f i 1 0 114 "2276" "{2276}" "{v}" _null_ _null_ json_build_object _null_ _null_ _null_ ));
+DATA(insert OID = 3200 ( json_build_object PGNSP PGUID 12 1 0 2276 0 f f f f f f i 1 0 114 "2276" "{2276}" "{v}" _null_ _null_ json_build_object _null_ _null_ _null_ ));
DESCR("build a json object from pairwise key/value inputs");
-DATA(insert OID = 3201 ( json_build_object PGNSP PGUID 12 1 0 0 0 f f f f f f i 0 0 114 "" _null_ _null_ _null_ _null_ json_build_object_noargs _null_ _null_ _null_ ));
+DATA(insert OID = 3201 ( json_build_object PGNSP PGUID 12 1 0 0 0 f f f f f f i 0 0 114 "" _null_ _null_ _null_ _null_ json_build_object_noargs _null_ _null_ _null_ ));
DESCR("build an empty json object");
-DATA(insert OID = 3202 ( json_object PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 114 "1009" _null_ _null_ _null_ _null_ json_object _null_ _null_ _null_ ));
+DATA(insert OID = 3202 ( json_object PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 114 "1009" _null_ _null_ _null_ _null_ json_object _null_ _null_ _null_ ));
DESCR("map text arrayof key value pais to json object");
-DATA(insert OID = 3203 ( json_object PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 114 "1009 1009" _null_ _null_ _null_ _null_ json_object_two_arg _null_ _null_ _null_ ));
+DATA(insert OID = 3203 ( json_object PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 114 "1009 1009" _null_ _null_ _null_ _null_ json_object_two_arg _null_ _null_ _null_ ));
DESCR("map text arrayof key value pais to json object");
DATA(insert OID = 3176 ( to_json PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 114 "2283" _null_ _null_ _null_ _null_ to_json _null_ _null_ _null_ ));
DESCR("map input to json");
DESCR("get record fields from a json object");
DATA(insert OID = 3205 ( json_to_recordset PGNSP PGUID 12 1 100 0 0 f f f f f t s 2 0 2249 "114 16" _null_ _null_ _null_ _null_ json_to_recordset _null_ _null_ _null_ ));
DESCR("get set of records with fields from a json array of objects");
-DATA(insert OID = 3968 ( json_typeof PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "114" _null_ _null_ _null_ _null_ json_typeof _null_ _null_ _null_ ));
+DATA(insert OID = 3968 ( json_typeof PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "114" _null_ _null_ _null_ _null_ json_typeof _null_ _null_ _null_ ));
DESCR("get the type of a json value");
/* uuid */
DATA(insert OID = 3920 ( jsonb_extract_path_op PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 3802 "3802 1009" _null_ _null_ "{from_json,path_elems}" _null_ jsonb_extract_path _null_ _null_ _null_ ));
DATA(insert OID = 3921 ( jsonb_extract_path_text PGNSP PGUID 12 1 0 25 0 f f f f t f i 2 0 25 "3802 1009" "{3802,1009}" "{i,v}" "{from_json,path_elems}" _null_ jsonb_extract_path_text _null_ _null_ _null_ ));
DESCR("get value from jsonb as text with path elements");
-DATA(insert OID = 3218 ( jsonb_extract_path_text_op PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 25 "3802 1009" _null_ _null_ "{from_json,path_elems}" _null_ jsonb_extract_path_text _null_ _null_ _null_ ));
+DATA(insert OID = 3218 ( jsonb_extract_path_text_op PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 25 "3802 1009" _null_ _null_ "{from_json,path_elems}" _null_ jsonb_extract_path_text _null_ _null_ _null_ ));
DATA(insert OID = 3219 ( jsonb_array_elements PGNSP PGUID 12 1 100 0 0 f f f f t t i 1 0 3802 "3802" "{3802,3802}" "{i,o}" "{from_json,value}" _null_ jsonb_array_elements _null_ _null_ _null_ ));
DESCR("elements of a jsonb array");
-DATA(insert OID = 3465 ( jsonb_array_elements_text PGNSP PGUID 12 1 100 0 0 f f f f t t i 1 0 25 "3802" "{3802,25}" "{i,o}" "{from_json,value}" _null_ jsonb_array_elements_text _null_ _null_ _null_ ));
+DATA(insert OID = 3465 ( jsonb_array_elements_text PGNSP PGUID 12 1 100 0 0 f f f f t t i 1 0 25 "3802" "{3802,25}" "{i,o}" "{from_json,value}" _null_ jsonb_array_elements_text _null_ _null_ _null_ ));
DESCR("elements of jsonb array");
DATA(insert OID = 3207 ( jsonb_array_length PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "3802" _null_ _null_ _null_ _null_ jsonb_array_length _null_ _null_ _null_ ));
DESCR("length of jsonb array");
DESCR("key value pairs of a jsonb object");
DATA(insert OID = 3932 ( jsonb_each_text PGNSP PGUID 12 1 100 0 0 f f f f t t i 1 0 2249 "3802" "{3802,25,25}" "{i,o,o}" "{from_json,key,value}" _null_ jsonb_each_text _null_ _null_ _null_ ));
DESCR("key value pairs of a jsonb object");
-DATA(insert OID = 3209 ( jsonb_populate_record PGNSP PGUID 12 1 0 0 0 f f f f f f s 3 0 2283 "2283 3802 16" _null_ _null_ _null_ _null_ jsonb_populate_record _null_ _null_ _null_ ));
+DATA(insert OID = 3209 ( jsonb_populate_record PGNSP PGUID 12 1 0 0 0 f f f f f f s 3 0 2283 "2283 3802 16" _null_ _null_ _null_ _null_ jsonb_populate_record _null_ _null_ _null_ ));
DESCR("get record fields from a jsonb object");
-DATA(insert OID = 3475 ( jsonb_populate_recordset PGNSP PGUID 12 1 100 0 0 f f f f f t s 3 0 2283 "2283 3802 16" _null_ _null_ _null_ _null_ jsonb_populate_recordset _null_ _null_ _null_ ));
+DATA(insert OID = 3475 ( jsonb_populate_recordset PGNSP PGUID 12 1 100 0 0 f f f f f t s 3 0 2283 "2283 3802 16" _null_ _null_ _null_ _null_ jsonb_populate_recordset _null_ _null_ _null_ ));
DESCR("get set of records with fields from a jsonb array of objects");
-DATA(insert OID = 3210 ( jsonb_typeof PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "3802" _null_ _null_ _null_ _null_ jsonb_typeof _null_ _null_ _null_ ));
+DATA(insert OID = 3210 ( jsonb_typeof PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "3802" _null_ _null_ _null_ _null_ jsonb_typeof _null_ _null_ _null_ ));
DESCR("get the type of a jsonb value");
DATA(insert OID = 4038 ( jsonb_ne PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3802 3802" _null_ _null_ _null_ _null_ jsonb_ne _null_ _null_ _null_ ));
DATA(insert OID = 4039 ( jsonb_lt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3802 3802" _null_ _null_ _null_ _null_ jsonb_lt _null_ _null_ _null_ ));
DESCR("hash");
DATA(insert OID = 4046 ( jsonb_contains PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3802 3802" _null_ _null_ _null_ _null_ jsonb_contains _null_ _null_ _null_ ));
DESCR("implementation of @> operator");
-DATA(insert OID = 4047 ( jsonb_exists PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3802 25" _null_ _null_ _null_ _null_ jsonb_exists _null_ _null_ _null_ ));
+DATA(insert OID = 4047 ( jsonb_exists PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3802 25" _null_ _null_ _null_ _null_ jsonb_exists _null_ _null_ _null_ ));
DESCR("implementation of ? operator");
-DATA(insert OID = 4048 ( jsonb_exists_any PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3802 1009" _null_ _null_ _null_ _null_ jsonb_exists_any _null_ _null_ _null_ ));
+DATA(insert OID = 4048 ( jsonb_exists_any PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3802 1009" _null_ _null_ _null_ _null_ jsonb_exists_any _null_ _null_ _null_ ));
DESCR("implementation of ?| operator");
-DATA(insert OID = 4049 ( jsonb_exists_all PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3802 1009" _null_ _null_ _null_ _null_ jsonb_exists_all _null_ _null_ _null_ ));
+DATA(insert OID = 4049 ( jsonb_exists_all PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3802 1009" _null_ _null_ _null_ _null_ jsonb_exists_all _null_ _null_ _null_ ));
DESCR("implementation of ?& operator");
-DATA(insert OID = 4050 ( jsonb_contained PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3802 3802" _null_ _null_ _null_ _null_ jsonb_contained _null_ _null_ _null_ ));
+DATA(insert OID = 4050 ( jsonb_contained PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3802 3802" _null_ _null_ _null_ _null_ jsonb_contained _null_ _null_ _null_ ));
DESCR("implementation of <@ operator");
DATA(insert OID = 4052 ( gjsonb_consistent PGNSP PGUID 12 1 0 0 0 f f f f t f i 5 0 16 "2281 2281 23 26 2281" _null_ _null_ _null_ _null_ gjsonb_consistent _null_ _null_ _null_ ));
DESCR("GiST support");
-DATA(insert OID = 4053 ( gjsonb_union PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2281 "2281 2281" _null_ _null_ _null_ _null_ gjsonb_union _null_ _null_ _null_ ));
+DATA(insert OID = 4053 ( gjsonb_union PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2281 "2281 2281" _null_ _null_ _null_ _null_ gjsonb_union _null_ _null_ _null_ ));
DESCR("GiST support");
DATA(insert OID = 4054 ( gjsonb_compress PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ gjsonb_compress _null_ _null_ _null_ ));
DESCR("GiST support");
DESCR("GiST support");
DATA(insert OID = 4056 ( gjsonb_penalty PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ gjsonb_penalty _null_ _null_ _null_ ));
DESCR("GiST support");
-DATA(insert OID = 4057 ( gjsonb_picksplit PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2281 "2281 2281" _null_ _null_ _null_ _null_ gjsonb_picksplit _null_ _null_ _null_ ));
+DATA(insert OID = 4057 ( gjsonb_picksplit PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2281 "2281 2281" _null_ _null_ _null_ _null_ gjsonb_picksplit _null_ _null_ _null_ ));
DESCR("GiST support");
DATA(insert OID = 4058 ( gjsonb_same PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ gjsonb_same _null_ _null_ _null_ ));
DESCR("GiST support");
DESCR("GIN support");
DATA(insert OID = 3483 ( gin_extract_jsonb_query PGNSP PGUID 12 1 0 0 0 f f f f t f i 7 0 2281 "2277 2281 21 2281 2281 2281 2281" _null_ _null_ _null_ _null_ gin_extract_jsonb_query _null_ _null_ _null_ ));
DESCR("GIN support");
-DATA(insert OID = 3484 ( gin_consistent_jsonb PGNSP PGUID 12 1 0 0 0 f f f f t f i 8 0 16 "2281 21 2277 23 2281 2281 2281 2281" _null_ _null_ _null_ _null_ gin_consistent_jsonb _null_ _null_ _null_ ));
+DATA(insert OID = 3484 ( gin_consistent_jsonb PGNSP PGUID 12 1 0 0 0 f f f f t f i 8 0 16 "2281 21 2277 23 2281 2281 2281 2281" _null_ _null_ _null_ _null_ gin_consistent_jsonb _null_ _null_ _null_ ));
DESCR("GIN support");
DATA(insert OID = 3485 ( gin_extract_jsonb_hash PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ gin_extract_jsonb_hash _null_ _null_ _null_ ));
DESCR("GIN support");
-DATA(insert OID = 3486 ( gin_extract_jsonb_query_hash PGNSP PGUID 12 1 0 0 0 f f f f t f i 7 0 2281 "2277 2281 21 2281 2281 2281 2281" _null_ _null_ _null_ _null_ gin_extract_jsonb_query_hash _null_ _null_ _null_ ));
+DATA(insert OID = 3486 ( gin_extract_jsonb_query_hash PGNSP PGUID 12 1 0 0 0 f f f f t f i 7 0 2281 "2277 2281 21 2281 2281 2281 2281" _null_ _null_ _null_ _null_ gin_extract_jsonb_query_hash _null_ _null_ _null_ ));
DESCR("GIN support");
DATA(insert OID = 3487 ( gin_consistent_jsonb_hash PGNSP PGUID 12 1 0 0 0 f f f f t f i 8 0 16 "2281 21 2277 23 2281 2281 2281 2281" _null_ _null_ _null_ _null_ gin_consistent_jsonb_hash _null_ _null_ _null_ ));
DESCR("GIN support");