A subplan invoked within an aggregate function's argument should
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 8 Mar 2001 01:49:01 +0000 (01:49 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 8 Mar 2001 01:49:01 +0000 (01:49 +0000)
be allowed to receive ungrouped variables of the current query level.
Curious that no one reported this bug before...

src/backend/optimizer/util/clauses.c

index 5ab45f67ac2001f355e92d3a78c0896ad9bc3948..9a3ac105365a435ed8f2d4a61474854280bee3bc 100644 (file)
@@ -542,6 +542,14 @@ check_subplans_for_ungrouped_vars_walker(Node *node,
        if (node == NULL)
                return false;
 
+       /*
+        * If we find an aggregate function, do not recurse into its
+        * arguments.  Subplans invoked within aggregate calls are allowed
+        * to receive ungrouped variables.
+        */
+       if (IsA(node, Aggref))
+               return false;
+
        /*
         * We can ignore Vars other than in subplan args lists, since the
         * parser already checked 'em.