Skip to content

Commit 93bcea9

Browse files
committed
✨ Add support for except/intersect queries
1 parent 5111faa commit 93bcea9

File tree

8 files changed

+355990
-355850
lines changed

8 files changed

+355990
-355850
lines changed

other/sqlparser/ast.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -300,12 +300,13 @@ type (
300300
// Lock is an enum for the type of lock in the statement
301301
Lock int8
302302

303-
// Union represents a UNION statement.
303+
// Union represents a UNION/INTERSECT/EXCEPT statement.
304304
Union struct {
305305
With *With
306306
Left SelectStatement
307307
Right SelectStatement
308308
Distinct bool
309+
Type string
309310
OrderBy OrderBy
310311
Limit *Limit
311312
Lock Lock

other/sqlparser/ast_format.go

+13-4
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,19 @@ func (node *Union) Format(buf *TrackedBuffer) {
109109
}
110110

111111
buf.WriteByte(' ')
112-
if node.Distinct {
113-
buf.literal(UnionStr)
114-
} else {
115-
buf.literal(UnionAllStr)
112+
switch node.Type {
113+
case "union":
114+
buf.literal("union")
115+
case "union all":
116+
buf.literal("union all")
117+
case "union distinct":
118+
buf.literal("union distinct")
119+
case "except":
120+
buf.literal("except")
121+
case "intersect":
122+
buf.literal("intersect")
123+
default:
124+
buf.literal("union")
116125
}
117126
buf.WriteByte(' ')
118127

other/sqlparser/ast_format_fast.go

+13-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

other/sqlparser/constants.go

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ const (
4848
UnionStr = "union"
4949
UnionAllStr = "union all"
5050
UnionDistinctStr = "union distinct"
51+
ExceptStr = "except"
52+
IntersectStr = "intersect"
5153

5254
// DDL strings.
5355
InsertStr = "insert"

other/sqlparser/keywords.go

+3
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,9 @@ var keywords = []keyword{
728728
{"undo", UNUSED},
729729
{"unicode", UNICODE},
730730
{"union", UNION},
731+
{"except", EXCEPT},
732+
{"intersect", INTERSECT},
733+
{"minus", EXCEPT},
731734
{"unique", UNIQUE},
732735
{"unknown", UNKNOWN},
733736
{"unlock", UNLOCK},

0 commit comments

Comments
 (0)