| 222 | } |
| 223 | |
| 224 | func TestWindowFunctionSQL(t *testing.T) { |
| 225 | stmt := &SelectStatement{ |
| 226 | Columns: []Expression{&FunctionCall{Name: "ROW_NUMBER", Over: &WindowSpec{PartitionBy: []Expression{&Identifier{Name: "dept_id"}}, OrderBy: []OrderByExpression{{Expression: &Identifier{Name: "salary"}, Ascending: false}}}}}, |
| 227 | From: []TableReference{{Name: "employees"}}, |
| 228 | } |
| 229 | want := "SELECT ROW_NUMBER() OVER (PARTITION BY dept_id ORDER BY salary DESC) FROM employees" |
| 230 | if got := stmt.SQL(); got != want { |
| 231 | t.Errorf("SQL() =\n %s\nwant:\n %s", got, want) |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | func TestCTESQL(t *testing.T) { |
| 236 | inner := &SelectStatement{Columns: []Expression{&Identifier{Name: "*"}}, From: []TableReference{{Name: "orders"}}, Where: &BinaryExpression{Left: &Identifier{Name: "total"}, Operator: ">", Right: &LiteralValue{Value: 100, Type: "INTEGER"}}} |