Fix jsonb_exists_all
authorPeter Geoghegan <[email protected]>
Fri, 7 Mar 2014 09:31:47 +0000 (01:31 -0800)
committerPeter Geoghegan <[email protected]>
Fri, 7 Mar 2014 09:31:47 +0000 (01:31 -0800)
src/backend/utils/adt/jsonb_op.c
src/backend/utils/adt/jsonb_support.c

index 50fc834d14ea5163181307686e86ec4d0b64edc8..8bb589ee16e206412fb8236fd03d13728faa1143 100644 (file)
@@ -151,12 +151,13 @@ jsonb_exists_any(PG_FUNCTION_ARGS)
 Datum
 jsonb_exists_all(PG_FUNCTION_ARGS)
 {
-   Jsonb           *js = PG_GETARG_JSONB(0);
-   ArrayType       *keys = PG_GETARG_ARRAYTYPE_P(1);
-   JsonbValue      *v = arrayToJsonbSortedArray(keys);
+   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;
-   uint32          *plowbound = NULL, lowbound = 0;
-   bool            res = false;
 
    if (JB_ISEMPTY(js) || v == NULL || v->array.nelems == 0)
    {
@@ -170,7 +171,7 @@ jsonb_exists_all(PG_FUNCTION_ARGS)
        plowbound = &lowbound;
 
    /*
-    * we exploit the fact that the pairs list is already sorted into strictly
+    * 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.
@@ -180,9 +181,9 @@ jsonb_exists_all(PG_FUNCTION_ARGS)
        if (findUncompressedJsonbValueByValue(VARDATA(js),
                                              JB_FLAG_OBJECT | JB_FLAG_ARRAY,
                                              plowbound,
-                                             v->array.elems + i) != NULL)
+                                             v->array.elems + i) == NULL)
        {
-           res = true;
+           res = false;
            break;
        }
    }
index f55c4da64bbd596bc36e4aa49321f0034ce19813..e695b892c69fec002ab508372e468f10b8edcc52 100644 (file)
@@ -306,15 +306,15 @@ compareJsonbBinaryValue(char *a, char *b)
    return res;
 }
 
-/****************************************************************************
- * find string key in object or element by value in array          *
- ****************************************************************************/
+/*
+ * Find string key in object or element by value in array
+ */
 JsonbValue *
 findUncompressedJsonbValueByValue(char *buffer, uint32 flags,
                                  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));