Commit f33a71a7 authored by Tom Lane's avatar Tom Lane

De-anonymize the union in JsonbValue.

Needed for strict C89 compliance.
parent 682c5bbe
...@@ -1397,9 +1397,9 @@ hstore_to_jsonb(PG_FUNCTION_ARGS) ...@@ -1397,9 +1397,9 @@ hstore_to_jsonb(PG_FUNCTION_ARGS)
key.estSize = sizeof(JEntry); key.estSize = sizeof(JEntry);
key.type = jbvString; key.type = jbvString;
key.string.len = HS_KEYLEN(entries, i); key.val.string.len = HS_KEYLEN(entries, i);
key.string.val = pnstrdup(HS_KEY(entries, base, i), key.string.len); key.val.string.val = pnstrdup(HS_KEY(entries, base, i), key.val.string.len);
key.estSize += key.string.len; key.estSize += key.val.string.len;
res = pushJsonbValue(&state, WJB_KEY, &key); res = pushJsonbValue(&state, WJB_KEY, &key);
...@@ -1412,9 +1412,9 @@ hstore_to_jsonb(PG_FUNCTION_ARGS) ...@@ -1412,9 +1412,9 @@ hstore_to_jsonb(PG_FUNCTION_ARGS)
{ {
val.estSize = sizeof(JEntry); val.estSize = sizeof(JEntry);
val.type = jbvString; val.type = jbvString;
val.string.len = HS_VALLEN(entries, i); val.val.string.len = HS_VALLEN(entries, i);
val.string.val = pnstrdup(HS_VAL(entries, base, i), val.string.len); val.val.string.val = pnstrdup(HS_VAL(entries, base, i), val.val.string.len);
val.estSize += val.string.len; val.estSize += val.val.string.len;
} }
res = pushJsonbValue(&state, WJB_VALUE, &val); res = pushJsonbValue(&state, WJB_VALUE, &val);
} }
...@@ -1449,9 +1449,9 @@ hstore_to_jsonb_loose(PG_FUNCTION_ARGS) ...@@ -1449,9 +1449,9 @@ hstore_to_jsonb_loose(PG_FUNCTION_ARGS)
key.estSize = sizeof(JEntry); key.estSize = sizeof(JEntry);
key.type = jbvString; key.type = jbvString;
key.string.len = HS_KEYLEN(entries, i); key.val.string.len = HS_KEYLEN(entries, i);
key.string.val = pnstrdup(HS_KEY(entries, base, i), key.string.len); key.val.string.val = pnstrdup(HS_KEY(entries, base, i), key.val.string.len);
key.estSize += key.string.len; key.estSize += key.val.string.len;
res = pushJsonbValue(&state, WJB_KEY, &key); res = pushJsonbValue(&state, WJB_KEY, &key);
...@@ -1465,12 +1465,12 @@ hstore_to_jsonb_loose(PG_FUNCTION_ARGS) ...@@ -1465,12 +1465,12 @@ hstore_to_jsonb_loose(PG_FUNCTION_ARGS)
else if (HS_VALLEN(entries, i) == 1 && *(HS_VAL(entries, base, i)) == 't') else if (HS_VALLEN(entries, i) == 1 && *(HS_VAL(entries, base, i)) == 't')
{ {
val.type = jbvBool; val.type = jbvBool;
val.boolean = true; val.val.boolean = true;
} }
else if (HS_VALLEN(entries, i) == 1 && *(HS_VAL(entries, base, i)) == 'f') else if (HS_VALLEN(entries, i) == 1 && *(HS_VAL(entries, base, i)) == 'f')
{ {
val.type = jbvBool; val.type = jbvBool;
val.boolean = false; val.val.boolean = false;
} }
else else
{ {
...@@ -1519,17 +1519,17 @@ hstore_to_jsonb_loose(PG_FUNCTION_ARGS) ...@@ -1519,17 +1519,17 @@ hstore_to_jsonb_loose(PG_FUNCTION_ARGS)
if (is_number) if (is_number)
{ {
val.type = jbvNumeric; val.type = jbvNumeric;
val.numeric = DatumGetNumeric( val.val.numeric = DatumGetNumeric(
DirectFunctionCall3(numeric_in, CStringGetDatum(tmp.data), 0, -1)); DirectFunctionCall3(numeric_in, CStringGetDatum(tmp.data), 0, -1));
val.estSize += VARSIZE_ANY(val.numeric) +sizeof(JEntry); val.estSize += VARSIZE_ANY(val.val.numeric) +sizeof(JEntry);
} }
else else
{ {
val.estSize = sizeof(JEntry); val.estSize = sizeof(JEntry);
val.type = jbvString; val.type = jbvString;
val.string.len = HS_VALLEN(entries, i); val.val.string.len = HS_VALLEN(entries, i);
val.string.val = pnstrdup(HS_VAL(entries, base, i), val.string.len); val.val.string.val = pnstrdup(HS_VAL(entries, base, i), val.val.string.len);
val.estSize += val.string.len; val.estSize += val.val.string.len;
} }
} }
res = pushJsonbValue(&state, WJB_VALUE, &val); res = pushJsonbValue(&state, WJB_VALUE, &val);
......
...@@ -247,9 +247,9 @@ jsonb_in_object_field_start(void *pstate, char *fname, bool isnull) ...@@ -247,9 +247,9 @@ jsonb_in_object_field_start(void *pstate, char *fname, bool isnull)
Assert (fname != NULL); Assert (fname != NULL);
v.type = jbvString; v.type = jbvString;
v.string.len = checkStringLen(strlen(fname)); v.val.string.len = checkStringLen(strlen(fname));
v.string.val = pnstrdup(fname, v.string.len); v.val.string.val = pnstrdup(fname, v.val.string.len);
v.estSize = sizeof(JEntry) + v.string.len; v.estSize = sizeof(JEntry) + v.val.string.len;
_state->res = pushJsonbValue(&_state->parseState, WJB_KEY, &v); _state->res = pushJsonbValue(&_state->parseState, WJB_KEY, &v);
} }
...@@ -263,15 +263,15 @@ jsonb_put_escaped_value(StringInfo out, JsonbValue * scalarVal) ...@@ -263,15 +263,15 @@ jsonb_put_escaped_value(StringInfo out, JsonbValue * scalarVal)
appendBinaryStringInfo(out, "null", 4); appendBinaryStringInfo(out, "null", 4);
break; break;
case jbvString: case jbvString:
escape_json(out, pnstrdup(scalarVal->string.val, scalarVal->string.len)); escape_json(out, pnstrdup(scalarVal->val.string.val, scalarVal->val.string.len));
break; break;
case jbvNumeric: case jbvNumeric:
appendStringInfoString(out, appendStringInfoString(out,
DatumGetCString(DirectFunctionCall1(numeric_out, DatumGetCString(DirectFunctionCall1(numeric_out,
PointerGetDatum(scalarVal->numeric)))); PointerGetDatum(scalarVal->val.numeric))));
break; break;
case jbvBool: case jbvBool:
if (scalarVal->boolean) if (scalarVal->val.boolean)
appendBinaryStringInfo(out, "true", 4); appendBinaryStringInfo(out, "true", 4);
else else
appendBinaryStringInfo(out, "false", 5); appendBinaryStringInfo(out, "false", 5);
...@@ -298,9 +298,9 @@ jsonb_in_scalar(void *pstate, char *token, JsonTokenType tokentype) ...@@ -298,9 +298,9 @@ jsonb_in_scalar(void *pstate, char *token, JsonTokenType tokentype)
case JSON_TOKEN_STRING: case JSON_TOKEN_STRING:
Assert (token != NULL); Assert (token != NULL);
v.type = jbvString; v.type = jbvString;
v.string.len = checkStringLen(strlen(token)); v.val.string.len = checkStringLen(strlen(token));
v.string.val = pnstrdup(token, v.string.len); v.val.string.val = pnstrdup(token, v.val.string.len);
v.estSize += v.string.len; v.estSize += v.val.string.len;
break; break;
case JSON_TOKEN_NUMBER: case JSON_TOKEN_NUMBER:
/* /*
...@@ -309,16 +309,16 @@ jsonb_in_scalar(void *pstate, char *token, JsonTokenType tokentype) ...@@ -309,16 +309,16 @@ jsonb_in_scalar(void *pstate, char *token, JsonTokenType tokentype)
*/ */
Assert (token != NULL); Assert (token != NULL);
v.type = jbvNumeric; v.type = jbvNumeric;
v.numeric = DatumGetNumeric(DirectFunctionCall3(numeric_in, CStringGetDatum(token), 0, -1)); v.val.numeric = DatumGetNumeric(DirectFunctionCall3(numeric_in, CStringGetDatum(token), 0, -1));
v.estSize += VARSIZE_ANY(v.numeric) + sizeof(JEntry) /* alignment */ ; v.estSize += VARSIZE_ANY(v.val.numeric) + sizeof(JEntry) /* alignment */ ;
break; break;
case JSON_TOKEN_TRUE: case JSON_TOKEN_TRUE:
v.type = jbvBool; v.type = jbvBool;
v.boolean = true; v.val.boolean = true;
break; break;
case JSON_TOKEN_FALSE: case JSON_TOKEN_FALSE:
v.type = jbvBool; v.type = jbvBool;
v.boolean = false; v.val.boolean = false;
break; break;
case JSON_TOKEN_NULL: case JSON_TOKEN_NULL:
v.type = jbvNull; v.type = jbvNull;
...@@ -335,8 +335,8 @@ jsonb_in_scalar(void *pstate, char *token, JsonTokenType tokentype) ...@@ -335,8 +335,8 @@ jsonb_in_scalar(void *pstate, char *token, JsonTokenType tokentype)
JsonbValue va; JsonbValue va;
va.type = jbvArray; va.type = jbvArray;
va.array.rawScalar = true; va.val.array.rawScalar = true;
va.array.nElems = 1; va.val.array.nElems = 1;
_state->res = pushJsonbValue(&_state->parseState, WJB_BEGIN_ARRAY, &va); _state->res = pushJsonbValue(&_state->parseState, WJB_BEGIN_ARRAY, &va);
_state->res = pushJsonbValue(&_state->parseState, WJB_ELEM, &v); _state->res = pushJsonbValue(&_state->parseState, WJB_ELEM, &v);
...@@ -399,7 +399,7 @@ JsonbToCString(StringInfo out, JsonbSuperHeader in, int estimated_len) ...@@ -399,7 +399,7 @@ JsonbToCString(StringInfo out, JsonbSuperHeader in, int estimated_len)
appendBinaryStringInfo(out, ", ", 2); appendBinaryStringInfo(out, ", ", 2);
first = true; first = true;
if (!v.array.rawScalar) if (!v.val.array.rawScalar)
appendStringInfoChar(out, '['); appendStringInfoChar(out, '[');
level++; level++;
break; break;
...@@ -448,7 +448,7 @@ JsonbToCString(StringInfo out, JsonbSuperHeader in, int estimated_len) ...@@ -448,7 +448,7 @@ JsonbToCString(StringInfo out, JsonbSuperHeader in, int estimated_len)
break; break;
case WJB_END_ARRAY: case WJB_END_ARRAY:
level--; level--;
if (!v.array.rawScalar) if (!v.val.array.rawScalar)
appendStringInfoChar(out, ']'); appendStringInfoChar(out, ']');
first = false; first = false;
break; break;
......
...@@ -618,7 +618,7 @@ make_scalar_key(const JsonbValue * scalarVal, char flag) ...@@ -618,7 +618,7 @@ make_scalar_key(const JsonbValue * scalarVal, char flag)
item = make_text_key("n", 1, flag); item = make_text_key("n", 1, flag);
break; break;
case jbvBool: case jbvBool:
item = make_text_key(scalarVal->boolean ? "t" : "f", 1, flag); item = make_text_key(scalarVal->val.boolean ? "t" : "f", 1, flag);
break; break;
case jbvNumeric: case jbvNumeric:
/* /*
...@@ -630,12 +630,12 @@ make_scalar_key(const JsonbValue * scalarVal, char flag) ...@@ -630,12 +630,12 @@ make_scalar_key(const JsonbValue * scalarVal, char flag)
* storing a "union" type in the GIN B-Tree, and indexing Jsonb * storing a "union" type in the GIN B-Tree, and indexing Jsonb
* strings takes precedence. * strings takes precedence.
*/ */
cstr = numeric_normalize(scalarVal->numeric); cstr = numeric_normalize(scalarVal->val.numeric);
item = make_text_key(cstr, strlen(cstr), flag); item = make_text_key(cstr, strlen(cstr), flag);
pfree(cstr); pfree(cstr);
break; break;
case jbvString: case jbvString:
item = make_text_key(scalarVal->string.val, scalarVal->string.len, item = make_text_key(scalarVal->val.string.val, scalarVal->val.string.len,
flag); flag);
break; break;
default: default:
......
...@@ -31,8 +31,8 @@ jsonb_exists(PG_FUNCTION_ARGS) ...@@ -31,8 +31,8 @@ jsonb_exists(PG_FUNCTION_ARGS)
* top level. No recursion occurs. * top level. No recursion occurs.
*/ */
kval.type = jbvString; kval.type = jbvString;
kval.string.val = VARDATA_ANY(key); kval.val.string.val = VARDATA_ANY(key);
kval.string.len = VARSIZE_ANY_EXHDR(key); kval.val.string.len = VARSIZE_ANY_EXHDR(key);
v = findJsonbValueFromSuperHeader(VARDATA(jb), v = findJsonbValueFromSuperHeader(VARDATA(jb),
JB_FOBJECT | JB_FARRAY, JB_FOBJECT | JB_FARRAY,
...@@ -52,7 +52,7 @@ jsonb_exists_any(PG_FUNCTION_ARGS) ...@@ -52,7 +52,7 @@ jsonb_exists_any(PG_FUNCTION_ARGS)
lowbound = 0; lowbound = 0;
int i; int i;
if (arrKey == NULL || arrKey->object.nPairs == 0) if (arrKey == NULL || arrKey->val.object.nPairs == 0)
PG_RETURN_BOOL(false); PG_RETURN_BOOL(false);
if (JB_ROOT_IS_OBJECT(jb)) if (JB_ROOT_IS_OBJECT(jb))
...@@ -64,12 +64,12 @@ jsonb_exists_any(PG_FUNCTION_ARGS) ...@@ -64,12 +64,12 @@ jsonb_exists_any(PG_FUNCTION_ARGS)
* each search can start one entry past the previous "found" entry, or at * each search can start one entry past the previous "found" entry, or at
* the lower bound of the last search. * the lower bound of the last search.
*/ */
for (i = 0; i < arrKey->array.nElems; i++) for (i = 0; i < arrKey->val.array.nElems; i++)
{ {
if (findJsonbValueFromSuperHeader(VARDATA(jb), if (findJsonbValueFromSuperHeader(VARDATA(jb),
JB_FOBJECT | JB_FARRAY, JB_FOBJECT | JB_FARRAY,
plowbound, plowbound,
arrKey->array.elems + i) != NULL) arrKey->val.array.elems + i) != NULL)
PG_RETURN_BOOL(true); PG_RETURN_BOOL(true);
} }
...@@ -86,7 +86,7 @@ jsonb_exists_all(PG_FUNCTION_ARGS) ...@@ -86,7 +86,7 @@ jsonb_exists_all(PG_FUNCTION_ARGS)
uint32 lowbound = 0; uint32 lowbound = 0;
int i; int i;
if (arrKey == NULL || arrKey->array.nElems == 0) if (arrKey == NULL || arrKey->val.array.nElems == 0)
PG_RETURN_BOOL(true); PG_RETURN_BOOL(true);
if (JB_ROOT_IS_OBJECT(jb)) if (JB_ROOT_IS_OBJECT(jb))
...@@ -98,12 +98,12 @@ jsonb_exists_all(PG_FUNCTION_ARGS) ...@@ -98,12 +98,12 @@ jsonb_exists_all(PG_FUNCTION_ARGS)
* each search can start one entry past the previous "found" entry, or at * each search can start one entry past the previous "found" entry, or at
* the lower bound of the last search. * the lower bound of the last search.
*/ */
for (i = 0; i < arrKey->array.nElems; i++) for (i = 0; i < arrKey->val.array.nElems; i++)
{ {
if (findJsonbValueFromSuperHeader(VARDATA(jb), if (findJsonbValueFromSuperHeader(VARDATA(jb),
JB_FOBJECT | JB_FARRAY, JB_FOBJECT | JB_FARRAY,
plowbound, plowbound,
arrKey->array.elems + i) == NULL) arrKey->val.array.elems + i) == NULL)
PG_RETURN_BOOL(false); PG_RETURN_BOOL(false);
} }
......
This diff is collapsed.
...@@ -295,9 +295,9 @@ jsonb_object_keys(PG_FUNCTION_ARGS) ...@@ -295,9 +295,9 @@ jsonb_object_keys(PG_FUNCTION_ARGS)
{ {
char *cstr; char *cstr;
cstr = palloc(v.string.len + 1 * sizeof(char)); cstr = palloc(v.val.string.len + 1 * sizeof(char));
memcpy(cstr, v.string.val, v.string.len); memcpy(cstr, v.val.string.val, v.val.string.len);
cstr[v.string.len] = '\0'; cstr[v.val.string.len] = '\0';
state->result[state->result_count++] = cstr; state->result[state->result_count++] = cstr;
} }
} }
...@@ -491,7 +491,7 @@ jsonb_object_field(PG_FUNCTION_ARGS) ...@@ -491,7 +491,7 @@ jsonb_object_field(PG_FUNCTION_ARGS)
if (r == WJB_KEY) if (r == WJB_KEY)
{ {
if (klen == v.string.len && strncmp(key, v.string.val, klen) == 0) if (klen == v.val.string.len && strncmp(key, v.val.string.val, klen) == 0)
{ {
/* /*
* The next thing the iterator fetches should be the value, no * The next thing the iterator fetches should be the value, no
...@@ -552,7 +552,7 @@ jsonb_object_field_text(PG_FUNCTION_ARGS) ...@@ -552,7 +552,7 @@ jsonb_object_field_text(PG_FUNCTION_ARGS)
if (r == WJB_KEY) if (r == WJB_KEY)
{ {
if (klen == v.string.len && strncmp(key, v.string.val, klen) == 0) if (klen == v.val.string.len && strncmp(key, v.val.string.val, klen) == 0)
{ {
text *result; text *result;
...@@ -568,7 +568,7 @@ jsonb_object_field_text(PG_FUNCTION_ARGS) ...@@ -568,7 +568,7 @@ jsonb_object_field_text(PG_FUNCTION_ARGS)
*/ */
if (v.type == jbvString) if (v.type == jbvString)
{ {
result = cstring_to_text_with_len(v.string.val, v.string.len); result = cstring_to_text_with_len(v.val.string.val, v.val.string.len);
} }
else if (v.type == jbvNull) else if (v.type == jbvNull)
{ {
...@@ -699,7 +699,7 @@ jsonb_array_element_text(PG_FUNCTION_ARGS) ...@@ -699,7 +699,7 @@ jsonb_array_element_text(PG_FUNCTION_ARGS)
if (v.type == jbvString) if (v.type == jbvString)
{ {
result = cstring_to_text_with_len(v.string.val, v.string.len); result = cstring_to_text_with_len(v.val.string.val, v.val.string.len);
} }
else if (v.type == jbvNull) else if (v.type == jbvNull)
{ {
...@@ -1209,11 +1209,11 @@ get_jsonb_path_all(FunctionCallInfo fcinfo, bool as_text) ...@@ -1209,11 +1209,11 @@ get_jsonb_path_all(FunctionCallInfo fcinfo, bool as_text)
if (jbvp->type == jbvBinary) if (jbvp->type == jbvBinary)
{ {
JsonbIterator *it = JsonbIteratorInit(jbvp->binary.data); JsonbIterator *it = JsonbIteratorInit(jbvp->val.binary.data);
int r; int r;
r = JsonbIteratorNext(&it, &tv, true); r = JsonbIteratorNext(&it, &tv, true);
superHeader = (JsonbSuperHeader) jbvp->binary.data; superHeader = (JsonbSuperHeader) jbvp->val.binary.data;
have_object = r == WJB_BEGIN_OBJECT; have_object = r == WJB_BEGIN_OBJECT;
have_array = r == WJB_BEGIN_ARRAY; have_array = r == WJB_BEGIN_ARRAY;
} }
...@@ -1227,7 +1227,7 @@ get_jsonb_path_all(FunctionCallInfo fcinfo, bool as_text) ...@@ -1227,7 +1227,7 @@ get_jsonb_path_all(FunctionCallInfo fcinfo, bool as_text)
if (as_text) if (as_text)
{ {
if (jbvp->type == jbvString) if (jbvp->type == jbvString)
PG_RETURN_TEXT_P(cstring_to_text_with_len(jbvp->string.val, jbvp->string.len)); PG_RETURN_TEXT_P(cstring_to_text_with_len(jbvp->val.string.val, jbvp->val.string.len));
else if (jbvp->type == jbvNull) else if (jbvp->type == jbvNull)
PG_RETURN_NULL(); PG_RETURN_NULL();
} }
...@@ -1443,7 +1443,7 @@ each_worker_jsonb(FunctionCallInfo fcinfo, bool as_text) ...@@ -1443,7 +1443,7 @@ each_worker_jsonb(FunctionCallInfo fcinfo, bool as_text)
/* Use the tmp context so we can clean up after each tuple is done */ /* Use the tmp context so we can clean up after each tuple is done */
old_cxt = MemoryContextSwitchTo(tmp_cxt); old_cxt = MemoryContextSwitchTo(tmp_cxt);
key = cstring_to_text_with_len(v.string.val, v.string.len); key = cstring_to_text_with_len(v.val.string.val, v.val.string.len);
/* /*
* The next thing the iterator fetches should be the value, no * The next thing the iterator fetches should be the value, no
...@@ -1468,7 +1468,7 @@ each_worker_jsonb(FunctionCallInfo fcinfo, bool as_text) ...@@ -1468,7 +1468,7 @@ each_worker_jsonb(FunctionCallInfo fcinfo, bool as_text)
if (v.type == jbvString) if (v.type == jbvString)
{ {
/* In text mode, scalar strings should be dequoted */ /* In text mode, scalar strings should be dequoted */
sv = cstring_to_text_with_len(v.string.val, v.string.len); sv = cstring_to_text_with_len(v.val.string.val, v.val.string.len);
} }
else else
{ {
...@@ -1788,7 +1788,7 @@ elements_worker_jsonb(FunctionCallInfo fcinfo, bool as_text) ...@@ -1788,7 +1788,7 @@ elements_worker_jsonb(FunctionCallInfo fcinfo, bool as_text)
if (v.type == jbvString) if (v.type == jbvString)
{ {
/* in text mode scalar strings should be dequoted */ /* in text mode scalar strings should be dequoted */
sv = cstring_to_text_with_len(v.string.val, v.string.len); sv = cstring_to_text_with_len(v.val.string.val, v.val.string.len);
} }
else else
{ {
...@@ -2270,18 +2270,18 @@ populate_record_worker(FunctionCallInfo fcinfo, bool have_record_arg) ...@@ -2270,18 +2270,18 @@ populate_record_worker(FunctionCallInfo fcinfo, bool have_record_arg)
else else
{ {
if (v->type == jbvString) if (v->type == jbvString)
s = pnstrdup(v->string.val, v->string.len); s = pnstrdup(v->val.string.val, v->val.string.len);
else if (v->type == jbvBool) else if (v->type == jbvBool)
s = pnstrdup((v->boolean) ? "t" : "f", 1); s = pnstrdup((v->val.boolean) ? "t" : "f", 1);
else if (v->type == jbvNumeric) else if (v->type == jbvNumeric)
s = DatumGetCString(DirectFunctionCall1(numeric_out, s = DatumGetCString(DirectFunctionCall1(numeric_out,
PointerGetDatum(v->numeric))); PointerGetDatum(v->val.numeric)));
else if (!use_json_as_text) else if (!use_json_as_text)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE), (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("cannot populate with a nested object unless use_json_as_text is true"))); errmsg("cannot populate with a nested object unless use_json_as_text is true")));
else if (v->type == jbvBinary) else if (v->type == jbvBinary)
s = JsonbToCString(NULL, v->binary.data, v->binary.len); s = JsonbToCString(NULL, v->val.binary.data, v->val.binary.len);
else else
elog(ERROR, "invalid jsonb type"); elog(ERROR, "invalid jsonb type");
} }
...@@ -2570,18 +2570,18 @@ make_row_from_rec_and_jsonb(Jsonb * element, PopulateRecordsetState *state) ...@@ -2570,18 +2570,18 @@ make_row_from_rec_and_jsonb(Jsonb * element, PopulateRecordsetState *state)
char *s = NULL; char *s = NULL;
if (v->type == jbvString) if (v->type == jbvString)
s = pnstrdup(v->string.val, v->string.len); s = pnstrdup(v->val.string.val, v->val.string.len);
else if (v->type == jbvBool) else if (v->type == jbvBool)
s = pnstrdup((v->boolean) ? "t" : "f", 1); s = pnstrdup((v->val.boolean) ? "t" : "f", 1);
else if (v->type == jbvNumeric) else if (v->type == jbvNumeric)
s = DatumGetCString(DirectFunctionCall1(numeric_out, s = DatumGetCString(DirectFunctionCall1(numeric_out,
PointerGetDatum(v->numeric))); PointerGetDatum(v->val.numeric)));
else if (!state->use_json_as_text) else if (!state->use_json_as_text)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE), (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("cannot populate with a nested object unless use_json_as_text is true"))); errmsg("cannot populate with a nested object unless use_json_as_text is true")));
else if (v->type == jbvBinary) else if (v->type == jbvBinary)
s = JsonbToCString(NULL, v->binary.data, v->binary.len); s = JsonbToCString(NULL, v->val.binary.data, v->val.binary.len);
else else
elog(ERROR, "invalid jsonb type"); elog(ERROR, "invalid jsonb type");
...@@ -3027,8 +3027,8 @@ findJsonbValueFromSuperHeaderLen(JsonbSuperHeader sheader, uint32 flags, ...@@ -3027,8 +3027,8 @@ findJsonbValueFromSuperHeaderLen(JsonbSuperHeader sheader, uint32 flags,
JsonbValue k; JsonbValue k;
k.type = jbvString; k.type = jbvString;
k.string.val = key; k.val.string.val = key;
k.string.len = keylen; k.val.string.len = keylen;
return findJsonbValueFromSuperHeader(sheader, flags, NULL, &k); return findJsonbValueFromSuperHeader(sheader, flags, NULL, &k);
} }
...@@ -141,7 +141,7 @@ typedef struct ...@@ -141,7 +141,7 @@ typedef struct
/* /*
* JsonbValue: In-memory representation of Jsonb. This is a convenient * JsonbValue: In-memory representation of Jsonb. This is a convenient
* deserialized representation, that can easily support using the anonymous * deserialized representation, that can easily support using the "val"
* union across underlying types during manipulation. The Jsonb on-disk * union across underlying types during manipulation. The Jsonb on-disk
* representation has various alignment considerations. * representation has various alignment considerations.
*/ */
...@@ -192,7 +192,7 @@ struct JsonbValue ...@@ -192,7 +192,7 @@ struct JsonbValue
int len; int len;
char *data; char *data;
} binary; } binary;
}; } val;
}; };
/* /*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment