SQL returns the SQL representation of this IN expression. The NOT modifier is included when InExpression.Not is true. Supports both value lists "x IN (1, 2, 3)" and subqueries "x IN (SELECT ...)".
()
| 280 | // The NOT modifier is included when InExpression.Not is true. |
| 281 | // Supports both value lists "x IN (1, 2, 3)" and subqueries "x IN (SELECT ...)". |
| 282 | func (i *InExpression) SQL() string { |
| 283 | if i == nil { |
| 284 | return "" |
| 285 | } |
| 286 | not := "" |
| 287 | if i.Not { |
| 288 | not = "NOT " |
| 289 | } |
| 290 | if i.Subquery != nil { |
| 291 | return fmt.Sprintf("%s %sIN (%s)", exprSQL(i.Expr), not, stmtSQL(i.Subquery)) |
| 292 | } |
| 293 | vals := make([]string, len(i.List)) |
| 294 | for idx, v := range i.List { |
| 295 | vals[idx] = exprSQL(v) |
| 296 | } |
| 297 | return fmt.Sprintf("%s %sIN (%s)", exprSQL(i.Expr), not, strings.Join(vals, ", ")) |
| 298 | } |
| 299 | |
| 300 | // SQL returns the SQL representation of this EXISTS expression as "EXISTS (subquery)". |
| 301 | func (e *ExistsExpression) SQL() string { |