summaryrefslogtreecommitdiff
path: root/src/backend/parser/parse_clause.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/parser/parse_clause.c')
-rw-r--r--src/backend/parser/parse_clause.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/backend/parser/parse_clause.c b/src/backend/parser/parse_clause.c
index 939fa834e0..87b0c8fd41 100644
--- a/src/backend/parser/parse_clause.c
+++ b/src/backend/parser/parse_clause.c
@@ -2011,6 +2011,20 @@ transformDistinctClause(ParseState *pstate,
true);
}
+ /*
+ * Complain if we found nothing to make DISTINCT. Returning an empty list
+ * would cause the parsed Query to look like it didn't have DISTINCT, with
+ * results that would probably surprise the user. Note: this case is
+ * presently impossible for aggregates because of grammar restrictions,
+ * but we check anyway.
+ */
+ if (result == NIL)
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR),
+ is_agg ?
+ errmsg("an aggregate with DISTINCT must have at least one argument") :
+ errmsg("SELECT DISTINCT must have at least one column")));
+
return result;
}
@@ -2115,6 +2129,11 @@ transformDistinctOnClause(ParseState *pstate, List *distinctlist,
true);
}
+ /*
+ * An empty result list is impossible here because of grammar restrictions.
+ */
+ Assert(result != NIL);
+
return result;
}