Return error if queries mix aggregate and raw

Fixes issue #3198
pull/3625/head
Philip O'Toole 2015-08-11 11:59:04 -07:00
parent be792b926a
commit 4770451837
1 changed files with 13 additions and 1 deletions

View File

@ -998,7 +998,19 @@ func (s *SelectStatement) validate(tr targetRequirement) error {
}
func (s *SelectStatement) validateAggregates(tr targetRequirement) error {
// First, determine if specific calls have at least one and only one argument
// First, if 1 field is an aggregate, then all fields must be an aggregate. This is
// a explicit limitation of the current system.
numAggregates := 0
for _, f := range s.Fields {
if _, ok := f.Expr.(*Call); ok {
numAggregates++
}
}
if numAggregates != 0 && numAggregates != len(s.Fields) {
return fmt.Errorf("mixing aggregate and non-aggregate queries is not supported")
}
// Secondly, determine if specific calls have at least one and only one argument
for _, f := range s.Fields {
if c, ok := f.Expr.(*Call); ok {
switch c.Name {