Skip to content

Commit 98f1b0c

Browse files
committed
DISTINCT key for UNION and INTERSECT
1 parent ac547c0 commit 98f1b0c

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

mindsdb_sql_parser/parser.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,10 +1061,13 @@ def database_engine(self, p):
10611061
@_('select UNION select',
10621062
'union UNION select',
10631063
'select UNION ALL select',
1064-
'union UNION ALL select')
1064+
'union UNION ALL select',
1065+
'select UNION DISTINCT select',
1066+
'union UNION DISTINCT select')
10651067
def union(self, p):
10661068
unique = not hasattr(p, 'ALL')
1067-
return Union(left=p[0], right=p[2] if unique else p[3], unique=unique)
1069+
distinct_key = hasattr(p, 'DISTINCT')
1070+
return Union(left=p[0], right=p[-1], unique=unique, distinct_key=distinct_key)
10681071

10691072
@_('select INTERSECT select',
10701073
'union INTERSECT select',
@@ -1074,15 +1077,19 @@ def union(self, p):
10741077
'union INTERSECT DISTINCT select')
10751078
def union(self, p):
10761079
unique = not hasattr(p, 'ALL')
1077-
return Intersect(left=p[0], right=p[-1], unique=unique)
1080+
distinct_key = hasattr(p, 'DISTINCT')
1081+
return Intersect(left=p[0], right=p[-1], unique=unique, distinct_key=distinct_key)
10781082

10791083
@_('select EXCEPT select',
10801084
'union EXCEPT select',
10811085
'select EXCEPT ALL select',
1082-
'union EXCEPT ALL select')
1086+
'union EXCEPT ALL select',
1087+
'select EXCEPT DISTINCT select',
1088+
'union EXCEPT DISTINCT select')
10831089
def union(self, p):
10841090
unique = not hasattr(p, 'ALL')
1085-
return Except(left=p[0], right=p[2] if unique else p[3], unique=unique)
1091+
distinct_key = hasattr(p, 'DISTINCT')
1092+
return Except(left=p[0], right=p[-1], unique=unique, distinct_key=distinct_key)
10861093

10871094
# tableau
10881095
@_('LPAREN select RPAREN')

0 commit comments

Comments
 (0)