Only jsonb arrays are subscriptable
authorPeter Geoghegan <[email protected]>
Mon, 17 Mar 2014 21:58:39 +0000 (14:58 -0700)
committerPeter Geoghegan <[email protected]>
Mon, 17 Mar 2014 21:58:39 +0000 (14:58 -0700)
src/backend/utils/adt/jsonb_util.c
src/backend/utils/adt/jsonfuncs.c
src/include/utils/jsonb.h

index 266ff1678b4b69c7f7800307c6edb80c4b0de745..470825d62fca872d4d5e55d6c1484d1d57eae3aa 100644 (file)
@@ -472,14 +472,14 @@ findJsonbValueFromSuperHeader(JsonbSuperHeader sheader, uint32 flags,
 }
 
 /*
- * Get i-th value of array or object.
+ * Get i-th value of Jsonb array from superheader.
  *
- * Returns palloc()'d copy of value, or NULL if it cannot be found.  "flags"
- * allows caller to specify which container types are of interest.
+ * Returns palloc()'d copy of value, or NULL if it cannot be found.
+ *
+ * This only works with Jsonb arrays, and
  */
 JsonbValue *
-getIthJsonbValueFromSuperHeader(JsonbSuperHeader sheader, uint32 flags,
-                               uint32 i)
+getIthJsonbValueFromSuperHeader(JsonbSuperHeader sheader, uint32 i)
 {
    uint32      superheader = *(uint32 *) sheader;
    JsonbValue *r;
@@ -487,8 +487,6 @@ getIthJsonbValueFromSuperHeader(JsonbSuperHeader sheader, uint32 flags,
               *e;
    char       *data;
 
-   Assert((flags & ~(JB_FARRAY | JB_FOBJECT)) == 0);
-
    r = palloc(sizeof(JsonbValue));
 
    if (i >= (superheader & JB_CMASK))
@@ -496,19 +494,14 @@ getIthJsonbValueFromSuperHeader(JsonbSuperHeader sheader, uint32 flags,
 
    array = (JEntry *) (sheader + sizeof(uint32));
 
-   if (flags & JB_FARRAY & superheader)
+   if (superheader & JB_FARRAY)
    {
        e = array + i;
        data = (char *) (array + (superheader & JB_CMASK));
    }
-   else if (flags & JB_FOBJECT & superheader)
-   {
-       e = array + i * 2 + 1;
-       data = (char *) (array + (superheader & JB_CMASK) * 2);
-   }
    else
    {
-       return NULL;
+       elog(ERROR, "not a jsonb array");
    }
 
    if (JBE_ISSTRING(*e))
index b36ecd24bc3094af2c58a28e7f0871e09ed3a77f..64b66c427bfd1e54ddcce0d54bf693f88fb8a5dd 100644 (file)
@@ -1211,7 +1211,7 @@ get_jsonb_path_all(FunctionCallInfo fcinfo, bool as_text)
                PG_RETURN_NULL();
            index = (uint32) lindex;
            jbvp = getIthJsonbValueFromSuperHeader((JsonbSuperHeader) jbvp,
-                                                  JB_FARRAY, index);
+                                                  index);
        }
        else
        {
index 04a74a2e510433cf07abf0aa592824774d417a4b..f02657cbb43ddc0ff3c2f87cc6513b7e50031efc 100644 (file)
@@ -300,7 +300,7 @@ extern JsonbValue *findJsonbValueFromSuperHeader(JsonbSuperHeader sheader,
                                                 uint32 *lowbound,
                                                 JsonbValue *key);
 extern JsonbValue *getIthJsonbValueFromSuperHeader(JsonbSuperHeader sheader,
-                                                  uint32 flags, uint32 i);
+                                                  uint32 i);
 extern JsonbValue *pushJsonbValue(ToJsonbState ** state, int r, JsonbValue *v);
 extern JsonbIterator *JsonbIteratorInit(JsonbSuperHeader buffer);
 extern int JsonbIteratorNext(JsonbIterator **it, JsonbValue *v,