Handle unsupported set operators for MySQL.
This commit is contained in:
parent
4c5584aaae
commit
7930fb23ba
4 changed files with 133 additions and 13 deletions
|
|
@ -7,37 +7,37 @@ import (
|
|||
// UNION effectively appends the result of sub-queries(select statements) into single query.
|
||||
// It eliminates duplicate rows from its result.
|
||||
func UNION(lhs, rhs SelectStatement, selects ...SelectStatement) SelectStatement {
|
||||
return newSetStatementImpl(union, false, toSelectList(lhs, rhs, selects...))
|
||||
return newSetStatementImpl(Union, false, toSelectList(lhs, rhs, selects...))
|
||||
}
|
||||
|
||||
// UNION_ALL effectively appends the result of sub-queries(select statements) into single query.
|
||||
// It does not eliminates duplicate rows from its result.
|
||||
func UNION_ALL(lhs, rhs SelectStatement, selects ...SelectStatement) SelectStatement {
|
||||
return newSetStatementImpl(union, true, toSelectList(lhs, rhs, selects...))
|
||||
return newSetStatementImpl(Union, true, toSelectList(lhs, rhs, selects...))
|
||||
}
|
||||
|
||||
// INTERSECT returns all rows that are in query results.
|
||||
// It eliminates duplicate rows from its result.
|
||||
func INTERSECT(lhs, rhs SelectStatement, selects ...SelectStatement) SelectStatement {
|
||||
return newSetStatementImpl(intersect, false, toSelectList(lhs, rhs, selects...))
|
||||
return newSetStatementImpl(Intersect, false, toSelectList(lhs, rhs, selects...))
|
||||
}
|
||||
|
||||
// INTERSECT_ALL returns all rows that are in query results.
|
||||
// It does not eliminates duplicate rows from its result.
|
||||
func INTERSECT_ALL(lhs, rhs SelectStatement, selects ...SelectStatement) SelectStatement {
|
||||
return newSetStatementImpl(intersect, true, toSelectList(lhs, rhs, selects...))
|
||||
return newSetStatementImpl(Intersect, true, toSelectList(lhs, rhs, selects...))
|
||||
}
|
||||
|
||||
// EXCEPT returns all rows that are in the result of query lhs but not in the result of query rhs.
|
||||
// It eliminates duplicate rows from its result.
|
||||
func EXCEPT(lhs, rhs SelectStatement) SelectStatement {
|
||||
return newSetStatementImpl(except, false, toSelectList(lhs, rhs))
|
||||
return newSetStatementImpl(Except, false, toSelectList(lhs, rhs))
|
||||
}
|
||||
|
||||
// EXCEPT_ALL returns all rows that are in the result of query lhs but not in the result of query rhs.
|
||||
// It does not eliminates duplicate rows from its result.
|
||||
func EXCEPT_ALL(lhs, rhs SelectStatement) SelectStatement {
|
||||
return newSetStatementImpl(except, true, toSelectList(lhs, rhs))
|
||||
return newSetStatementImpl(Except, true, toSelectList(lhs, rhs))
|
||||
}
|
||||
|
||||
func toSelectList(lhs, rhs SelectStatement, selects ...SelectStatement) []SelectStatement {
|
||||
|
|
@ -45,9 +45,9 @@ func toSelectList(lhs, rhs SelectStatement, selects ...SelectStatement) []Select
|
|||
}
|
||||
|
||||
const (
|
||||
union = "UNION"
|
||||
intersect = "INTERSECT"
|
||||
except = "EXCEPT"
|
||||
Union = "UNION"
|
||||
Intersect = "INTERSECT"
|
||||
Except = "EXCEPT"
|
||||
)
|
||||
|
||||
// Similar to selectStatementImpl, but less complete
|
||||
|
|
@ -125,6 +125,10 @@ func (s *setStatementImpl) serializeImpl(out *SqlBuilder) error {
|
|||
return errors.New("jet: UNION Statement must have at least two SELECT statements")
|
||||
}
|
||||
|
||||
if setOverride := out.Dialect.SerializeOverride(s.operator); setOverride != nil {
|
||||
return setOverride()(SelectStatementType, out)
|
||||
}
|
||||
|
||||
out.newLine()
|
||||
out.WriteString("(")
|
||||
out.increaseIdent()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue