| 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"}}} |
| 237 | stmt := &SelectStatement{ |
| 238 | With: &WithClause{CTEs: []*CommonTableExpr{{Name: "big_orders", Statement: inner}}}, |
| 239 | Columns: []Expression{&Identifier{Name: "*"}}, |
| 240 | From: []TableReference{{Name: "big_orders"}}, |
| 241 | } |
| 242 | want := "WITH big_orders AS (SELECT * FROM orders WHERE total > 100) SELECT * FROM big_orders" |
| 243 | if got := stmt.SQL(); got != want { |
| 244 | t.Errorf("SQL() =\n %s\nwant:\n %s", got, want) |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | func TestSetOperationSQL(t *testing.T) { |
| 249 | stmt := &SetOperation{ |