diff options
Diffstat (limited to 'src/backend/parser/parse_agg.c')
-rw-r--r-- | src/backend/parser/parse_agg.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/backend/parser/parse_agg.c b/src/backend/parser/parse_agg.c index bd095d05c0b..102accd0716 100644 --- a/src/backend/parser/parse_agg.c +++ b/src/backend/parser/parse_agg.c @@ -1333,9 +1333,6 @@ substitute_grouped_columns_mutator(Node *node, if (node == NULL) return NULL; - if (IsA(node, Const) || - IsA(node, Param)) - return node; /* constants are always acceptable */ if (IsA(node, Aggref)) { @@ -1410,6 +1407,16 @@ substitute_grouped_columns_mutator(Node *node, } /* + * Constants are always acceptable. We have to do this after we checked + * the subexpression as a whole for a match, because it is possible that + * we have GROUP BY items that are constants, and the constants would + * become not so constant after the grouping step. + */ + if (IsA(node, Const) || + IsA(node, Param)) + return node; + + /* * If we have an ungrouped Var of the original query level, we have a * failure. Vars below the original query level are not a problem, and * neither are Vars from above it. (If such Vars are ungrouped as far as |