| 663 | } |
| 664 | |
| 665 | func (t *translator) groupBy(sch *selectScope, in []ast.Expr, inType super.Type) []exprloc { |
| 666 | var out []exprloc |
| 667 | for _, expr := range in { |
| 668 | var typ super.Type |
| 669 | var e sem.Expr |
| 670 | if colno, ok := isOrdinal(expr); ok { |
| 671 | if colno < 1 || colno > len(sch.columns) { |
| 672 | t.error(expr, fmt.Errorf("position %d is not in select list", colno)) |
| 673 | typ = t.checker.unknown |
| 674 | } else { |
| 675 | save := sch.groupByLoc |
| 676 | sch.groupByLoc = expr |
| 677 | e, typ = t.expr(sch.columns[colno-1].astExpr, inType) |
| 678 | sch.groupByLoc = save |
| 679 | } |
| 680 | } else { |
| 681 | e, typ = t.expr(expr, inType) |
| 682 | } |
| 683 | out = append(out, exprloc{expr, e, typ}) |
| 684 | } |
| 685 | return out |
| 686 | } |
| 687 | |
| 688 | func isOrdinal(e ast.Expr) (int, bool) { |
| 689 | if e, ok := e.(*ast.Primitive); ok && e.Type == "int64" { |