Jsonb *jb = PG_GETARG_JSONB(0);
char *out;
- out = JsonbToCString(NULL, (JB_ISEMPTY(jb)) ? NULL : VARDATA(jb), VARSIZE(jb));
+ out = JsonbToCString(NULL, VARDATA(jb), VARSIZE(jb));
PG_RETURN_CSTRING(out);
}
StringInfo jtext = makeStringInfo();
int version = 1;
- (void) JsonbToCString(jtext, (JB_ISEMPTY(jb)) ? NULL : VARDATA(jb),
- VARSIZE(jb));
+ (void) JsonbToCString(jtext, VARDATA(jb), VARSIZE(jb));
pq_begintypsend(&buf);
pq_sendint(&buf, version, 1);
kval.string.val = VARDATA_ANY(key);
kval.string.len = VARSIZE_ANY_EXHDR(key);
- if (!JB_ISEMPTY(jb))
- v = findJsonbValueFromSuperHeader(VARDATA(jb),
- JB_FOBJECT | JB_FARRAY,
- NULL,
- &kval);
+ v = findJsonbValueFromSuperHeader(VARDATA(jb),
+ JB_FOBJECT | JB_FARRAY,
+ NULL,
+ &kval);
PG_RETURN_BOOL(v != NULL);
}
uint32 *plowbound = NULL,
lowbound = 0;
- if (JB_ISEMPTY(jb) || v == NULL || v->object.nPairs == 0)
+ if (v == NULL || v->object.nPairs == 0)
PG_RETURN_BOOL(false);
if (JB_ROOT_IS_OBJECT(jb))
int res;
- if (JB_ISEMPTY(jb1) || JB_ISEMPTY(jb2))
- {
- if (JB_ISEMPTY(jb1))
- {
- if (JB_ISEMPTY(jb2))
- res = 0;
- else
- res = -1;
- }
- else
- {
- res = 1;
- }
- }
- else if (JB_ROOT_IS_SCALAR(jb1) && !JB_ROOT_IS_SCALAR(jb2))
- {
- res = -1;
- }
- else if (JB_ROOT_IS_SCALAR(jb2) && !JB_ROOT_IS_SCALAR(jb1))
- {
- res = 1;
- }
- else
- {
- res = compareJsonbSuperHeaderValue(VARDATA(jb1), VARDATA(jb2));
- }
+ res = compareJsonbSuperHeaderValue(VARDATA(jb1), VARDATA(jb2));
/*
* This is a btree support function; this is one of the few places where
res = (v1.boolean > v2.boolean) ? 1 : -1;
break;
case jbvArray:
+ /*
+ * This could be a "raw scalar" pseudo array. That's a
+ * special case here though, since we still want the
+ * general type-based comparisons to apply, and as far
+ * as we're concerned a pseudo array is just a scalar.
+ */
+ if (v1.array.scalar != v2.array.scalar)
+ res = (v1.array.scalar) ? -1 : 1;
if (v1.array.nElems != v2.array.nElems)
res = (v1.array.nElems > v2.array.nElems) ? 1 : -1;
break;
{
if (v1.type == v2.type)
{
- Assert(r1 != WJB_DONE && r2 != WJB_DONE);
-
/*
* Types were the same, and yet since iterator return codes
* differed, one must have finished before the other (and thus
* there must be a variation in the number of pairs/elements).
+ *
+ * This code is just defensive, since control won't reach here
+ * in practice as it'll already be apparent that an underlying
+ * container type has a different number of elements.
*/
if (v1.type == jbvArray)
{
{
Jsonb *jb = PG_GETARG_JSONB(0);
- json = cstring_to_text(JsonbToCString(NULL, (JB_ISEMPTY(jb)) ? NULL : VARDATA(jb), VARSIZE(jb)));
+ json = cstring_to_text(JsonbToCString(NULL, VARDATA(jb), VARSIZE(jb)));
}
if (array_contains_nulls(path))
if (as_text)
{
PG_RETURN_TEXT_P(cstring_to_text(JsonbToCString(NULL,
- (JB_ISEMPTY(res))?
- NULL : VARDATA(res),
+ VARDATA(res),
VARSIZE(res))));
}
else
jb = PG_GETARG_JSONB(have_record_arg ? 1 : 0);
/* same logic as for json */
- if (JB_ISEMPTY(jb) && rec)
+ if (!have_record_arg && rec)
PG_RETURN_POINTER(rec);
}
}
else
{
- if (!JB_ISEMPTY(jb))
{
char *key = NameStr(tupdesc->attrs[i]->attname);
continue;
}
- if (!JB_ISEMPTY(element))
{
char *key = NameStr(tupdesc->attrs[i]->attname);
#define JB_FARRAY 0x40000000
/* Get information on varlena Jsonb */
-#define JB_ISEMPTY(jbp_) (VARSIZE(jbp_) == 0)
-#define JB_ROOT_COUNT(jbp_) (JB_ISEMPTY(jbp_) ? \
- 0: ( *(uint32*) VARDATA(jbp_) & JB_CMASK))
-#define JB_ROOT_IS_SCALAR(jbp_) (JB_ISEMPTY(jbp_) ? \
- 0: ( *(uint32*) VARDATA(jbp_) & JB_FSCALAR))
-#define JB_ROOT_IS_OBJECT(jbp_) (JB_ISEMPTY(jbp_) ? \
- 0: ( *(uint32*) VARDATA(jbp_) & JB_FOBJECT))
-#define JB_ROOT_IS_ARRAY(jbp_) (JB_ISEMPTY(jbp_) ? \
- 0: ( *(uint32*) VARDATA(jbp_) & JB_FARRAY))
+#define JB_ROOT_COUNT(jbp_) ( *(uint32*) VARDATA(jbp_) & JB_CMASK)
+#define JB_ROOT_IS_SCALAR(jbp_) ( *(uint32*) VARDATA(jbp_) & JB_FSCALAR)
+#define JB_ROOT_IS_OBJECT(jbp_) ( *(uint32*) VARDATA(jbp_) & JB_FOBJECT)
+#define JB_ROOT_IS_ARRAY(jbp_) ( *(uint32*) VARDATA(jbp_) & JB_FARRAY)
/* Jentry macros */
#define JENTRY_POSMASK 0x0FFFFFFF