Table of Contents

1. lexerTests

1.1. lexer token tests

1.1.1. ansiLexerTests

1.1.1.1. ansi lexer token tests
+
Right [ ( ( "" , 1 , 1 ) , Symbol "+" ) ]
-
Right [ ( ( "" , 1 , 1 ) , Symbol "-" ) ]
^
Right [ ( ( "" , 1 , 1 ) , Symbol "^" ) ]
*
Right [ ( ( "" , 1 , 1 ) , Symbol "*" ) ]
/
Right [ ( ( "" , 1 , 1 ) , Symbol "/" ) ]
%
Right [ ( ( "" , 1 , 1 ) , Symbol "%" ) ]
~
Right [ ( ( "" , 1 , 1 ) , Symbol "~" ) ]
&
Right [ ( ( "" , 1 , 1 ) , Symbol "&" ) ]
|
Right [ ( ( "" , 1 , 1 ) , Symbol "|" ) ]
?
Right [ ( ( "" , 1 , 1 ) , Symbol "?" ) ]
<
Right [ ( ( "" , 1 , 1 ) , Symbol "<" ) ]
>
Right [ ( ( "" , 1 , 1 ) , Symbol ">" ) ]
[
Right [ ( ( "" , 1 , 1 ) , Symbol "[" ) ]
]
Right [ ( ( "" , 1 , 1 ) , Symbol "]" ) ]
=
Right [ ( ( "" , 1 , 1 ) , Symbol "=" ) ]
,
Right [ ( ( "" , 1 , 1 ) , Symbol "," ) ]
;
Right [ ( ( "" , 1 , 1 ) , Symbol ";" ) ]
(
Right [ ( ( "" , 1 , 1 ) , Symbol "(" ) ]
)
Right [ ( ( "" , 1 , 1 ) , Symbol ")" ) ]
>=
Right [ ( ( "" , 1 , 1 ) , Symbol ">=" ) ]
<=
Right [ ( ( "" , 1 , 1 ) , Symbol "<=" ) ]
!=
Right [ ( ( "" , 1 , 1 ) , Symbol "!=" ) ]
<>
Right [ ( ( "" , 1 , 1 ) , Symbol "<>" ) ]
||
Right [ ( ( "" , 1 , 1 ) , Symbol "||" ) ]
a
Right [ ( ( "" , 1 , 1 ) , Identifier Nothing "a" ) ]
_a
Right [ ( ( "" , 1 , 1 ) , Identifier Nothing "_a" ) ]
test
Right [ ( ( "" , 1 , 1 ) , Identifier Nothing "test" ) ]
table
Right [ ( ( "" , 1 , 1 ) , Identifier Nothing "table" ) ]
Stuff
Right [ ( ( "" , 1 , 1 ) , Identifier Nothing "Stuff" ) ]
STUFF
Right [ ( ( "" , 1 , 1 ) , Identifier Nothing "STUFF" ) ]
"a"
Right
  [ ( ( "" , 1 , 1 ) , Identifier (Just ( "\"" , "\"" )) "a" ) ]
"_a"
Right
  [ ( ( "" , 1 , 1 ) , Identifier (Just ( "\"" , "\"" )) "_a" ) ]
"test"
Right
  [ ( ( "" , 1 , 1 ) , Identifier (Just ( "\"" , "\"" )) "test" ) ]
"table"
Right
  [ ( ( "" , 1 , 1 ) , Identifier (Just ( "\"" , "\"" )) "table" ) ]
"Stuff"
Right
  [ ( ( "" , 1 , 1 ) , Identifier (Just ( "\"" , "\"" )) "Stuff" ) ]
"STUFF"
Right
  [ ( ( "" , 1 , 1 ) , Identifier (Just ( "\"" , "\"" )) "STUFF" ) ]
u&"a"
Right
  [ ( ( "" , 1 , 1 ) , Identifier (Just ( "u&\"" , "\"" )) "a" ) ]
u&"_a"
Right
  [ ( ( "" , 1 , 1 ) , Identifier (Just ( "u&\"" , "\"" )) "_a" ) ]
u&"test"
Right
  [ ( ( "" , 1 , 1 ) , Identifier (Just ( "u&\"" , "\"" )) "test" ) ]
u&"table"
Right
  [ ( ( "" , 1 , 1 ) , Identifier (Just ( "u&\"" , "\"" )) "table" )
  ]
u&"Stuff"
Right
  [ ( ( "" , 1 , 1 ) , Identifier (Just ( "u&\"" , "\"" )) "Stuff" )
  ]
u&"STUFF"
Right
  [ ( ( "" , 1 , 1 ) , Identifier (Just ( "u&\"" , "\"" )) "STUFF" )
  ]
:a
Right [ ( ( "" , 1 , 1 ) , PrefixedVariable ':' "a" ) ]
:_a
Right [ ( ( "" , 1 , 1 ) , PrefixedVariable ':' "_a" ) ]
:test
Right [ ( ( "" , 1 , 1 ) , PrefixedVariable ':' "test" ) ]
:table
Right [ ( ( "" , 1 , 1 ) , PrefixedVariable ':' "table" ) ]
:Stuff
Right [ ( ( "" , 1 , 1 ) , PrefixedVariable ':' "Stuff" ) ]
:STUFF
Right [ ( ( "" , 1 , 1 ) , PrefixedVariable ':' "STUFF" ) ]
"normal "" iden"
Right
  [ ( ( "" , 1 , 1 )
    , Identifier (Just ( "\"" , "\"" )) "normal \"\" iden"
    )
  ]
'string'
Right [ ( ( "" , 1 , 1 ) , SqlString "'" "'" "string" ) ]
'normal '' quote'
Right [ ( ( "" , 1 , 1 ) , SqlString "'" "'" "normal '' quote" ) ]
'normalendquote '''
Right
  [ ( ( "" , 1 , 1 ) , SqlString "'" "'" "normalendquote ''" ) ]
'
'
Right [ ( ( "" , 1 , 1 ) , SqlString "'" "'" "\n" ) ]
n'test'
Right [ ( ( "" , 1 , 1 ) , SqlString "n'" "'" "test" ) ]
N'test'
Right [ ( ( "" , 1 , 1 ) , SqlString "N'" "'" "test" ) ]
b'test'
Right [ ( ( "" , 1 , 1 ) , SqlString "b'" "'" "test" ) ]
B'test'
Right [ ( ( "" , 1 , 1 ) , SqlString "B'" "'" "test" ) ]
x'test'
Right [ ( ( "" , 1 , 1 ) , SqlString "x'" "'" "test" ) ]
X'test'
Right [ ( ( "" , 1 , 1 ) , SqlString "X'" "'" "test" ) ]
u&'test'
Right [ ( ( "" , 1 , 1 ) , SqlString "u&'" "'" "test" ) ]
10
Right [ ( ( "" , 1 , 1 ) , SqlNumber "10" ) ]
.1
Right [ ( ( "" , 1 , 1 ) , SqlNumber ".1" ) ]
5e3
Right [ ( ( "" , 1 , 1 ) , SqlNumber "5e3" ) ]
5e+3
Right [ ( ( "" , 1 , 1 ) , SqlNumber "5e+3" ) ]
5e-3
Right [ ( ( "" , 1 , 1 ) , SqlNumber "5e-3" ) ]
10.2
Right [ ( ( "" , 1 , 1 ) , SqlNumber "10.2" ) ]
10.2e7
Right [ ( ( "" , 1 , 1 ) , SqlNumber "10.2e7" ) ]
Right [ ( ( "" , 1 , 1 ) , Whitespace " " ) ]
Right [ ( ( "" , 1 , 1 ) , Whitespace "  " ) ]
Right [ ( ( "" , 1 , 1 ) , Whitespace " " ) ]
Right [ ( ( "" , 1 , 1 ) , Whitespace " \n" ) ]
Right [ ( ( "" , 1 , 1 ) , Whitespace " " ) ]
Right [ ( ( "" , 1 , 1 ) , Whitespace " \t" ) ]
Right [ ( ( "" , 1 , 1 ) , Whitespace "\n" ) ]
Right [ ( ( "" , 1 , 1 ) , Whitespace "\n " ) ]
Right [ ( ( "" , 1 , 1 ) , Whitespace "\n" ) ]
Right [ ( ( "" , 1 , 1 ) , Whitespace "\n\n" ) ]
Right [ ( ( "" , 1 , 1 ) , Whitespace "\n" ) ]
Right [ ( ( "" , 1 , 1 ) , Whitespace "\n\t" ) ]
Right [ ( ( "" , 1 , 1 ) , Whitespace "\t" ) ]
Right [ ( ( "" , 1 , 1 ) , Whitespace "\t " ) ]
Right [ ( ( "" , 1 , 1 ) , Whitespace "\t" ) ]
Right [ ( ( "" , 1 , 1 ) , Whitespace "\t\n" ) ]
Right [ ( ( "" , 1 , 1 ) , Whitespace "\t" ) ]
Right [ ( ( "" , 1 , 1 ) , Whitespace "\t\t" ) ]
--
Right [ ( ( "" , 1 , 1 ) , LineComment "--" ) ]
--
Right [ ( ( "" , 1 , 1 ) , LineComment "-- " ) ]
-- this is a comment
Right [ ( ( "" , 1 , 1 ) , LineComment "-- this is a comment" ) ]
-- line com
Right [ ( ( "" , 1 , 1 ) , LineComment "-- line com\n" ) ]
/**/
Right [ ( ( "" , 1 , 1 ) , BlockComment "/**/" ) ]
/* */
Right [ ( ( "" , 1 , 1 ) , BlockComment "/* */" ) ]
/* this is a comment */
Right
  [ ( ( "" , 1 , 1 ) , BlockComment "/* this is a comment */" ) ]
/* this *is/ a comment */
Right
  [ ( ( "" , 1 , 1 ) , BlockComment "/* this *is/ a comment */" ) ]
1.1.1.2. ansiadhoclexertests
Right []
-- line com
stuff
Right
  [ ( ( "" , 1 , 1 ) , LineComment "-- line com\n" )
  , ( ( "" , 2 , 1 ) , Identifier Nothing "stuff" )
  ]
*/
Left
  ParseError
    { peErrorString =
        "(line 1, column 3):\ncomment end without comment start"
    , peFilename = ""
    , pePosition = ( 1 , 3 )
    , peFormattedError =
        ":1:3:\n*/\n  ^\n(line 1, column 3):\ncomment end without comment start"
    }
|||
Left
  ParseError
    { peErrorString = "(line 1, column 4):\nunexpected '|'"
    , peFilename = ""
    , pePosition = ( 1 , 4 )
    , peFormattedError =
        ":1:4:\n|||\n   ^\n(line 1, column 4):\nunexpected '|'"
    }
||||
Left
  ParseError
    { peErrorString = "(line 1, column 4):\nunexpected '|'"
    , peFilename = ""
    , pePosition = ( 1 , 4 )
    , peFormattedError =
        ":1:4:\n||||\n   ^\n(line 1, column 4):\nunexpected '|'"
    }
|||||
Left
  ParseError
    { peErrorString = "(line 1, column 4):\nunexpected '|'"
    , peFilename = ""
    , pePosition = ( 1 , 4 )
    , peFormattedError =
        ":1:4:\n|||||\n   ^\n(line 1, column 4):\nunexpected '|'"
    }
12e3e4
Left
  ParseError
    { peErrorString = "(line 1, column 6):\nunexpected 'e'"
    , peFilename = ""
    , pePosition = ( 1 , 6 )
    , peFormattedError =
        ":1:6:\n12e3e4\n     ^\n(line 1, column 6):\nunexpected 'e'"
    }
12e3e4
Left
  ParseError
    { peErrorString = "(line 1, column 6):\nunexpected 'e'"
    , peFilename = ""
    , pePosition = ( 1 , 6 )
    , peFormattedError =
        ":1:6:\n12e3e4\n     ^\n(line 1, column 6):\nunexpected 'e'"
    }
12e3e4
Left
  ParseError
    { peErrorString = "(line 1, column 6):\nunexpected 'e'"
    , peFilename = ""
    , pePosition = ( 1 , 6 )
    , peFormattedError =
        ":1:6:\n12e3e4\n     ^\n(line 1, column 6):\nunexpected 'e'"
    }
12e3.4
Left
  ParseError
    { peErrorString = "(line 1, column 6):\nunexpected '.'"
    , peFilename = ""
    , pePosition = ( 1 , 6 )
    , peFormattedError =
        ":1:6:\n12e3.4\n     ^\n(line 1, column 6):\nunexpected '.'"
    }
12.4.5
Left
  ParseError
    { peErrorString = "(line 1, column 6):\nunexpected '.'"
    , peFilename = ""
    , pePosition = ( 1 , 6 )
    , peFormattedError =
        ":1:6:\n12.4.5\n     ^\n(line 1, column 6):\nunexpected '.'"
    }
12.4e5.6
Left
  ParseError
    { peErrorString = "(line 1, column 8):\nunexpected '.'"
    , peFilename = ""
    , pePosition = ( 1 , 8 )
    , peFormattedError =
        ":1:8:\n12.4e5.6\n       ^\n(line 1, column 8):\nunexpected '.'"
    }
12.4e5e7
Left
  ParseError
    { peErrorString = "(line 1, column 8):\nunexpected 'e'"
    , peFilename = ""
    , pePosition = ( 1 , 8 )
    , peFormattedError =
        ":1:8:\n12.4e5e7\n       ^\n(line 1, column 8):\nunexpected 'e'"
    }

1.1.2. postgresLexerTests

1.1.2.1. postgres lexer token tests
+
Right [ ( ( "" , 1 , 1 ) , Symbol "+" ) ]
-
Right [ ( ( "" , 1 , 1 ) , Symbol "-" ) ]
^
Right [ ( ( "" , 1 , 1 ) , Symbol "^" ) ]
*
Right [ ( ( "" , 1 , 1 ) , Symbol "*" ) ]
/
Right [ ( ( "" , 1 , 1 ) , Symbol "/" ) ]
%
Right [ ( ( "" , 1 , 1 ) , Symbol "%" ) ]
~
Right [ ( ( "" , 1 , 1 ) , Symbol "~" ) ]
&
Right [ ( ( "" , 1 , 1 ) , Symbol "&" ) ]
|
Right [ ( ( "" , 1 , 1 ) , Symbol "|" ) ]
?
Right [ ( ( "" , 1 , 1 ) , Symbol "?" ) ]
<
Right [ ( ( "" , 1 , 1 ) , Symbol "<" ) ]
>
Right [ ( ( "" , 1 , 1 ) , Symbol ">" ) ]
[
Right [ ( ( "" , 1 , 1 ) , Symbol "[" ) ]
]
Right [ ( ( "" , 1 , 1 ) , Symbol "]" ) ]
=
Right [ ( ( "" , 1 , 1 ) , Symbol "=" ) ]
,
Right [ ( ( "" , 1 , 1 ) , Symbol "," ) ]
;
Right [ ( ( "" , 1 , 1 ) , Symbol ";" ) ]
(
Right [ ( ( "" , 1 , 1 ) , Symbol "(" ) ]
)
Right [ ( ( "" , 1 , 1 ) , Symbol ")" ) ]
:
Right [ ( ( "" , 1 , 1 ) , Symbol ":" ) ]
>=
Right [ ( ( "" , 1 , 1 ) , Symbol ">=" ) ]
<=
Right [ ( ( "" , 1 , 1 ) , Symbol "<=" ) ]
!=
Right [ ( ( "" , 1 , 1 ) , Symbol "!=" ) ]
<>
Right [ ( ( "" , 1 , 1 ) , Symbol "<>" ) ]
||
Right [ ( ( "" , 1 , 1 ) , Symbol "||" ) ]
::
Right [ ( ( "" , 1 , 1 ) , Symbol "::" ) ]
..
Right [ ( ( "" , 1 , 1 ) , Symbol ".." ) ]
:=
Right [ ( ( "" , 1 , 1 ) , Symbol ":=" ) ]
a
Right [ ( ( "" , 1 , 1 ) , Identifier Nothing "a" ) ]
_a
Right [ ( ( "" , 1 , 1 ) , Identifier Nothing "_a" ) ]
test
Right [ ( ( "" , 1 , 1 ) , Identifier Nothing "test" ) ]
table
Right [ ( ( "" , 1 , 1 ) , Identifier Nothing "table" ) ]
Stuff
Right [ ( ( "" , 1 , 1 ) , Identifier Nothing "Stuff" ) ]
STUFF
Right [ ( ( "" , 1 , 1 ) , Identifier Nothing "STUFF" ) ]
"a"
Right
  [ ( ( "" , 1 , 1 ) , Identifier (Just ( "\"" , "\"" )) "a" ) ]
"_a"
Right
  [ ( ( "" , 1 , 1 ) , Identifier (Just ( "\"" , "\"" )) "_a" ) ]
"test"
Right
  [ ( ( "" , 1 , 1 ) , Identifier (Just ( "\"" , "\"" )) "test" ) ]
"table"
Right
  [ ( ( "" , 1 , 1 ) , Identifier (Just ( "\"" , "\"" )) "table" ) ]
"Stuff"
Right
  [ ( ( "" , 1 , 1 ) , Identifier (Just ( "\"" , "\"" )) "Stuff" ) ]
"STUFF"
Right
  [ ( ( "" , 1 , 1 ) , Identifier (Just ( "\"" , "\"" )) "STUFF" ) ]
u&"a"
Right
  [ ( ( "" , 1 , 1 ) , Identifier (Just ( "u&\"" , "\"" )) "a" ) ]
u&"_a"
Right
  [ ( ( "" , 1 , 1 ) , Identifier (Just ( "u&\"" , "\"" )) "_a" ) ]
u&"test"
Right
  [ ( ( "" , 1 , 1 ) , Identifier (Just ( "u&\"" , "\"" )) "test" ) ]
u&"table"
Right
  [ ( ( "" , 1 , 1 ) , Identifier (Just ( "u&\"" , "\"" )) "table" )
  ]
u&"Stuff"
Right
  [ ( ( "" , 1 , 1 ) , Identifier (Just ( "u&\"" , "\"" )) "Stuff" )
  ]
u&"STUFF"
Right
  [ ( ( "" , 1 , 1 ) , Identifier (Just ( "u&\"" , "\"" )) "STUFF" )
  ]
:a
Right [ ( ( "" , 1 , 1 ) , PrefixedVariable ':' "a" ) ]
:_a
Right [ ( ( "" , 1 , 1 ) , PrefixedVariable ':' "_a" ) ]
:test
Right [ ( ( "" , 1 , 1 ) , PrefixedVariable ':' "test" ) ]
:table
Right [ ( ( "" , 1 , 1 ) , PrefixedVariable ':' "table" ) ]
:Stuff
Right [ ( ( "" , 1 , 1 ) , PrefixedVariable ':' "Stuff" ) ]
:STUFF
Right [ ( ( "" , 1 , 1 ) , PrefixedVariable ':' "STUFF" ) ]
$1
Right [ ( ( "" , 1 , 1 ) , PositionalArg 1 ) ]
"normal "" iden"
Right
  [ ( ( "" , 1 , 1 )
    , Identifier (Just ( "\"" , "\"" )) "normal \"\" iden"
    )
  ]
'string'
Right [ ( ( "" , 1 , 1 ) , SqlString "'" "'" "string" ) ]
'normal '' quote'
Right [ ( ( "" , 1 , 1 ) , SqlString "'" "'" "normal '' quote" ) ]
'normalendquote '''
Right
  [ ( ( "" , 1 , 1 ) , SqlString "'" "'" "normalendquote ''" ) ]
'
'
Right [ ( ( "" , 1 , 1 ) , SqlString "'" "'" "\n" ) ]
E'
'
Right [ ( ( "" , 1 , 1 ) , SqlString "E'" "'" "\n" ) ]
e'this '' quote'
Right [ ( ( "" , 1 , 1 ) , SqlString "e'" "'" "this '' quote" ) ]
e'this \' quote'
Right [ ( ( "" , 1 , 1 ) , SqlString "e'" "'" "this \\' quote" ) ]
'not this \' quote
Right
  [ ( ( "" , 1 , 1 ) , SqlString "'" "'" "not this \\" )
  , ( ( "" , 1 , 13 ) , Whitespace " " )
  , ( ( "" , 1 , 14 ) , Identifier Nothing "quote" )
  ]
$$ string 1 $$
Right [ ( ( "" , 1 , 1 ) , SqlString "$$" "$$" " string 1 " ) ]
$$ string $ 2 $$
Right [ ( ( "" , 1 , 1 ) , SqlString "$$" "$$" " string $ 2 " ) ]
$a$ $$string 3$$ $a$
Right
  [ ( ( "" , 1 , 1 ) , SqlString "$a$" "$a$" " $$string 3$$ " ) ]
n'test'
Right [ ( ( "" , 1 , 1 ) , SqlString "n'" "'" "test" ) ]
N'test'
Right [ ( ( "" , 1 , 1 ) , SqlString "N'" "'" "test" ) ]
b'test'
Right [ ( ( "" , 1 , 1 ) , SqlString "b'" "'" "test" ) ]
B'test'
Right [ ( ( "" , 1 , 1 ) , SqlString "B'" "'" "test" ) ]
x'test'
Right [ ( ( "" , 1 , 1 ) , SqlString "x'" "'" "test" ) ]
X'test'
Right [ ( ( "" , 1 , 1 ) , SqlString "X'" "'" "test" ) ]
u&'test'
Right [ ( ( "" , 1 , 1 ) , SqlString "u&'" "'" "test" ) ]
e'test'
Right [ ( ( "" , 1 , 1 ) , SqlString "e'" "'" "test" ) ]
E'test'
Right [ ( ( "" , 1 , 1 ) , SqlString "E'" "'" "test" ) ]
10
Right [ ( ( "" , 1 , 1 ) , SqlNumber "10" ) ]
.1
Right [ ( ( "" , 1 , 1 ) , SqlNumber ".1" ) ]
5e3
Right [ ( ( "" , 1 , 1 ) , SqlNumber "5e3" ) ]
5e+3
Right [ ( ( "" , 1 , 1 ) , SqlNumber "5e+3" ) ]
5e-3
Right [ ( ( "" , 1 , 1 ) , SqlNumber "5e-3" ) ]
10.2
Right [ ( ( "" , 1 , 1 ) , SqlNumber "10.2" ) ]
10.2e7
Right [ ( ( "" , 1 , 1 ) , SqlNumber "10.2e7" ) ]
Right [ ( ( "" , 1 , 1 ) , Whitespace " " ) ]
Right [ ( ( "" , 1 , 1 ) , Whitespace "  " ) ]
Right [ ( ( "" , 1 , 1 ) , Whitespace " " ) ]
Right [ ( ( "" , 1 , 1 ) , Whitespace " \n" ) ]
Right [ ( ( "" , 1 , 1 ) , Whitespace " " ) ]
Right [ ( ( "" , 1 , 1 ) , Whitespace " \t" ) ]
Right [ ( ( "" , 1 , 1 ) , Whitespace "\n" ) ]
Right [ ( ( "" , 1 , 1 ) , Whitespace "\n " ) ]
Right [ ( ( "" , 1 , 1 ) , Whitespace "\n" ) ]
Right [ ( ( "" , 1 , 1 ) , Whitespace "\n\n" ) ]
Right [ ( ( "" , 1 , 1 ) , Whitespace "\n" ) ]
Right [ ( ( "" , 1 , 1 ) , Whitespace "\n\t" ) ]
Right [ ( ( "" , 1 , 1 ) , Whitespace "\t" ) ]
Right [ ( ( "" , 1 , 1 ) , Whitespace "\t " ) ]
Right [ ( ( "" , 1 , 1 ) , Whitespace "\t" ) ]
Right [ ( ( "" , 1 , 1 ) , Whitespace "\t\n" ) ]
Right [ ( ( "" , 1 , 1 ) , Whitespace "\t" ) ]
Right [ ( ( "" , 1 , 1 ) , Whitespace "\t\t" ) ]
--
Right [ ( ( "" , 1 , 1 ) , LineComment "--" ) ]
--
Right [ ( ( "" , 1 , 1 ) , LineComment "-- " ) ]
-- this is a comment
Right [ ( ( "" , 1 , 1 ) , LineComment "-- this is a comment" ) ]
-- line com
Right [ ( ( "" , 1 , 1 ) , LineComment "-- line com\n" ) ]
/**/
Right [ ( ( "" , 1 , 1 ) , BlockComment "/**/" ) ]
/* */
Right [ ( ( "" , 1 , 1 ) , BlockComment "/* */" ) ]
/* this is a comment */
Right
  [ ( ( "" , 1 , 1 ) , BlockComment "/* this is a comment */" ) ]
/* this *is/ a comment */
Right
  [ ( ( "" , 1 , 1 ) , BlockComment "/* this *is/ a comment */" ) ]
1.1.2.2. adhoc postgres lexertests
*/
Left
  ParseError
    { peErrorString =
        "(line 1, column 3):\ncomment end without comment start"
    , peFilename = ""
    , pePosition = ( 1 , 3 )
    , peFormattedError =
        ":1:3:\n*/\n  ^\n(line 1, column 3):\ncomment end without comment start"
    }
:::
Left
  ParseError
    { peErrorString = "(line 1, column 4):\nunexpected ':'"
    , peFilename = ""
    , pePosition = ( 1 , 4 )
    , peFormattedError =
        ":1:4:\n:::\n   ^\n(line 1, column 4):\nunexpected ':'"
    }
::::
Left
  ParseError
    { peErrorString = "(line 1, column 4):\nunexpected ':'"
    , peFilename = ""
    , pePosition = ( 1 , 4 )
    , peFormattedError =
        ":1:4:\n::::\n   ^\n(line 1, column 4):\nunexpected ':'"
    }
:::::
Left
  ParseError
    { peErrorString = "(line 1, column 4):\nunexpected ':'"
    , peFilename = ""
    , pePosition = ( 1 , 4 )
    , peFormattedError =
        ":1:4:\n:::::\n   ^\n(line 1, column 4):\nunexpected ':'"
    }
@*/
Left
  ParseError
    { peErrorString =
        "(line 1, column 4):\ncomment end without comment start"
    , peFilename = ""
    , pePosition = ( 1 , 4 )
    , peFormattedError =
        ":1:4:\n@*/\n   ^\n(line 1, column 4):\ncomment end without comment start"
    }
-*/
Left
  ParseError
    { peErrorString =
        "(line 1, column 4):\ncomment end without comment start"
    , peFilename = ""
    , pePosition = ( 1 , 4 )
    , peFormattedError =
        ":1:4:\n-*/\n   ^\n(line 1, column 4):\ncomment end without comment start"
    }
12e3e4
Left
  ParseError
    { peErrorString = "(line 1, column 6):\nunexpected 'e'"
    , peFilename = ""
    , pePosition = ( 1 , 6 )
    , peFormattedError =
        ":1:6:\n12e3e4\n     ^\n(line 1, column 6):\nunexpected 'e'"
    }
12e3e4
Left
  ParseError
    { peErrorString = "(line 1, column 6):\nunexpected 'e'"
    , peFilename = ""
    , pePosition = ( 1 , 6 )
    , peFormattedError =
        ":1:6:\n12e3e4\n     ^\n(line 1, column 6):\nunexpected 'e'"
    }
12e3e4
Left
  ParseError
    { peErrorString = "(line 1, column 6):\nunexpected 'e'"
    , peFilename = ""
    , pePosition = ( 1 , 6 )
    , peFormattedError =
        ":1:6:\n12e3e4\n     ^\n(line 1, column 6):\nunexpected 'e'"
    }
12e3.4
Left
  ParseError
    { peErrorString = "(line 1, column 6):\nunexpected '.'"
    , peFilename = ""
    , pePosition = ( 1 , 6 )
    , peFormattedError =
        ":1:6:\n12e3.4\n     ^\n(line 1, column 6):\nunexpected '.'"
    }
12.4.5
Left
  ParseError
    { peErrorString = "(line 1, column 6):\nunexpected '.'"
    , peFilename = ""
    , pePosition = ( 1 , 6 )
    , peFormattedError =
        ":1:6:\n12.4.5\n     ^\n(line 1, column 6):\nunexpected '.'"
    }
12.4e5.6
Left
  ParseError
    { peErrorString = "(line 1, column 8):\nunexpected '.'"
    , peFilename = ""
    , pePosition = ( 1 , 8 )
    , peFormattedError =
        ":1:8:\n12.4e5.6\n       ^\n(line 1, column 8):\nunexpected '.'"
    }
12.4e5e7
Left
  ParseError
    { peErrorString = "(line 1, column 8):\nunexpected 'e'"
    , peFilename = ""
    , pePosition = ( 1 , 8 )
    , peFormattedError =
        ":1:8:\n12.4e5e7\n       ^\n(line 1, column 8):\nunexpected 'e'"
    }
1..2
Right
  [ ( ( "" , 1 , 1 ) , SqlNumber "1" )
  , ( ( "" , 1 , 2 ) , Symbol ".." )
  , ( ( "" , 1 , 4 ) , SqlNumber "2" )
  ]

1.1.3. sqlServerLexTests

@variable
Right [ ( ( "" , 1 , 1 ) , PrefixedVariable '@' "variable" ) ]
#variable
Right [ ( ( "" , 1 , 1 ) , PrefixedVariable '#' "variable" ) ]
[quoted identifier]
Right
  [ ( ( "" , 1 , 1 )
    , Identifier (Just ( "[" , "]" )) "quoted identifier"
    )
  ]

1.1.4. oracleLexTests

1.1.5. mySqlLexerTests

`quoted identifier`
Right
  [ ( ( "" , 1 , 1 )
    , Identifier (Just ( "`" , "`" )) "quoted identifier"
    )
  ]

1.1.6. odbcLexTests

{}
Right
  [ ( ( "" , 1 , 1 ) , Symbol "{" )
  , ( ( "" , 1 , 2 ) , Symbol "}" )
  ]
{
Left
  ParseError
    { peErrorString =
        "(line 1, column 1):\nunexpected '{'\nexpecting \"n'\", \"N'\", \"b'\", \"B'\", \"x'\", \"X'\", \"u&'\", \"U&'\", \"'\", \"\\\"\", \"[\", \"--\", \"/*\", digit, \".\", \"*/\", \":\", \"@\", \"#\", \",\", \";\", \"(\", \")\", \"?\", \">=\", \"<=\", \"!=\", \"<>\", \"+\", \"-\", \"^\", \"*\", \"/\", \"%\", \"~\", \"&\", \"<\", \">\", \"=\", \"|\" or end of input"
    , peFilename = ""
    , pePosition = ( 1 , 1 )
    , peFormattedError =
        ":1:1:\n{\n^\n(line 1, column 1):\nunexpected '{'\nexpecting \"n'\", \"N'\", \"b'\", \"B'\", \"x'\", \"X'\", \"u&'\", \"U&'\", \"'\", \"\\\"\", \"[\", \"--\", \"/*\", digit, \".\", \"*/\", \":\", \"@\", \"#\", \",\", \";\", \"(\", \")\", \"?\", \">=\", \"<=\", \"!=\", \"<>\", \"+\", \"-\", \"^\", \"*\", \"/\", \"%\", \"~\", \"&\", \"<\", \">\", \"=\", \"|\" or end of input"
    }
}
Left
  ParseError
    { peErrorString =
        "(line 1, column 1):\nunexpected '}'\nexpecting \"n'\", \"N'\", \"b'\", \"B'\", \"x'\", \"X'\", \"u&'\", \"U&'\", \"'\", \"\\\"\", \"[\", \"--\", \"/*\", digit, \".\", \"*/\", \":\", \"@\", \"#\", \",\", \";\", \"(\", \")\", \"?\", \">=\", \"<=\", \"!=\", \"<>\", \"+\", \"-\", \"^\", \"*\", \"/\", \"%\", \"~\", \"&\", \"<\", \">\", \"=\", \"|\" or end of input"
    , peFilename = ""
    , pePosition = ( 1 , 1 )
    , peFormattedError =
        ":1:1:\n}\n^\n(line 1, column 1):\nunexpected '}'\nexpecting \"n'\", \"N'\", \"b'\", \"B'\", \"x'\", \"X'\", \"u&'\", \"U&'\", \"'\", \"\\\"\", \"[\", \"--\", \"/*\", digit, \".\", \"*/\", \":\", \"@\", \"#\", \",\", \";\", \"(\", \")\", \"?\", \">=\", \"<=\", \"!=\", \"<>\", \"+\", \"-\", \"^\", \"*\", \"/\", \"%\", \"~\", \"&\", \"<\", \">\", \"=\", \"|\" or end of input"
    }

2. scalarExprTests

2.1. literals

3
NumLit "3"
3.
NumLit "3."
3.3
NumLit "3.3"
.3
NumLit ".3"
3.e3
NumLit "3.e3"
3.3e3
NumLit "3.3e3"
.3e3
NumLit ".3e3"
3e3
NumLit "3e3"
3e+3
NumLit "3e+3"
3e-3
NumLit "3e-3"
'string'
StringLit "'" "'" "string"
'string with a '' quote'
StringLit "'" "'" "string with a '' quote"
'1'
StringLit "'" "'" "1"
interval '3' day
IntervalLit
  { ilSign = Nothing
  , ilLiteral = "3"
  , ilFrom = Itf "day" Nothing
  , ilTo = Nothing
  }
interval '3' day (3)
IntervalLit
  { ilSign = Nothing
  , ilLiteral = "3"
  , ilFrom = Itf "day" (Just ( 3 , Nothing ))
  , ilTo = Nothing
  }
interval '3 weeks'
TypedLit (TypeName [ Name Nothing "interval" ]) "3 weeks"

2.2. identifiers

iden1
Iden [ Name Nothing "iden1" ]
"quoted identifier"
Iden [ Name (Just ( "\"" , "\"" )) "quoted identifier" ]
"from"
Iden [ Name (Just ( "\"" , "\"" )) "from" ]

2.3. star

*
Star

2.4. parameter

?
Parameter
$13
PositionalArg 13

2.5. dot

t.a
Iden [ Name Nothing "t" , Name Nothing "a" ]
t.*
BinOp (Iden [ Name Nothing "t" ]) [ Name Nothing "." ] Star
a.b.c
Iden [ Name Nothing "a" , Name Nothing "b" , Name Nothing "c" ]
ROW(t.*,42)
App
  [ Name Nothing "ROW" ]
  [ BinOp (Iden [ Name Nothing "t" ]) [ Name Nothing "." ] Star
  , NumLit "42"
  ]

2.6. app

f()
App [ Name Nothing "f" ] []
f(a)
App [ Name Nothing "f" ] [ Iden [ Name Nothing "a" ] ]
f(a,b)
App
  [ Name Nothing "f" ]
  [ Iden [ Name Nothing "a" ] , Iden [ Name Nothing "b" ] ]

2.7. caseexp

case a when 1 then 2 end
Case
  { caseTest = Just (Iden [ Name Nothing "a" ])
  , caseWhens = [ ( [ NumLit "1" ] , NumLit "2" ) ]
  , caseElse = Nothing
  }
case a when 1 then 2 when 3 then 4 end
Case
  { caseTest = Just (Iden [ Name Nothing "a" ])
  , caseWhens =
      [ ( [ NumLit "1" ] , NumLit "2" )
      , ( [ NumLit "3" ] , NumLit "4" )
      ]
  , caseElse = Nothing
  }
case a when 1 then 2 when 3 then 4 else 5 end
Case
  { caseTest = Just (Iden [ Name Nothing "a" ])
  , caseWhens =
      [ ( [ NumLit "1" ] , NumLit "2" )
      , ( [ NumLit "3" ] , NumLit "4" )
      ]
  , caseElse = Just (NumLit "5")
  }
case when a=1 then 2 when a=3 then 4 else 5 end
Case
  { caseTest = Nothing
  , caseWhens =
      [ ( [ BinOp
              (Iden [ Name Nothing "a" ]) [ Name Nothing "=" ] (NumLit "1")
          ]
        , NumLit "2"
        )
      , ( [ BinOp
              (Iden [ Name Nothing "a" ]) [ Name Nothing "=" ] (NumLit "3")
          ]
        , NumLit "4"
        )
      ]
  , caseElse = Just (NumLit "5")
  }
case a when 1,2 then 10 when 3,4 then 20 end
Case
  { caseTest = Just (Iden [ Name Nothing "a" ])
  , caseWhens =
      [ ( [ NumLit "1" , NumLit "2" ] , NumLit "10" )
      , ( [ NumLit "3" , NumLit "4" ] , NumLit "20" )
      ]
  , caseElse = Nothing
  }

2.8. operators

2.8.1. binaryOperators

a + b
BinOp
  (Iden [ Name Nothing "a" ])
  [ Name Nothing "+" ]
  (Iden [ Name Nothing "b" ])
a + b * c
BinOp
  (Iden [ Name Nothing "a" ])
  [ Name Nothing "+" ]
  (BinOp
     (Iden [ Name Nothing "b" ])
     [ Name Nothing "*" ]
     (Iden [ Name Nothing "c" ]))
a * b + c
BinOp
  (BinOp
     (Iden [ Name Nothing "a" ])
     [ Name Nothing "*" ]
     (Iden [ Name Nothing "b" ]))
  [ Name Nothing "+" ]
  (Iden [ Name Nothing "c" ])

2.8.2. unaryOperators

not a
PrefixOp [ Name Nothing "not" ] (Iden [ Name Nothing "a" ])
not not a
PrefixOp
  [ Name Nothing "not" ]
  (PrefixOp [ Name Nothing "not" ] (Iden [ Name Nothing "a" ]))
+a
PrefixOp [ Name Nothing "+" ] (Iden [ Name Nothing "a" ])
-a
PrefixOp [ Name Nothing "-" ] (Iden [ Name Nothing "a" ])

2.8.3. operators

cast('1' as int)
Cast (StringLit "'" "'" "1") (TypeName [ Name Nothing "int" ])
int '3'
TypedLit (TypeName [ Name Nothing "int" ]) "3"
cast('1' as double precision)
Cast
  (StringLit "'" "'" "1")
  (TypeName [ Name Nothing "double precision" ])
cast('1' as float(8))
Cast
  (StringLit "'" "'" "1") (PrecTypeName [ Name Nothing "float" ] 8)
cast('1' as decimal(15,2))
Cast
  (StringLit "'" "'" "1")
  (PrecScaleTypeName [ Name Nothing "decimal" ] 15 2)
double precision '3'
TypedLit (TypeName [ Name Nothing "double precision" ]) "3"

2.8.4. unaryOperators

a in (1,2,3)
In
  True
  (Iden [ Name Nothing "a" ])
  (InList [ NumLit "1" , NumLit "2" , NumLit "3" ])
a is null
PostfixOp [ Name Nothing "is null" ] (Iden [ Name Nothing "a" ])
a is not null
PostfixOp
  [ Name Nothing "is not null" ] (Iden [ Name Nothing "a" ])
a is true
PostfixOp [ Name Nothing "is true" ] (Iden [ Name Nothing "a" ])
a is not true
PostfixOp
  [ Name Nothing "is not true" ] (Iden [ Name Nothing "a" ])
a is false
PostfixOp [ Name Nothing "is false" ] (Iden [ Name Nothing "a" ])
a is not false
PostfixOp
  [ Name Nothing "is not false" ] (Iden [ Name Nothing "a" ])
a is unknown
PostfixOp [ Name Nothing "is unknown" ] (Iden [ Name Nothing "a" ])
a is not unknown
PostfixOp
  [ Name Nothing "is not unknown" ] (Iden [ Name Nothing "a" ])
a is distinct from b
BinOp
  (Iden [ Name Nothing "a" ])
  [ Name Nothing "is distinct from" ]
  (Iden [ Name Nothing "b" ])
a is not distinct from b
BinOp
  (Iden [ Name Nothing "a" ])
  [ Name Nothing "is not distinct from" ]
  (Iden [ Name Nothing "b" ])
a like b
BinOp
  (Iden [ Name Nothing "a" ])
  [ Name Nothing "like" ]
  (Iden [ Name Nothing "b" ])
a not like b
BinOp
  (Iden [ Name Nothing "a" ])
  [ Name Nothing "not like" ]
  (Iden [ Name Nothing "b" ])
a is similar to b
BinOp
  (Iden [ Name Nothing "a" ])
  [ Name Nothing "is similar to" ]
  (Iden [ Name Nothing "b" ])
a is not similar to b
BinOp
  (Iden [ Name Nothing "a" ])
  [ Name Nothing "is not similar to" ]
  (Iden [ Name Nothing "b" ])
a overlaps b
BinOp
  (Iden [ Name Nothing "a" ])
  [ Name Nothing "overlaps" ]
  (Iden [ Name Nothing "b" ])
a between b and c
SpecialOp
  [ Name Nothing "between" ]
  [ Iden [ Name Nothing "a" ]
  , Iden [ Name Nothing "b" ]
  , Iden [ Name Nothing "c" ]
  ]
a not between b and c
SpecialOp
  [ Name Nothing "not between" ]
  [ Iden [ Name Nothing "a" ]
  , Iden [ Name Nothing "b" ]
  , Iden [ Name Nothing "c" ]
  ]
(1,2)
SpecialOp [ Name Nothing "rowctor" ] [ NumLit "1" , NumLit "2" ]
extract(day from t)
SpecialOpK
  [ Name Nothing "extract" ]
  (Just (Iden [ Name Nothing "day" ]))
  [ ( "from" , Iden [ Name Nothing "t" ] ) ]
substring(x from 1 for 2)
SpecialOpK
  [ Name Nothing "substring" ]
  (Just (Iden [ Name Nothing "x" ]))
  [ ( "from" , NumLit "1" ) , ( "for" , NumLit "2" ) ]
substring(x from 1)
SpecialOpK
  [ Name Nothing "substring" ]
  (Just (Iden [ Name Nothing "x" ]))
  [ ( "from" , NumLit "1" ) ]
substring(x for 2)
SpecialOpK
  [ Name Nothing "substring" ]
  (Just (Iden [ Name Nothing "x" ]))
  [ ( "for" , NumLit "2" ) ]
substring(x from 1 for 2 collate C)
SpecialOpK
  [ Name Nothing "substring" ]
  (Just (Iden [ Name Nothing "x" ]))
  [ ( "from" , NumLit "1" )
  , ( "for" , Collate (NumLit "2") [ Name Nothing "C" ] )
  ]
POSITION( string1 IN string2 )
SpecialOpK
  [ Name Nothing "position" ]
  (Just (Iden [ Name Nothing "string1" ]))
  [ ( "in" , Iden [ Name Nothing "string2" ] ) ]
CONVERT(char_value USING conversion_char_name)
SpecialOpK
  [ Name Nothing "convert" ]
  (Just (Iden [ Name Nothing "char_value" ]))
  [ ( "using" , Iden [ Name Nothing "conversion_char_name" ] ) ]
TRANSLATE(char_value USING translation_name)
SpecialOpK
  [ Name Nothing "translate" ]
  (Just (Iden [ Name Nothing "char_value" ]))
  [ ( "using" , Iden [ Name Nothing "translation_name" ] ) ]
OVERLAY(string PLACING embedded_string FROM start)
SpecialOpK
  [ Name Nothing "overlay" ]
  (Just (Iden [ Name Nothing "string" ]))
  [ ( "placing" , Iden [ Name Nothing "embedded_string" ] )
  , ( "from" , Iden [ Name Nothing "start" ] )
  ]
OVERLAY(string PLACING embedded_string FROM start FOR length)
SpecialOpK
  [ Name Nothing "overlay" ]
  (Just (Iden [ Name Nothing "string" ]))
  [ ( "placing" , Iden [ Name Nothing "embedded_string" ] )
  , ( "from" , Iden [ Name Nothing "start" ] )
  , ( "for" , Iden [ Name Nothing "length" ] )
  ]
trim(from target_string)
SpecialOpK
  [ Name Nothing "trim" ]
  Nothing
  [ ( "both" , StringLit "'" "'" " " )
  , ( "from" , Iden [ Name Nothing "target_string" ] )
  ]
trim(leading from target_string)
SpecialOpK
  [ Name Nothing "trim" ]
  Nothing
  [ ( "leading" , StringLit "'" "'" " " )
  , ( "from" , Iden [ Name Nothing "target_string" ] )
  ]
trim(trailing from target_string)
SpecialOpK
  [ Name Nothing "trim" ]
  Nothing
  [ ( "trailing" , StringLit "'" "'" " " )
  , ( "from" , Iden [ Name Nothing "target_string" ] )
  ]
trim(both from target_string)
SpecialOpK
  [ Name Nothing "trim" ]
  Nothing
  [ ( "both" , StringLit "'" "'" " " )
  , ( "from" , Iden [ Name Nothing "target_string" ] )
  ]
trim(leading 'x' from target_string)
SpecialOpK
  [ Name Nothing "trim" ]
  Nothing
  [ ( "leading" , StringLit "'" "'" "x" )
  , ( "from" , Iden [ Name Nothing "target_string" ] )
  ]
trim(trailing 'y' from target_string)
SpecialOpK
  [ Name Nothing "trim" ]
  Nothing
  [ ( "trailing" , StringLit "'" "'" "y" )
  , ( "from" , Iden [ Name Nothing "target_string" ] )
  ]
trim(both 'z' from target_string collate C)
SpecialOpK
  [ Name Nothing "trim" ]
  Nothing
  [ ( "both" , StringLit "'" "'" "z" )
  , ( "from"
    , Collate
        (Iden [ Name Nothing "target_string" ]) [ Name Nothing "C" ]
    )
  ]
trim(leading from target_string)
SpecialOpK
  [ Name Nothing "trim" ]
  Nothing
  [ ( "leading" , StringLit "'" "'" " " )
  , ( "from" , Iden [ Name Nothing "target_string" ] )
  ]

2.9. parens

(a)
Parens (Iden [ Name Nothing "a" ])
(a + b)
Parens
  (BinOp
     (Iden [ Name Nothing "a" ])
     [ Name Nothing "+" ]
     (Iden [ Name Nothing "b" ]))

2.10. unaryOperators

exists (select a from t)
SubQueryExpr
  SqExists
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
    , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
    , qeWhere = Nothing
    , qeGroupBy = []
    , qeHaving = Nothing
    , qeOrderBy = []
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
(select a from t)
SubQueryExpr
  SqSq
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
    , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
    , qeWhere = Nothing
    , qeGroupBy = []
    , qeHaving = Nothing
    , qeOrderBy = []
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
a in (select a from t)
In
  True
  (Iden [ Name Nothing "a" ])
  (InQueryExpr
     Select
       { qeSetQuantifier = SQDefault
       , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
       , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
       , qeWhere = Nothing
       , qeGroupBy = []
       , qeHaving = Nothing
       , qeOrderBy = []
       , qeOffset = Nothing
       , qeFetchFirst = Nothing
       })
a not in (select a from t)
In
  False
  (Iden [ Name Nothing "a" ])
  (InQueryExpr
     Select
       { qeSetQuantifier = SQDefault
       , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
       , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
       , qeWhere = Nothing
       , qeGroupBy = []
       , qeHaving = Nothing
       , qeOrderBy = []
       , qeOffset = Nothing
       , qeFetchFirst = Nothing
       })
a > all (select a from t)
QuantifiedComparison
  (Iden [ Name Nothing "a" ])
  [ Name Nothing ">" ]
  CPAll
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
    , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
    , qeWhere = Nothing
    , qeGroupBy = []
    , qeHaving = Nothing
    , qeOrderBy = []
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
a = some (select a from t)
QuantifiedComparison
  (Iden [ Name Nothing "a" ])
  [ Name Nothing "=" ]
  CPSome
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
    , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
    , qeWhere = Nothing
    , qeGroupBy = []
    , qeHaving = Nothing
    , qeOrderBy = []
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
a <= any (select a from t)
QuantifiedComparison
  (Iden [ Name Nothing "a" ])
  [ Name Nothing "<=" ]
  CPAny
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
    , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
    , qeWhere = Nothing
    , qeGroupBy = []
    , qeHaving = Nothing
    , qeOrderBy = []
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }

2.11. aggregates

count(*)
App [ Name Nothing "count" ] [ Star ]
sum(a order by a)
AggregateApp
  { aggName = [ Name Nothing "sum" ]
  , aggDistinct = SQDefault
  , aggArgs = [ Iden [ Name Nothing "a" ] ]
  , aggOrderBy =
      [ SortSpec (Iden [ Name Nothing "a" ]) DirDefault NullsOrderDefault
      ]
  , aggFilter = Nothing
  }
sum(all a)
AggregateApp
  { aggName = [ Name Nothing "sum" ]
  , aggDistinct = All
  , aggArgs = [ Iden [ Name Nothing "a" ] ]
  , aggOrderBy = []
  , aggFilter = Nothing
  }
count(distinct a)
AggregateApp
  { aggName = [ Name Nothing "count" ]
  , aggDistinct = Distinct
  , aggArgs = [ Iden [ Name Nothing "a" ] ]
  , aggOrderBy = []
  , aggFilter = Nothing
  }

2.12. windowFunctions

max(a) over ()
WindowApp
  { wnName = [ Name Nothing "max" ]
  , wnArgs = [ Iden [ Name Nothing "a" ] ]
  , wnPartition = []
  , wnOrderBy = []
  , wnFrame = Nothing
  }
count(*) over ()
WindowApp
  { wnName = [ Name Nothing "count" ]
  , wnArgs = [ Star ]
  , wnPartition = []
  , wnOrderBy = []
  , wnFrame = Nothing
  }
max(a) over (partition by b)
WindowApp
  { wnName = [ Name Nothing "max" ]
  , wnArgs = [ Iden [ Name Nothing "a" ] ]
  , wnPartition = [ Iden [ Name Nothing "b" ] ]
  , wnOrderBy = []
  , wnFrame = Nothing
  }
max(a) over (partition by b,c)
WindowApp
  { wnName = [ Name Nothing "max" ]
  , wnArgs = [ Iden [ Name Nothing "a" ] ]
  , wnPartition =
      [ Iden [ Name Nothing "b" ] , Iden [ Name Nothing "c" ] ]
  , wnOrderBy = []
  , wnFrame = Nothing
  }
sum(a) over (order by b)
WindowApp
  { wnName = [ Name Nothing "sum" ]
  , wnArgs = [ Iden [ Name Nothing "a" ] ]
  , wnPartition = []
  , wnOrderBy =
      [ SortSpec (Iden [ Name Nothing "b" ]) DirDefault NullsOrderDefault
      ]
  , wnFrame = Nothing
  }
sum(a) over (order by b desc,c)
WindowApp
  { wnName = [ Name Nothing "sum" ]
  , wnArgs = [ Iden [ Name Nothing "a" ] ]
  , wnPartition = []
  , wnOrderBy =
      [ SortSpec (Iden [ Name Nothing "b" ]) Desc NullsOrderDefault
      , SortSpec (Iden [ Name Nothing "c" ]) DirDefault NullsOrderDefault
      ]
  , wnFrame = Nothing
  }
sum(a) over (partition by b order by c)
WindowApp
  { wnName = [ Name Nothing "sum" ]
  , wnArgs = [ Iden [ Name Nothing "a" ] ]
  , wnPartition = [ Iden [ Name Nothing "b" ] ]
  , wnOrderBy =
      [ SortSpec (Iden [ Name Nothing "c" ]) DirDefault NullsOrderDefault
      ]
  , wnFrame = Nothing
  }
sum(a) over (partition by b order by c range unbounded preceding)
WindowApp
  { wnName = [ Name Nothing "sum" ]
  , wnArgs = [ Iden [ Name Nothing "a" ] ]
  , wnPartition = [ Iden [ Name Nothing "b" ] ]
  , wnOrderBy =
      [ SortSpec (Iden [ Name Nothing "c" ]) DirDefault NullsOrderDefault
      ]
  , wnFrame = Just (FrameFrom FrameRange UnboundedPreceding)
  }
sum(a) over (partition by b order by c range 5 preceding)
WindowApp
  { wnName = [ Name Nothing "sum" ]
  , wnArgs = [ Iden [ Name Nothing "a" ] ]
  , wnPartition = [ Iden [ Name Nothing "b" ] ]
  , wnOrderBy =
      [ SortSpec (Iden [ Name Nothing "c" ]) DirDefault NullsOrderDefault
      ]
  , wnFrame = Just (FrameFrom FrameRange (Preceding (NumLit "5")))
  }
sum(a) over (partition by b order by c range current row)
WindowApp
  { wnName = [ Name Nothing "sum" ]
  , wnArgs = [ Iden [ Name Nothing "a" ] ]
  , wnPartition = [ Iden [ Name Nothing "b" ] ]
  , wnOrderBy =
      [ SortSpec (Iden [ Name Nothing "c" ]) DirDefault NullsOrderDefault
      ]
  , wnFrame = Just (FrameFrom FrameRange Current)
  }
sum(a) over (partition by b order by c rows 5 following)
WindowApp
  { wnName = [ Name Nothing "sum" ]
  , wnArgs = [ Iden [ Name Nothing "a" ] ]
  , wnPartition = [ Iden [ Name Nothing "b" ] ]
  , wnOrderBy =
      [ SortSpec (Iden [ Name Nothing "c" ]) DirDefault NullsOrderDefault
      ]
  , wnFrame = Just (FrameFrom FrameRows (Following (NumLit "5")))
  }
sum(a) over (partition by b order by c range unbounded following)
WindowApp
  { wnName = [ Name Nothing "sum" ]
  , wnArgs = [ Iden [ Name Nothing "a" ] ]
  , wnPartition = [ Iden [ Name Nothing "b" ] ]
  , wnOrderBy =
      [ SortSpec (Iden [ Name Nothing "c" ]) DirDefault NullsOrderDefault
      ]
  , wnFrame = Just (FrameFrom FrameRange UnboundedFollowing)
  }
sum(a) over (partition by b order by c
range between 5 preceding and 5 following)
WindowApp
  { wnName = [ Name Nothing "sum" ]
  , wnArgs = [ Iden [ Name Nothing "a" ] ]
  , wnPartition = [ Iden [ Name Nothing "b" ] ]
  , wnOrderBy =
      [ SortSpec (Iden [ Name Nothing "c" ]) DirDefault NullsOrderDefault
      ]
  , wnFrame =
      Just
        (FrameBetween
           FrameRange (Preceding (NumLit "5")) (Following (NumLit "5")))
  }

2.13. functionsWithReservedNames

abs(a)
App [ Name Nothing "abs" ] [ Iden [ Name Nothing "a" ] ]
char_length(a)
App [ Name Nothing "char_length" ] [ Iden [ Name Nothing "a" ] ]

3. odbc

3.1. datetime

{d '2000-01-01'}
OdbcLiteral OLDate "2000-01-01"
{t '12:00:01.1'}
OdbcLiteral OLTime "12:00:01.1"
{ts '2000-01-01 12:00:01.1'}
OdbcLiteral OLTimestamp "2000-01-01 12:00:01.1"

3.2. functions

{fn CHARACTER_LENGTH(string_exp)}
OdbcFunc
  (App
     [ Name Nothing "CHARACTER_LENGTH" ]
     [ Iden [ Name Nothing "string_exp" ] ])
{fn EXTRACT(day from t)}
OdbcFunc
  (SpecialOpK
     [ Name Nothing "extract" ]
     (Just (Iden [ Name Nothing "day" ]))
     [ ( "from" , Iden [ Name Nothing "t" ] ) ])
{fn now()}
OdbcFunc (App [ Name Nothing "now" ] [])
{fn CONVERT('2000-01-01', SQL_DATE)}
OdbcFunc
  (App
     [ Name Nothing "CONVERT" ]
     [ StringLit "'" "'" "2000-01-01"
     , Iden [ Name Nothing "SQL_DATE" ]
     ])
{fn CONVERT({fn CURDATE()}, SQL_DATE)}
OdbcFunc
  (App
     [ Name Nothing "CONVERT" ]
     [ OdbcFunc (App [ Name Nothing "CURDATE" ] [])
     , Iden [ Name Nothing "SQL_DATE" ]
     ])

3.3. outer join

select * from {oj t1 left outer join t2 on expr}
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList = [ ( Star , Nothing ) ]
  , qeFrom =
      [ TROdbc
          (TRJoin
             (TRSimple [ Name Nothing "t1" ])
             False
             JLeft
             (TRSimple [ Name Nothing "t2" ])
             (Just (JoinOn (Iden [ Name Nothing "expr" ]))))
      ]
  , qeWhere = Nothing
  , qeGroupBy = []
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }

3.4. check parsing bugs

select {fn CONVERT(cint,SQL_BIGINT)} from t;
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList =
      [ ( OdbcFunc
            (App
               [ Name Nothing "CONVERT" ]
               [ Iden [ Name Nothing "cint" ]
               , Iden [ Name Nothing "SQL_BIGINT" ]
               ])
        , Nothing
        )
      ]
  , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
  , qeWhere = Nothing
  , qeGroupBy = []
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }

4. queryExprComponentTests

4.1. duplicates

select a from t
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
  , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
  , qeWhere = Nothing
  , qeGroupBy = []
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }
select all a from t
Select
  { qeSetQuantifier = All
  , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
  , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
  , qeWhere = Nothing
  , qeGroupBy = []
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }
select distinct a from t
Select
  { qeSetQuantifier = Distinct
  , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
  , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
  , qeWhere = Nothing
  , qeGroupBy = []
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }

4.2. selectLists

select 1
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList = [ ( NumLit "1" , Nothing ) ]
  , qeFrom = []
  , qeWhere = Nothing
  , qeGroupBy = []
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }
select a
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
  , qeFrom = []
  , qeWhere = Nothing
  , qeGroupBy = []
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }
select a,b
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList =
      [ ( Iden [ Name Nothing "a" ] , Nothing )
      , ( Iden [ Name Nothing "b" ] , Nothing )
      ]
  , qeFrom = []
  , qeWhere = Nothing
  , qeGroupBy = []
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }
select 1+2,3+4
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList =
      [ ( BinOp (NumLit "1") [ Name Nothing "+" ] (NumLit "2")
        , Nothing
        )
      , ( BinOp (NumLit "3") [ Name Nothing "+" ] (NumLit "4")
        , Nothing
        )
      ]
  , qeFrom = []
  , qeWhere = Nothing
  , qeGroupBy = []
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }
select a as a, /*comment*/ b as b
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList =
      [ ( Iden [ Name Nothing "a" ] , Just (Name Nothing "a") )
      , ( Iden [ Name Nothing "b" ] , Just (Name Nothing "b") )
      ]
  , qeFrom = []
  , qeWhere = Nothing
  , qeGroupBy = []
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }
select a a, b b
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList =
      [ ( Iden [ Name Nothing "a" ] , Just (Name Nothing "a") )
      , ( Iden [ Name Nothing "b" ] , Just (Name Nothing "b") )
      ]
  , qeFrom = []
  , qeWhere = Nothing
  , qeGroupBy = []
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }
select a + b * c
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList =
      [ ( BinOp
            (Iden [ Name Nothing "a" ])
            [ Name Nothing "+" ]
            (BinOp
               (Iden [ Name Nothing "b" ])
               [ Name Nothing "*" ]
               (Iden [ Name Nothing "c" ]))
        , Nothing
        )
      ]
  , qeFrom = []
  , qeWhere = Nothing
  , qeGroupBy = []
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }

4.3. whereClause

select a from t where a = 5
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
  , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
  , qeWhere =
      Just
        (BinOp
           (Iden [ Name Nothing "a" ]) [ Name Nothing "=" ] (NumLit "5"))
  , qeGroupBy = []
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }

4.4. having

select a,sum(b) from t group by a having sum(b) > 5
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList =
      [ ( Iden [ Name Nothing "a" ] , Nothing )
      , ( App [ Name Nothing "sum" ] [ Iden [ Name Nothing "b" ] ]
        , Nothing
        )
      ]
  , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
  , qeWhere = Nothing
  , qeGroupBy = [ SimpleGroup (Iden [ Name Nothing "a" ]) ]
  , qeHaving =
      Just
        (BinOp
           (App [ Name Nothing "sum" ] [ Iden [ Name Nothing "b" ] ])
           [ Name Nothing ">" ]
           (NumLit "5"))
  , qeOrderBy = []
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }

4.5. orderBy

select a from t order by a
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
  , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
  , qeWhere = Nothing
  , qeGroupBy = []
  , qeHaving = Nothing
  , qeOrderBy =
      [ SortSpec (Iden [ Name Nothing "a" ]) DirDefault NullsOrderDefault
      ]
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }
select a from t order by a, b
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
  , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
  , qeWhere = Nothing
  , qeGroupBy = []
  , qeHaving = Nothing
  , qeOrderBy =
      [ SortSpec (Iden [ Name Nothing "a" ]) DirDefault NullsOrderDefault
      , SortSpec (Iden [ Name Nothing "b" ]) DirDefault NullsOrderDefault
      ]
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }
select a from t order by a asc
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
  , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
  , qeWhere = Nothing
  , qeGroupBy = []
  , qeHaving = Nothing
  , qeOrderBy =
      [ SortSpec (Iden [ Name Nothing "a" ]) Asc NullsOrderDefault ]
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }
select a from t order by a desc, b desc
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
  , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
  , qeWhere = Nothing
  , qeGroupBy = []
  , qeHaving = Nothing
  , qeOrderBy =
      [ SortSpec (Iden [ Name Nothing "a" ]) Desc NullsOrderDefault
      , SortSpec (Iden [ Name Nothing "b" ]) Desc NullsOrderDefault
      ]
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }
select a from t order by a desc nulls first, b desc nulls last
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
  , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
  , qeWhere = Nothing
  , qeGroupBy = []
  , qeHaving = Nothing
  , qeOrderBy =
      [ SortSpec (Iden [ Name Nothing "a" ]) Desc NullsFirst
      , SortSpec (Iden [ Name Nothing "b" ]) Desc NullsLast
      ]
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }

4.6. offsetFetch

select a from t offset 5 rows fetch next 10 rows only
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
  , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
  , qeWhere = Nothing
  , qeGroupBy = []
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Just (NumLit "5")
  , qeFetchFirst = Just (NumLit "10")
  }
select a from t offset 5 rows;
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
  , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
  , qeWhere = Nothing
  , qeGroupBy = []
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Just (NumLit "5")
  , qeFetchFirst = Nothing
  }
select a from t fetch next 10 row only;
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
  , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
  , qeWhere = Nothing
  , qeGroupBy = []
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Nothing
  , qeFetchFirst = Just (NumLit "10")
  }
select a from t offset 5 row fetch first 10 row only
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
  , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
  , qeWhere = Nothing
  , qeGroupBy = []
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Just (NumLit "5")
  , qeFetchFirst = Just (NumLit "10")
  }

4.7. combos

select a from t union select b from u
QueryExprSetOp
  { qe0 =
      Select
        { qeSetQuantifier = SQDefault
        , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
        , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
        , qeWhere = Nothing
        , qeGroupBy = []
        , qeHaving = Nothing
        , qeOrderBy = []
        , qeOffset = Nothing
        , qeFetchFirst = Nothing
        }
  , qeCombOp = Union
  , qeSetQuantifier = SQDefault
  , qeCorresponding = Respectively
  , qe1 =
      Select
        { qeSetQuantifier = SQDefault
        , qeSelectList = [ ( Iden [ Name Nothing "b" ] , Nothing ) ]
        , qeFrom = [ TRSimple [ Name Nothing "u" ] ]
        , qeWhere = Nothing
        , qeGroupBy = []
        , qeHaving = Nothing
        , qeOrderBy = []
        , qeOffset = Nothing
        , qeFetchFirst = Nothing
        }
  }
select a from t intersect select b from u
QueryExprSetOp
  { qe0 =
      Select
        { qeSetQuantifier = SQDefault
        , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
        , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
        , qeWhere = Nothing
        , qeGroupBy = []
        , qeHaving = Nothing
        , qeOrderBy = []
        , qeOffset = Nothing
        , qeFetchFirst = Nothing
        }
  , qeCombOp = Intersect
  , qeSetQuantifier = SQDefault
  , qeCorresponding = Respectively
  , qe1 =
      Select
        { qeSetQuantifier = SQDefault
        , qeSelectList = [ ( Iden [ Name Nothing "b" ] , Nothing ) ]
        , qeFrom = [ TRSimple [ Name Nothing "u" ] ]
        , qeWhere = Nothing
        , qeGroupBy = []
        , qeHaving = Nothing
        , qeOrderBy = []
        , qeOffset = Nothing
        , qeFetchFirst = Nothing
        }
  }
select a from t except all select b from u
QueryExprSetOp
  { qe0 =
      Select
        { qeSetQuantifier = SQDefault
        , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
        , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
        , qeWhere = Nothing
        , qeGroupBy = []
        , qeHaving = Nothing
        , qeOrderBy = []
        , qeOffset = Nothing
        , qeFetchFirst = Nothing
        }
  , qeCombOp = Except
  , qeSetQuantifier = All
  , qeCorresponding = Respectively
  , qe1 =
      Select
        { qeSetQuantifier = SQDefault
        , qeSelectList = [ ( Iden [ Name Nothing "b" ] , Nothing ) ]
        , qeFrom = [ TRSimple [ Name Nothing "u" ] ]
        , qeWhere = Nothing
        , qeGroupBy = []
        , qeHaving = Nothing
        , qeOrderBy = []
        , qeOffset = Nothing
        , qeFetchFirst = Nothing
        }
  }
select a from t union distinct corresponding select b from u
QueryExprSetOp
  { qe0 =
      Select
        { qeSetQuantifier = SQDefault
        , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
        , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
        , qeWhere = Nothing
        , qeGroupBy = []
        , qeHaving = Nothing
        , qeOrderBy = []
        , qeOffset = Nothing
        , qeFetchFirst = Nothing
        }
  , qeCombOp = Union
  , qeSetQuantifier = Distinct
  , qeCorresponding = Corresponding
  , qe1 =
      Select
        { qeSetQuantifier = SQDefault
        , qeSelectList = [ ( Iden [ Name Nothing "b" ] , Nothing ) ]
        , qeFrom = [ TRSimple [ Name Nothing "u" ] ]
        , qeWhere = Nothing
        , qeGroupBy = []
        , qeHaving = Nothing
        , qeOrderBy = []
        , qeOffset = Nothing
        , qeFetchFirst = Nothing
        }
  }
select a from t union select a from t union select a from t
QueryExprSetOp
  { qe0 =
      Select
        { qeSetQuantifier = SQDefault
        , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
        , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
        , qeWhere = Nothing
        , qeGroupBy = []
        , qeHaving = Nothing
        , qeOrderBy = []
        , qeOffset = Nothing
        , qeFetchFirst = Nothing
        }
  , qeCombOp = Union
  , qeSetQuantifier = SQDefault
  , qeCorresponding = Respectively
  , qe1 =
      QueryExprSetOp
        { qe0 =
            Select
              { qeSetQuantifier = SQDefault
              , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
              , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
              , qeWhere = Nothing
              , qeGroupBy = []
              , qeHaving = Nothing
              , qeOrderBy = []
              , qeOffset = Nothing
              , qeFetchFirst = Nothing
              }
        , qeCombOp = Union
        , qeSetQuantifier = SQDefault
        , qeCorresponding = Respectively
        , qe1 =
            Select
              { qeSetQuantifier = SQDefault
              , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
              , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
              , qeWhere = Nothing
              , qeGroupBy = []
              , qeHaving = Nothing
              , qeOrderBy = []
              , qeOffset = Nothing
              , qeFetchFirst = Nothing
              }
        }
  }

4.8. with queries

with u as (select a from t) select a from u
With
  { qeWithRecursive = False
  , qeViews =
      [ ( Alias (Name Nothing "u") Nothing
        , Select
            { qeSetQuantifier = SQDefault
            , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
            , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
            , qeWhere = Nothing
            , qeGroupBy = []
            , qeHaving = Nothing
            , qeOrderBy = []
            , qeOffset = Nothing
            , qeFetchFirst = Nothing
            }
        )
      ]
  , qeQueryExpression =
      Select
        { qeSetQuantifier = SQDefault
        , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
        , qeFrom = [ TRSimple [ Name Nothing "u" ] ]
        , qeWhere = Nothing
        , qeGroupBy = []
        , qeHaving = Nothing
        , qeOrderBy = []
        , qeOffset = Nothing
        , qeFetchFirst = Nothing
        }
  }
with u(b) as (select a from t) select a from u
With
  { qeWithRecursive = False
  , qeViews =
      [ ( Alias (Name Nothing "u") (Just [ Name Nothing "b" ])
        , Select
            { qeSetQuantifier = SQDefault
            , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
            , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
            , qeWhere = Nothing
            , qeGroupBy = []
            , qeHaving = Nothing
            , qeOrderBy = []
            , qeOffset = Nothing
            , qeFetchFirst = Nothing
            }
        )
      ]
  , qeQueryExpression =
      Select
        { qeSetQuantifier = SQDefault
        , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
        , qeFrom = [ TRSimple [ Name Nothing "u" ] ]
        , qeWhere = Nothing
        , qeGroupBy = []
        , qeHaving = Nothing
        , qeOrderBy = []
        , qeOffset = Nothing
        , qeFetchFirst = Nothing
        }
  }
with x as (select a from t),
     u as (select a from x)
select a from u
With
  { qeWithRecursive = False
  , qeViews =
      [ ( Alias (Name Nothing "x") Nothing
        , Select
            { qeSetQuantifier = SQDefault
            , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
            , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
            , qeWhere = Nothing
            , qeGroupBy = []
            , qeHaving = Nothing
            , qeOrderBy = []
            , qeOffset = Nothing
            , qeFetchFirst = Nothing
            }
        )
      , ( Alias (Name Nothing "u") Nothing
        , Select
            { qeSetQuantifier = SQDefault
            , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
            , qeFrom = [ TRSimple [ Name Nothing "x" ] ]
            , qeWhere = Nothing
            , qeGroupBy = []
            , qeHaving = Nothing
            , qeOrderBy = []
            , qeOffset = Nothing
            , qeFetchFirst = Nothing
            }
        )
      ]
  , qeQueryExpression =
      Select
        { qeSetQuantifier = SQDefault
        , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
        , qeFrom = [ TRSimple [ Name Nothing "u" ] ]
        , qeWhere = Nothing
        , qeGroupBy = []
        , qeHaving = Nothing
        , qeOrderBy = []
        , qeOffset = Nothing
        , qeFetchFirst = Nothing
        }
  }
with recursive u as (select a from t) select a from u
With
  { qeWithRecursive = True
  , qeViews =
      [ ( Alias (Name Nothing "u") Nothing
        , Select
            { qeSetQuantifier = SQDefault
            , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
            , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
            , qeWhere = Nothing
            , qeGroupBy = []
            , qeHaving = Nothing
            , qeOrderBy = []
            , qeOffset = Nothing
            , qeFetchFirst = Nothing
            }
        )
      ]
  , qeQueryExpression =
      Select
        { qeSetQuantifier = SQDefault
        , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
        , qeFrom = [ TRSimple [ Name Nothing "u" ] ]
        , qeWhere = Nothing
        , qeGroupBy = []
        , qeHaving = Nothing
        , qeOrderBy = []
        , qeOffset = Nothing
        , qeFetchFirst = Nothing
        }
  }

4.9. values

values (1,2),(3,4)
Values
  [ [ NumLit "1" , NumLit "2" ] , [ NumLit "3" , NumLit "4" ] ]

4.10. tables

table tbl
Table [ Name Nothing "tbl" ]

5. query exprs

select 1
[ SelectStatement
    Select
      { qeSetQuantifier = SQDefault
      , qeSelectList = [ ( NumLit "1" , Nothing ) ]
      , qeFrom = []
      , qeWhere = Nothing
      , qeGroupBy = []
      , qeHaving = Nothing
      , qeOrderBy = []
      , qeOffset = Nothing
      , qeFetchFirst = Nothing
      }
]
select 1;
[ SelectStatement
    Select
      { qeSetQuantifier = SQDefault
      , qeSelectList = [ ( NumLit "1" , Nothing ) ]
      , qeFrom = []
      , qeWhere = Nothing
      , qeGroupBy = []
      , qeHaving = Nothing
      , qeOrderBy = []
      , qeOffset = Nothing
      , qeFetchFirst = Nothing
      }
]
select 1;select 1
[ SelectStatement
    Select
      { qeSetQuantifier = SQDefault
      , qeSelectList = [ ( NumLit "1" , Nothing ) ]
      , qeFrom = []
      , qeWhere = Nothing
      , qeGroupBy = []
      , qeHaving = Nothing
      , qeOrderBy = []
      , qeOffset = Nothing
      , qeFetchFirst = Nothing
      }
, SelectStatement
    Select
      { qeSetQuantifier = SQDefault
      , qeSelectList = [ ( NumLit "1" , Nothing ) ]
      , qeFrom = []
      , qeWhere = Nothing
      , qeGroupBy = []
      , qeHaving = Nothing
      , qeOrderBy = []
      , qeOffset = Nothing
      , qeFetchFirst = Nothing
      }
]
 select 1;select 1;
[ SelectStatement
    Select
      { qeSetQuantifier = SQDefault
      , qeSelectList = [ ( NumLit "1" , Nothing ) ]
      , qeFrom = []
      , qeWhere = Nothing
      , qeGroupBy = []
      , qeHaving = Nothing
      , qeOrderBy = []
      , qeOffset = Nothing
      , qeFetchFirst = Nothing
      }
, SelectStatement
    Select
      { qeSetQuantifier = SQDefault
      , qeSelectList = [ ( NumLit "1" , Nothing ) ]
      , qeFrom = []
      , qeWhere = Nothing
      , qeGroupBy = []
      , qeHaving = Nothing
      , qeOrderBy = []
      , qeOffset = Nothing
      , qeFetchFirst = Nothing
      }
]
SELECT CURRENT_TIMESTAMP;
[ SelectStatement
    Select
      { qeSetQuantifier = SQDefault
      , qeSelectList =
          [ ( Iden [ Name Nothing "CURRENT_TIMESTAMP" ] , Nothing ) ]
      , qeFrom = []
      , qeWhere = Nothing
      , qeGroupBy = []
      , qeHaving = Nothing
      , qeOrderBy = []
      , qeOffset = Nothing
      , qeFetchFirst = Nothing
      }
]
SELECT "CURRENT_TIMESTAMP";
[ SelectStatement
    Select
      { qeSetQuantifier = SQDefault
      , qeSelectList =
          [ ( Iden [ Name (Just ( "\"" , "\"" )) "CURRENT_TIMESTAMP" ]
            , Nothing
            )
          ]
      , qeFrom = []
      , qeWhere = Nothing
      , qeGroupBy = []
      , qeHaving = Nothing
      , qeOrderBy = []
      , qeOffset = Nothing
      , qeFetchFirst = Nothing
      }
]

6. tableRefTests

select a from t
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
  , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
  , qeWhere = Nothing
  , qeGroupBy = []
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }
select a from f(a)
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
  , qeFrom =
      [ TRFunction [ Name Nothing "f" ] [ Iden [ Name Nothing "a" ] ] ]
  , qeWhere = Nothing
  , qeGroupBy = []
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }
select a from t,u
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
  , qeFrom =
      [ TRSimple [ Name Nothing "t" ] , TRSimple [ Name Nothing "u" ] ]
  , qeWhere = Nothing
  , qeGroupBy = []
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }
select a from s.t
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
  , qeFrom = [ TRSimple [ Name Nothing "s" , Name Nothing "t" ] ]
  , qeWhere = Nothing
  , qeGroupBy = []
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }
select a from lateral a
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
  , qeFrom = [ TRLateral (TRSimple [ Name Nothing "a" ]) ]
  , qeWhere = Nothing
  , qeGroupBy = []
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }
select a from lateral a,b
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
  , qeFrom =
      [ TRLateral (TRSimple [ Name Nothing "a" ])
      , TRSimple [ Name Nothing "b" ]
      ]
  , qeWhere = Nothing
  , qeGroupBy = []
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }
select a from a, lateral b
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
  , qeFrom =
      [ TRSimple [ Name Nothing "a" ]
      , TRLateral (TRSimple [ Name Nothing "b" ])
      ]
  , qeWhere = Nothing
  , qeGroupBy = []
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }
select a from a natural join lateral b
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
  , qeFrom =
      [ TRJoin
          (TRSimple [ Name Nothing "a" ])
          True
          JInner
          (TRLateral (TRSimple [ Name Nothing "b" ]))
          Nothing
      ]
  , qeWhere = Nothing
  , qeGroupBy = []
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }
select a from lateral a natural join lateral b
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
  , qeFrom =
      [ TRJoin
          (TRLateral (TRSimple [ Name Nothing "a" ]))
          True
          JInner
          (TRLateral (TRSimple [ Name Nothing "b" ]))
          Nothing
      ]
  , qeWhere = Nothing
  , qeGroupBy = []
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }
select a from t inner join u on expr
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
  , qeFrom =
      [ TRJoin
          (TRSimple [ Name Nothing "t" ])
          False
          JInner
          (TRSimple [ Name Nothing "u" ])
          (Just (JoinOn (Iden [ Name Nothing "expr" ])))
      ]
  , qeWhere = Nothing
  , qeGroupBy = []
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }
select a from t join u on expr
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
  , qeFrom =
      [ TRJoin
          (TRSimple [ Name Nothing "t" ])
          False
          JInner
          (TRSimple [ Name Nothing "u" ])
          (Just (JoinOn (Iden [ Name Nothing "expr" ])))
      ]
  , qeWhere = Nothing
  , qeGroupBy = []
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }
select a from t left join u on expr
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
  , qeFrom =
      [ TRJoin
          (TRSimple [ Name Nothing "t" ])
          False
          JLeft
          (TRSimple [ Name Nothing "u" ])
          (Just (JoinOn (Iden [ Name Nothing "expr" ])))
      ]
  , qeWhere = Nothing
  , qeGroupBy = []
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }
select a from t right join u on expr
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
  , qeFrom =
      [ TRJoin
          (TRSimple [ Name Nothing "t" ])
          False
          JRight
          (TRSimple [ Name Nothing "u" ])
          (Just (JoinOn (Iden [ Name Nothing "expr" ])))
      ]
  , qeWhere = Nothing
  , qeGroupBy = []
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }
select a from t full join u on expr
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
  , qeFrom =
      [ TRJoin
          (TRSimple [ Name Nothing "t" ])
          False
          JFull
          (TRSimple [ Name Nothing "u" ])
          (Just (JoinOn (Iden [ Name Nothing "expr" ])))
      ]
  , qeWhere = Nothing
  , qeGroupBy = []
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }
select a from t cross join u
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
  , qeFrom =
      [ TRJoin
          (TRSimple [ Name Nothing "t" ])
          False
          JCross
          (TRSimple [ Name Nothing "u" ])
          Nothing
      ]
  , qeWhere = Nothing
  , qeGroupBy = []
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }
select a from t natural inner join u
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
  , qeFrom =
      [ TRJoin
          (TRSimple [ Name Nothing "t" ])
          True
          JInner
          (TRSimple [ Name Nothing "u" ])
          Nothing
      ]
  , qeWhere = Nothing
  , qeGroupBy = []
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }
select a from t inner join u using(a,b)
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
  , qeFrom =
      [ TRJoin
          (TRSimple [ Name Nothing "t" ])
          False
          JInner
          (TRSimple [ Name Nothing "u" ])
          (Just (JoinUsing [ Name Nothing "a" , Name Nothing "b" ]))
      ]
  , qeWhere = Nothing
  , qeGroupBy = []
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }
select a from (select a from t)
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
  , qeFrom =
      [ TRQueryExpr
          Select
            { qeSetQuantifier = SQDefault
            , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
            , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
            , qeWhere = Nothing
            , qeGroupBy = []
            , qeHaving = Nothing
            , qeOrderBy = []
            , qeOffset = Nothing
            , qeFetchFirst = Nothing
            }
      ]
  , qeWhere = Nothing
  , qeGroupBy = []
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }
select a from t as u
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
  , qeFrom =
      [ TRAlias
          (TRSimple [ Name Nothing "t" ]) (Alias (Name Nothing "u") Nothing)
      ]
  , qeWhere = Nothing
  , qeGroupBy = []
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }
select a from t u
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
  , qeFrom =
      [ TRAlias
          (TRSimple [ Name Nothing "t" ]) (Alias (Name Nothing "u") Nothing)
      ]
  , qeWhere = Nothing
  , qeGroupBy = []
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }
select a from t u(b)
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
  , qeFrom =
      [ TRAlias
          (TRSimple [ Name Nothing "t" ])
          (Alias (Name Nothing "u") (Just [ Name Nothing "b" ]))
      ]
  , qeWhere = Nothing
  , qeGroupBy = []
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }
select a from (t cross join u) as u
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
  , qeFrom =
      [ TRAlias
          (TRParens
             (TRJoin
                (TRSimple [ Name Nothing "t" ])
                False
                JCross
                (TRSimple [ Name Nothing "u" ])
                Nothing))
          (Alias (Name Nothing "u") Nothing)
      ]
  , qeWhere = Nothing
  , qeGroupBy = []
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }
select a from t cross join u cross join v
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList = [ ( Iden [ Name Nothing "a" ] , Nothing ) ]
  , qeFrom =
      [ TRJoin
          (TRJoin
             (TRSimple [ Name Nothing "t" ])
             False
             JCross
             (TRSimple [ Name Nothing "u" ])
             Nothing)
          False
          JCross
          (TRSimple [ Name Nothing "v" ])
          Nothing
      ]
  , qeWhere = Nothing
  , qeGroupBy = []
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }

7. groupByTests

7.1. simpleGroupBy

select a,sum(b) from t group by a
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList =
      [ ( Iden [ Name Nothing "a" ] , Nothing )
      , ( App [ Name Nothing "sum" ] [ Iden [ Name Nothing "b" ] ]
        , Nothing
        )
      ]
  , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
  , qeWhere = Nothing
  , qeGroupBy = [ SimpleGroup (Iden [ Name Nothing "a" ]) ]
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }
select a,b,sum(c) from t group by a,b
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList =
      [ ( Iden [ Name Nothing "a" ] , Nothing )
      , ( Iden [ Name Nothing "b" ] , Nothing )
      , ( App [ Name Nothing "sum" ] [ Iden [ Name Nothing "c" ] ]
        , Nothing
        )
      ]
  , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
  , qeWhere = Nothing
  , qeGroupBy =
      [ SimpleGroup (Iden [ Name Nothing "a" ])
      , SimpleGroup (Iden [ Name Nothing "b" ])
      ]
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }

7.2. newGroupBy

select * from t group by ()
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList = [ ( Star , Nothing ) ]
  , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
  , qeWhere = Nothing
  , qeGroupBy = [ GroupingParens [] ]
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }
select * from t group by grouping sets ((), (a))
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList = [ ( Star , Nothing ) ]
  , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
  , qeWhere = Nothing
  , qeGroupBy =
      [ GroupingSets
          [ GroupingParens []
          , GroupingParens [ SimpleGroup (Iden [ Name Nothing "a" ]) ]
          ]
      ]
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }
select * from t group by cube(a,b)
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList = [ ( Star , Nothing ) ]
  , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
  , qeWhere = Nothing
  , qeGroupBy =
      [ Cube
          [ SimpleGroup (Iden [ Name Nothing "a" ])
          , SimpleGroup (Iden [ Name Nothing "b" ])
          ]
      ]
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }
select * from t group by rollup(a,b)
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList = [ ( Star , Nothing ) ]
  , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
  , qeWhere = Nothing
  , qeGroupBy =
      [ Rollup
          [ SimpleGroup (Iden [ Name Nothing "a" ])
          , SimpleGroup (Iden [ Name Nothing "b" ])
          ]
      ]
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }

7.3. randomGroupBy

select * from t GROUP BY a
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList = [ ( Star , Nothing ) ]
    , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
    , qeWhere = Nothing
    , qeGroupBy = [ SimpleGroup (Iden [ Name Nothing "a" ]) ]
    , qeHaving = Nothing
    , qeOrderBy = []
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
select * from t GROUP BY GROUPING SETS((a))
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList = [ ( Star , Nothing ) ]
    , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
    , qeWhere = Nothing
    , qeGroupBy =
        [ GroupingSets
            [ GroupingParens [ SimpleGroup (Iden [ Name Nothing "a" ]) ] ]
        ]
    , qeHaving = Nothing
    , qeOrderBy = []
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
select * from t GROUP BY a,b,c
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList = [ ( Star , Nothing ) ]
    , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
    , qeWhere = Nothing
    , qeGroupBy =
        [ SimpleGroup (Iden [ Name Nothing "a" ])
        , SimpleGroup (Iden [ Name Nothing "b" ])
        , SimpleGroup (Iden [ Name Nothing "c" ])
        ]
    , qeHaving = Nothing
    , qeOrderBy = []
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
select * from t GROUP BY GROUPING SETS((a,b,c))
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList = [ ( Star , Nothing ) ]
    , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
    , qeWhere = Nothing
    , qeGroupBy =
        [ GroupingSets
            [ GroupingParens
                [ SimpleGroup (Iden [ Name Nothing "a" ])
                , SimpleGroup (Iden [ Name Nothing "b" ])
                , SimpleGroup (Iden [ Name Nothing "c" ])
                ]
            ]
        ]
    , qeHaving = Nothing
    , qeOrderBy = []
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
select * from t GROUP BY ROLLUP(a,b)
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList = [ ( Star , Nothing ) ]
    , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
    , qeWhere = Nothing
    , qeGroupBy =
        [ Rollup
            [ SimpleGroup (Iden [ Name Nothing "a" ])
            , SimpleGroup (Iden [ Name Nothing "b" ])
            ]
        ]
    , qeHaving = Nothing
    , qeOrderBy = []
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
select * from t GROUP BY GROUPING SETS((a,b),
(a),
() )
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList = [ ( Star , Nothing ) ]
    , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
    , qeWhere = Nothing
    , qeGroupBy =
        [ GroupingSets
            [ GroupingParens
                [ SimpleGroup (Iden [ Name Nothing "a" ])
                , SimpleGroup (Iden [ Name Nothing "b" ])
                ]
            , GroupingParens [ SimpleGroup (Iden [ Name Nothing "a" ]) ]
            , GroupingParens []
            ]
        ]
    , qeHaving = Nothing
    , qeOrderBy = []
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
select * from t GROUP BY ROLLUP(b,a)
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList = [ ( Star , Nothing ) ]
    , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
    , qeWhere = Nothing
    , qeGroupBy =
        [ Rollup
            [ SimpleGroup (Iden [ Name Nothing "b" ])
            , SimpleGroup (Iden [ Name Nothing "a" ])
            ]
        ]
    , qeHaving = Nothing
    , qeOrderBy = []
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
select * from t GROUP BY GROUPING SETS((b,a),
(b),
() )
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList = [ ( Star , Nothing ) ]
    , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
    , qeWhere = Nothing
    , qeGroupBy =
        [ GroupingSets
            [ GroupingParens
                [ SimpleGroup (Iden [ Name Nothing "b" ])
                , SimpleGroup (Iden [ Name Nothing "a" ])
                ]
            , GroupingParens [ SimpleGroup (Iden [ Name Nothing "b" ]) ]
            , GroupingParens []
            ]
        ]
    , qeHaving = Nothing
    , qeOrderBy = []
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
select * from t GROUP BY CUBE(a,b,c)
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList = [ ( Star , Nothing ) ]
    , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
    , qeWhere = Nothing
    , qeGroupBy =
        [ Cube
            [ SimpleGroup (Iden [ Name Nothing "a" ])
            , SimpleGroup (Iden [ Name Nothing "b" ])
            , SimpleGroup (Iden [ Name Nothing "c" ])
            ]
        ]
    , qeHaving = Nothing
    , qeOrderBy = []
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
select * from t GROUP BY GROUPING SETS((a,b,c),
(a,b),
(a,c),
(b,c),
(a),
(b),
(c),
() )
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList = [ ( Star , Nothing ) ]
    , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
    , qeWhere = Nothing
    , qeGroupBy =
        [ GroupingSets
            [ GroupingParens
                [ SimpleGroup (Iden [ Name Nothing "a" ])
                , SimpleGroup (Iden [ Name Nothing "b" ])
                , SimpleGroup (Iden [ Name Nothing "c" ])
                ]
            , GroupingParens
                [ SimpleGroup (Iden [ Name Nothing "a" ])
                , SimpleGroup (Iden [ Name Nothing "b" ])
                ]
            , GroupingParens
                [ SimpleGroup (Iden [ Name Nothing "a" ])
                , SimpleGroup (Iden [ Name Nothing "c" ])
                ]
            , GroupingParens
                [ SimpleGroup (Iden [ Name Nothing "b" ])
                , SimpleGroup (Iden [ Name Nothing "c" ])
                ]
            , GroupingParens [ SimpleGroup (Iden [ Name Nothing "a" ]) ]
            , GroupingParens [ SimpleGroup (Iden [ Name Nothing "b" ]) ]
            , GroupingParens [ SimpleGroup (Iden [ Name Nothing "c" ]) ]
            , GroupingParens []
            ]
        ]
    , qeHaving = Nothing
    , qeOrderBy = []
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
select * from t GROUP BY ROLLUP(Province, County, City)
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList = [ ( Star , Nothing ) ]
    , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
    , qeWhere = Nothing
    , qeGroupBy =
        [ Rollup
            [ SimpleGroup (Iden [ Name Nothing "Province" ])
            , SimpleGroup (Iden [ Name Nothing "County" ])
            , SimpleGroup (Iden [ Name Nothing "City" ])
            ]
        ]
    , qeHaving = Nothing
    , qeOrderBy = []
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
select * from t GROUP BY ROLLUP(Province, (County, City))
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList = [ ( Star , Nothing ) ]
    , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
    , qeWhere = Nothing
    , qeGroupBy =
        [ Rollup
            [ SimpleGroup (Iden [ Name Nothing "Province" ])
            , GroupingParens
                [ SimpleGroup (Iden [ Name Nothing "County" ])
                , SimpleGroup (Iden [ Name Nothing "City" ])
                ]
            ]
        ]
    , qeHaving = Nothing
    , qeOrderBy = []
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
select * from t GROUP BY ROLLUP(Province, (County, City))
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList = [ ( Star , Nothing ) ]
    , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
    , qeWhere = Nothing
    , qeGroupBy =
        [ Rollup
            [ SimpleGroup (Iden [ Name Nothing "Province" ])
            , GroupingParens
                [ SimpleGroup (Iden [ Name Nothing "County" ])
                , SimpleGroup (Iden [ Name Nothing "City" ])
                ]
            ]
        ]
    , qeHaving = Nothing
    , qeOrderBy = []
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
select * from t GROUP BY GROUPING SETS((Province, County, City),
(Province),
() )
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList = [ ( Star , Nothing ) ]
    , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
    , qeWhere = Nothing
    , qeGroupBy =
        [ GroupingSets
            [ GroupingParens
                [ SimpleGroup (Iden [ Name Nothing "Province" ])
                , SimpleGroup (Iden [ Name Nothing "County" ])
                , SimpleGroup (Iden [ Name Nothing "City" ])
                ]
            , GroupingParens [ SimpleGroup (Iden [ Name Nothing "Province" ]) ]
            , GroupingParens []
            ]
        ]
    , qeHaving = Nothing
    , qeOrderBy = []
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
select * from t GROUP BY GROUPING SETS((Province, County, City),
(Province, County),
(Province),
() )
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList = [ ( Star , Nothing ) ]
    , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
    , qeWhere = Nothing
    , qeGroupBy =
        [ GroupingSets
            [ GroupingParens
                [ SimpleGroup (Iden [ Name Nothing "Province" ])
                , SimpleGroup (Iden [ Name Nothing "County" ])
                , SimpleGroup (Iden [ Name Nothing "City" ])
                ]
            , GroupingParens
                [ SimpleGroup (Iden [ Name Nothing "Province" ])
                , SimpleGroup (Iden [ Name Nothing "County" ])
                ]
            , GroupingParens [ SimpleGroup (Iden [ Name Nothing "Province" ]) ]
            , GroupingParens []
            ]
        ]
    , qeHaving = Nothing
    , qeOrderBy = []
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
select * from t GROUP BY a, ROLLUP(b,c)
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList = [ ( Star , Nothing ) ]
    , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
    , qeWhere = Nothing
    , qeGroupBy =
        [ SimpleGroup (Iden [ Name Nothing "a" ])
        , Rollup
            [ SimpleGroup (Iden [ Name Nothing "b" ])
            , SimpleGroup (Iden [ Name Nothing "c" ])
            ]
        ]
    , qeHaving = Nothing
    , qeOrderBy = []
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
select * from t GROUP BY GROUPING SETS((a,b,c),
(a,b),
(a) )
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList = [ ( Star , Nothing ) ]
    , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
    , qeWhere = Nothing
    , qeGroupBy =
        [ GroupingSets
            [ GroupingParens
                [ SimpleGroup (Iden [ Name Nothing "a" ])
                , SimpleGroup (Iden [ Name Nothing "b" ])
                , SimpleGroup (Iden [ Name Nothing "c" ])
                ]
            , GroupingParens
                [ SimpleGroup (Iden [ Name Nothing "a" ])
                , SimpleGroup (Iden [ Name Nothing "b" ])
                ]
            , GroupingParens [ SimpleGroup (Iden [ Name Nothing "a" ]) ]
            ]
        ]
    , qeHaving = Nothing
    , qeOrderBy = []
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
select * from t GROUP BY a, b, ROLLUP(c,d)
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList = [ ( Star , Nothing ) ]
    , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
    , qeWhere = Nothing
    , qeGroupBy =
        [ SimpleGroup (Iden [ Name Nothing "a" ])
        , SimpleGroup (Iden [ Name Nothing "b" ])
        , Rollup
            [ SimpleGroup (Iden [ Name Nothing "c" ])
            , SimpleGroup (Iden [ Name Nothing "d" ])
            ]
        ]
    , qeHaving = Nothing
    , qeOrderBy = []
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
select * from t GROUP BY GROUPING SETS((a,b,c,d),
(a,b,c),
(a,b) )
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList = [ ( Star , Nothing ) ]
    , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
    , qeWhere = Nothing
    , qeGroupBy =
        [ GroupingSets
            [ GroupingParens
                [ SimpleGroup (Iden [ Name Nothing "a" ])
                , SimpleGroup (Iden [ Name Nothing "b" ])
                , SimpleGroup (Iden [ Name Nothing "c" ])
                , SimpleGroup (Iden [ Name Nothing "d" ])
                ]
            , GroupingParens
                [ SimpleGroup (Iden [ Name Nothing "a" ])
                , SimpleGroup (Iden [ Name Nothing "b" ])
                , SimpleGroup (Iden [ Name Nothing "c" ])
                ]
            , GroupingParens
                [ SimpleGroup (Iden [ Name Nothing "a" ])
                , SimpleGroup (Iden [ Name Nothing "b" ])
                ]
            ]
        ]
    , qeHaving = Nothing
    , qeOrderBy = []
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
select * from t GROUP BY ROLLUP(a), ROLLUP(b,c)
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList = [ ( Star , Nothing ) ]
    , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
    , qeWhere = Nothing
    , qeGroupBy =
        [ Rollup [ SimpleGroup (Iden [ Name Nothing "a" ]) ]
        , Rollup
            [ SimpleGroup (Iden [ Name Nothing "b" ])
            , SimpleGroup (Iden [ Name Nothing "c" ])
            ]
        ]
    , qeHaving = Nothing
    , qeOrderBy = []
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
select * from t GROUP BY GROUPING SETS((a,b,c),
(a,b),
(a),
(b,c),
(b),
() )
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList = [ ( Star , Nothing ) ]
    , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
    , qeWhere = Nothing
    , qeGroupBy =
        [ GroupingSets
            [ GroupingParens
                [ SimpleGroup (Iden [ Name Nothing "a" ])
                , SimpleGroup (Iden [ Name Nothing "b" ])
                , SimpleGroup (Iden [ Name Nothing "c" ])
                ]
            , GroupingParens
                [ SimpleGroup (Iden [ Name Nothing "a" ])
                , SimpleGroup (Iden [ Name Nothing "b" ])
                ]
            , GroupingParens [ SimpleGroup (Iden [ Name Nothing "a" ]) ]
            , GroupingParens
                [ SimpleGroup (Iden [ Name Nothing "b" ])
                , SimpleGroup (Iden [ Name Nothing "c" ])
                ]
            , GroupingParens [ SimpleGroup (Iden [ Name Nothing "b" ]) ]
            , GroupingParens []
            ]
        ]
    , qeHaving = Nothing
    , qeOrderBy = []
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
select * from t GROUP BY ROLLUP(a), CUBE(b,c)
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList = [ ( Star , Nothing ) ]
    , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
    , qeWhere = Nothing
    , qeGroupBy =
        [ Rollup [ SimpleGroup (Iden [ Name Nothing "a" ]) ]
        , Cube
            [ SimpleGroup (Iden [ Name Nothing "b" ])
            , SimpleGroup (Iden [ Name Nothing "c" ])
            ]
        ]
    , qeHaving = Nothing
    , qeOrderBy = []
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
select * from t GROUP BY GROUPING SETS((a,b,c),
(a,b),
(a,c),
(a),
(b,c),
(b),
(c),
() )
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList = [ ( Star , Nothing ) ]
    , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
    , qeWhere = Nothing
    , qeGroupBy =
        [ GroupingSets
            [ GroupingParens
                [ SimpleGroup (Iden [ Name Nothing "a" ])
                , SimpleGroup (Iden [ Name Nothing "b" ])
                , SimpleGroup (Iden [ Name Nothing "c" ])
                ]
            , GroupingParens
                [ SimpleGroup (Iden [ Name Nothing "a" ])
                , SimpleGroup (Iden [ Name Nothing "b" ])
                ]
            , GroupingParens
                [ SimpleGroup (Iden [ Name Nothing "a" ])
                , SimpleGroup (Iden [ Name Nothing "c" ])
                ]
            , GroupingParens [ SimpleGroup (Iden [ Name Nothing "a" ]) ]
            , GroupingParens
                [ SimpleGroup (Iden [ Name Nothing "b" ])
                , SimpleGroup (Iden [ Name Nothing "c" ])
                ]
            , GroupingParens [ SimpleGroup (Iden [ Name Nothing "b" ]) ]
            , GroupingParens [ SimpleGroup (Iden [ Name Nothing "c" ]) ]
            , GroupingParens []
            ]
        ]
    , qeHaving = Nothing
    , qeOrderBy = []
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
select * from t GROUP BY CUBE(a,b), ROLLUP(c,d)
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList = [ ( Star , Nothing ) ]
    , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
    , qeWhere = Nothing
    , qeGroupBy =
        [ Cube
            [ SimpleGroup (Iden [ Name Nothing "a" ])
            , SimpleGroup (Iden [ Name Nothing "b" ])
            ]
        , Rollup
            [ SimpleGroup (Iden [ Name Nothing "c" ])
            , SimpleGroup (Iden [ Name Nothing "d" ])
            ]
        ]
    , qeHaving = Nothing
    , qeOrderBy = []
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
select * from t GROUP BY GROUPING SETS((a,b,c,d),
(a,b,c),
(a,b),
(a,c,d),
(a,c),
(a),
(b,c,d),
(b,c),
(b),
(c,d),
(c),
() )
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList = [ ( Star , Nothing ) ]
    , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
    , qeWhere = Nothing
    , qeGroupBy =
        [ GroupingSets
            [ GroupingParens
                [ SimpleGroup (Iden [ Name Nothing "a" ])
                , SimpleGroup (Iden [ Name Nothing "b" ])
                , SimpleGroup (Iden [ Name Nothing "c" ])
                , SimpleGroup (Iden [ Name Nothing "d" ])
                ]
            , GroupingParens
                [ SimpleGroup (Iden [ Name Nothing "a" ])
                , SimpleGroup (Iden [ Name Nothing "b" ])
                , SimpleGroup (Iden [ Name Nothing "c" ])
                ]
            , GroupingParens
                [ SimpleGroup (Iden [ Name Nothing "a" ])
                , SimpleGroup (Iden [ Name Nothing "b" ])
                ]
            , GroupingParens
                [ SimpleGroup (Iden [ Name Nothing "a" ])
                , SimpleGroup (Iden [ Name Nothing "c" ])
                , SimpleGroup (Iden [ Name Nothing "d" ])
                ]
            , GroupingParens
                [ SimpleGroup (Iden [ Name Nothing "a" ])
                , SimpleGroup (Iden [ Name Nothing "c" ])
                ]
            , GroupingParens [ SimpleGroup (Iden [ Name Nothing "a" ]) ]
            , GroupingParens
                [ SimpleGroup (Iden [ Name Nothing "b" ])
                , SimpleGroup (Iden [ Name Nothing "c" ])
                , SimpleGroup (Iden [ Name Nothing "d" ])
                ]
            , GroupingParens
                [ SimpleGroup (Iden [ Name Nothing "b" ])
                , SimpleGroup (Iden [ Name Nothing "c" ])
                ]
            , GroupingParens [ SimpleGroup (Iden [ Name Nothing "b" ]) ]
            , GroupingParens
                [ SimpleGroup (Iden [ Name Nothing "c" ])
                , SimpleGroup (Iden [ Name Nothing "d" ])
                ]
            , GroupingParens [ SimpleGroup (Iden [ Name Nothing "c" ]) ]
            , GroupingParens []
            ]
        ]
    , qeHaving = Nothing
    , qeOrderBy = []
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
select * from t GROUP BY a, ROLLUP(a,b)
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList = [ ( Star , Nothing ) ]
    , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
    , qeWhere = Nothing
    , qeGroupBy =
        [ SimpleGroup (Iden [ Name Nothing "a" ])
        , Rollup
            [ SimpleGroup (Iden [ Name Nothing "a" ])
            , SimpleGroup (Iden [ Name Nothing "b" ])
            ]
        ]
    , qeHaving = Nothing
    , qeOrderBy = []
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
select * from t GROUP BY GROUPING SETS((a,b),
(a) )
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList = [ ( Star , Nothing ) ]
    , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
    , qeWhere = Nothing
    , qeGroupBy =
        [ GroupingSets
            [ GroupingParens
                [ SimpleGroup (Iden [ Name Nothing "a" ])
                , SimpleGroup (Iden [ Name Nothing "b" ])
                ]
            , GroupingParens [ SimpleGroup (Iden [ Name Nothing "a" ]) ]
            ]
        ]
    , qeHaving = Nothing
    , qeOrderBy = []
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
select * from t GROUP BY Region,
ROLLUP(Sales_Person, WEEK(Sales_Date)),
CUBE(YEAR(Sales_Date), MONTH (Sales_Date))
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList = [ ( Star , Nothing ) ]
    , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
    , qeWhere = Nothing
    , qeGroupBy =
        [ SimpleGroup (Iden [ Name Nothing "Region" ])
        , Rollup
            [ SimpleGroup (Iden [ Name Nothing "Sales_Person" ])
            , SimpleGroup
                (App
                   [ Name Nothing "WEEK" ] [ Iden [ Name Nothing "Sales_Date" ] ])
            ]
        , Cube
            [ SimpleGroup
                (App
                   [ Name Nothing "YEAR" ] [ Iden [ Name Nothing "Sales_Date" ] ])
            , SimpleGroup
                (App
                   [ Name Nothing "MONTH" ] [ Iden [ Name Nothing "Sales_Date" ] ])
            ]
        ]
    , qeHaving = Nothing
    , qeOrderBy = []
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
select * from t GROUP BY ROLLUP (Region, Sales_Person, WEEK(Sales_Date),
YEAR(Sales_Date), MONTH(Sales_Date) )
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList = [ ( Star , Nothing ) ]
    , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
    , qeWhere = Nothing
    , qeGroupBy =
        [ Rollup
            [ SimpleGroup (Iden [ Name Nothing "Region" ])
            , SimpleGroup (Iden [ Name Nothing "Sales_Person" ])
            , SimpleGroup
                (App
                   [ Name Nothing "WEEK" ] [ Iden [ Name Nothing "Sales_Date" ] ])
            , SimpleGroup
                (App
                   [ Name Nothing "YEAR" ] [ Iden [ Name Nothing "Sales_Date" ] ])
            , SimpleGroup
                (App
                   [ Name Nothing "MONTH" ] [ Iden [ Name Nothing "Sales_Date" ] ])
            ]
        ]
    , qeHaving = Nothing
    , qeOrderBy = []
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
SELECT WEEK(SALES_DATE) AS WEEK,
DAYOFWEEK(SALES_DATE) AS DAY_WEEK,
SALES_PERSON, SUM(SALES) AS UNITS_SOLD
FROM SALES
WHERE WEEK(SALES_DATE) = 13
GROUP BY WEEK(SALES_DATE), DAYOFWEEK(SALES_DATE), SALES_PERSON
ORDER BY WEEK, DAY_WEEK, SALES_PERSON
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList =
        [ ( App
              [ Name Nothing "WEEK" ] [ Iden [ Name Nothing "SALES_DATE" ] ]
          , Just (Name Nothing "WEEK")
          )
        , ( App
              [ Name Nothing "DAYOFWEEK" ] [ Iden [ Name Nothing "SALES_DATE" ] ]
          , Just (Name Nothing "DAY_WEEK")
          )
        , ( Iden [ Name Nothing "SALES_PERSON" ] , Nothing )
        , ( App [ Name Nothing "SUM" ] [ Iden [ Name Nothing "SALES" ] ]
          , Just (Name Nothing "UNITS_SOLD")
          )
        ]
    , qeFrom = [ TRSimple [ Name Nothing "SALES" ] ]
    , qeWhere =
        Just
          (BinOp
             (App
                [ Name Nothing "WEEK" ] [ Iden [ Name Nothing "SALES_DATE" ] ])
             [ Name Nothing "=" ]
             (NumLit "13"))
    , qeGroupBy =
        [ SimpleGroup
            (App
               [ Name Nothing "WEEK" ] [ Iden [ Name Nothing "SALES_DATE" ] ])
        , SimpleGroup
            (App
               [ Name Nothing "DAYOFWEEK" ]
               [ Iden [ Name Nothing "SALES_DATE" ] ])
        , SimpleGroup (Iden [ Name Nothing "SALES_PERSON" ])
        ]
    , qeHaving = Nothing
    , qeOrderBy =
        [ SortSpec
            (Iden [ Name Nothing "WEEK" ]) DirDefault NullsOrderDefault
        , SortSpec
            (Iden [ Name Nothing "DAY_WEEK" ]) DirDefault NullsOrderDefault
        , SortSpec
            (Iden [ Name Nothing "SALES_PERSON" ]) DirDefault NullsOrderDefault
        ]
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
SELECT WEEK(SALES_DATE) AS WEEK,
DAYOFWEEK(SALES_DATE) AS DAY_WEEK,
SALES_PERSON, SUM(SALES) AS UNITS_SOLD
FROM SALES
WHERE WEEK(SALES_DATE) = 13
GROUP BY GROUPING SETS ( (WEEK(SALES_DATE), SALES_PERSON),
(DAYOFWEEK(SALES_DATE), SALES_PERSON))
ORDER BY WEEK, DAY_WEEK, SALES_PERSON
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList =
        [ ( App
              [ Name Nothing "WEEK" ] [ Iden [ Name Nothing "SALES_DATE" ] ]
          , Just (Name Nothing "WEEK")
          )
        , ( App
              [ Name Nothing "DAYOFWEEK" ] [ Iden [ Name Nothing "SALES_DATE" ] ]
          , Just (Name Nothing "DAY_WEEK")
          )
        , ( Iden [ Name Nothing "SALES_PERSON" ] , Nothing )
        , ( App [ Name Nothing "SUM" ] [ Iden [ Name Nothing "SALES" ] ]
          , Just (Name Nothing "UNITS_SOLD")
          )
        ]
    , qeFrom = [ TRSimple [ Name Nothing "SALES" ] ]
    , qeWhere =
        Just
          (BinOp
             (App
                [ Name Nothing "WEEK" ] [ Iden [ Name Nothing "SALES_DATE" ] ])
             [ Name Nothing "=" ]
             (NumLit "13"))
    , qeGroupBy =
        [ GroupingSets
            [ GroupingParens
                [ SimpleGroup
                    (App
                       [ Name Nothing "WEEK" ] [ Iden [ Name Nothing "SALES_DATE" ] ])
                , SimpleGroup (Iden [ Name Nothing "SALES_PERSON" ])
                ]
            , GroupingParens
                [ SimpleGroup
                    (App
                       [ Name Nothing "DAYOFWEEK" ]
                       [ Iden [ Name Nothing "SALES_DATE" ] ])
                , SimpleGroup (Iden [ Name Nothing "SALES_PERSON" ])
                ]
            ]
        ]
    , qeHaving = Nothing
    , qeOrderBy =
        [ SortSpec
            (Iden [ Name Nothing "WEEK" ]) DirDefault NullsOrderDefault
        , SortSpec
            (Iden [ Name Nothing "DAY_WEEK" ]) DirDefault NullsOrderDefault
        , SortSpec
            (Iden [ Name Nothing "SALES_PERSON" ]) DirDefault NullsOrderDefault
        ]
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
SELECT WEEK(SALES_DATE) AS WEEK,
DAYOFWEEK(SALES_DATE) AS DAY_WEEK,
SALES_PERSON, SUM(SALES) AS UNITS_SOLD
FROM SALES
WHERE WEEK(SALES_DATE) = 13
GROUP BY ROLLUP ( WEEK(SALES_DATE), DAYOFWEEK(SALES_DATE), SALES_PERSON )
ORDER BY WEEK, DAY_WEEK, SALES_PERSON
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList =
        [ ( App
              [ Name Nothing "WEEK" ] [ Iden [ Name Nothing "SALES_DATE" ] ]
          , Just (Name Nothing "WEEK")
          )
        , ( App
              [ Name Nothing "DAYOFWEEK" ] [ Iden [ Name Nothing "SALES_DATE" ] ]
          , Just (Name Nothing "DAY_WEEK")
          )
        , ( Iden [ Name Nothing "SALES_PERSON" ] , Nothing )
        , ( App [ Name Nothing "SUM" ] [ Iden [ Name Nothing "SALES" ] ]
          , Just (Name Nothing "UNITS_SOLD")
          )
        ]
    , qeFrom = [ TRSimple [ Name Nothing "SALES" ] ]
    , qeWhere =
        Just
          (BinOp
             (App
                [ Name Nothing "WEEK" ] [ Iden [ Name Nothing "SALES_DATE" ] ])
             [ Name Nothing "=" ]
             (NumLit "13"))
    , qeGroupBy =
        [ Rollup
            [ SimpleGroup
                (App
                   [ Name Nothing "WEEK" ] [ Iden [ Name Nothing "SALES_DATE" ] ])
            , SimpleGroup
                (App
                   [ Name Nothing "DAYOFWEEK" ]
                   [ Iden [ Name Nothing "SALES_DATE" ] ])
            , SimpleGroup (Iden [ Name Nothing "SALES_PERSON" ])
            ]
        ]
    , qeHaving = Nothing
    , qeOrderBy =
        [ SortSpec
            (Iden [ Name Nothing "WEEK" ]) DirDefault NullsOrderDefault
        , SortSpec
            (Iden [ Name Nothing "DAY_WEEK" ]) DirDefault NullsOrderDefault
        , SortSpec
            (Iden [ Name Nothing "SALES_PERSON" ]) DirDefault NullsOrderDefault
        ]
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
SELECT WEEK(SALES_DATE) AS WEEK,
DAYOFWEEK(SALES_DATE) AS DAY_WEEK,
SALES_PERSON, SUM(SALES) AS UNITS_SOLD
FROM SALES
WHERE WEEK(SALES_DATE) = 13
GROUP BY CUBE ( WEEK(SALES_DATE), DAYOFWEEK(SALES_DATE), SALES_PERSON )
ORDER BY WEEK, DAY_WEEK, SALES_PERSON
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList =
        [ ( App
              [ Name Nothing "WEEK" ] [ Iden [ Name Nothing "SALES_DATE" ] ]
          , Just (Name Nothing "WEEK")
          )
        , ( App
              [ Name Nothing "DAYOFWEEK" ] [ Iden [ Name Nothing "SALES_DATE" ] ]
          , Just (Name Nothing "DAY_WEEK")
          )
        , ( Iden [ Name Nothing "SALES_PERSON" ] , Nothing )
        , ( App [ Name Nothing "SUM" ] [ Iden [ Name Nothing "SALES" ] ]
          , Just (Name Nothing "UNITS_SOLD")
          )
        ]
    , qeFrom = [ TRSimple [ Name Nothing "SALES" ] ]
    , qeWhere =
        Just
          (BinOp
             (App
                [ Name Nothing "WEEK" ] [ Iden [ Name Nothing "SALES_DATE" ] ])
             [ Name Nothing "=" ]
             (NumLit "13"))
    , qeGroupBy =
        [ Cube
            [ SimpleGroup
                (App
                   [ Name Nothing "WEEK" ] [ Iden [ Name Nothing "SALES_DATE" ] ])
            , SimpleGroup
                (App
                   [ Name Nothing "DAYOFWEEK" ]
                   [ Iden [ Name Nothing "SALES_DATE" ] ])
            , SimpleGroup (Iden [ Name Nothing "SALES_PERSON" ])
            ]
        ]
    , qeHaving = Nothing
    , qeOrderBy =
        [ SortSpec
            (Iden [ Name Nothing "WEEK" ]) DirDefault NullsOrderDefault
        , SortSpec
            (Iden [ Name Nothing "DAY_WEEK" ]) DirDefault NullsOrderDefault
        , SortSpec
            (Iden [ Name Nothing "SALES_PERSON" ]) DirDefault NullsOrderDefault
        ]
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
SELECT SALES_PERSON,
MONTH(SALES_DATE) AS MONTH,
SUM(SALES) AS UNITS_SOLD
FROM SALES
GROUP BY GROUPING SETS ( (SALES_PERSON, MONTH(SALES_DATE)),
()
)
ORDER BY SALES_PERSON, MONTH
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList =
        [ ( Iden [ Name Nothing "SALES_PERSON" ] , Nothing )
        , ( App
              [ Name Nothing "MONTH" ] [ Iden [ Name Nothing "SALES_DATE" ] ]
          , Just (Name Nothing "MONTH")
          )
        , ( App [ Name Nothing "SUM" ] [ Iden [ Name Nothing "SALES" ] ]
          , Just (Name Nothing "UNITS_SOLD")
          )
        ]
    , qeFrom = [ TRSimple [ Name Nothing "SALES" ] ]
    , qeWhere = Nothing
    , qeGroupBy =
        [ GroupingSets
            [ GroupingParens
                [ SimpleGroup (Iden [ Name Nothing "SALES_PERSON" ])
                , SimpleGroup
                    (App
                       [ Name Nothing "MONTH" ] [ Iden [ Name Nothing "SALES_DATE" ] ])
                ]
            , GroupingParens []
            ]
        ]
    , qeHaving = Nothing
    , qeOrderBy =
        [ SortSpec
            (Iden [ Name Nothing "SALES_PERSON" ]) DirDefault NullsOrderDefault
        , SortSpec
            (Iden [ Name Nothing "MONTH" ]) DirDefault NullsOrderDefault
        ]
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
SELECT WEEK(SALES_DATE) AS WEEK,
DAYOFWEEK(SALES_DATE) AS DAY_WEEK,
SUM(SALES) AS UNITS_SOLD
FROM SALES
GROUP BY ROLLUP ( WEEK(SALES_DATE), DAYOFWEEK(SALES_DATE) )
ORDER BY WEEK, DAY_WEEK
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList =
        [ ( App
              [ Name Nothing "WEEK" ] [ Iden [ Name Nothing "SALES_DATE" ] ]
          , Just (Name Nothing "WEEK")
          )
        , ( App
              [ Name Nothing "DAYOFWEEK" ] [ Iden [ Name Nothing "SALES_DATE" ] ]
          , Just (Name Nothing "DAY_WEEK")
          )
        , ( App [ Name Nothing "SUM" ] [ Iden [ Name Nothing "SALES" ] ]
          , Just (Name Nothing "UNITS_SOLD")
          )
        ]
    , qeFrom = [ TRSimple [ Name Nothing "SALES" ] ]
    , qeWhere = Nothing
    , qeGroupBy =
        [ Rollup
            [ SimpleGroup
                (App
                   [ Name Nothing "WEEK" ] [ Iden [ Name Nothing "SALES_DATE" ] ])
            , SimpleGroup
                (App
                   [ Name Nothing "DAYOFWEEK" ]
                   [ Iden [ Name Nothing "SALES_DATE" ] ])
            ]
        ]
    , qeHaving = Nothing
    , qeOrderBy =
        [ SortSpec
            (Iden [ Name Nothing "WEEK" ]) DirDefault NullsOrderDefault
        , SortSpec
            (Iden [ Name Nothing "DAY_WEEK" ]) DirDefault NullsOrderDefault
        ]
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
SELECT MONTH(SALES_DATE) AS MONTH,
REGION,
SUM(SALES) AS UNITS_SOLD
FROM SALES
GROUP BY ROLLUP ( MONTH(SALES_DATE), REGION )
ORDER BY MONTH, REGION
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList =
        [ ( App
              [ Name Nothing "MONTH" ] [ Iden [ Name Nothing "SALES_DATE" ] ]
          , Just (Name Nothing "MONTH")
          )
        , ( Iden [ Name Nothing "REGION" ] , Nothing )
        , ( App [ Name Nothing "SUM" ] [ Iden [ Name Nothing "SALES" ] ]
          , Just (Name Nothing "UNITS_SOLD")
          )
        ]
    , qeFrom = [ TRSimple [ Name Nothing "SALES" ] ]
    , qeWhere = Nothing
    , qeGroupBy =
        [ Rollup
            [ SimpleGroup
                (App
                   [ Name Nothing "MONTH" ] [ Iden [ Name Nothing "SALES_DATE" ] ])
            , SimpleGroup (Iden [ Name Nothing "REGION" ])
            ]
        ]
    , qeHaving = Nothing
    , qeOrderBy =
        [ SortSpec
            (Iden [ Name Nothing "MONTH" ]) DirDefault NullsOrderDefault
        , SortSpec
            (Iden [ Name Nothing "REGION" ]) DirDefault NullsOrderDefault
        ]
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
SELECT WEEK(SALES_DATE) AS WEEK,
DAYOFWEEK(SALES_DATE) AS DAY_WEEK,
MONTH(SALES_DATE) AS MONTH,
REGION,
SUM(SALES) AS UNITS_SOLD
FROM SALES
GROUP BY GROUPING SETS ( ROLLUP( WEEK(SALES_DATE), DAYOFWEEK(SALES_DATE) ),
ROLLUP( MONTH(SALES_DATE), REGION ) )
ORDER BY WEEK, DAY_WEEK, MONTH, REGION
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList =
        [ ( App
              [ Name Nothing "WEEK" ] [ Iden [ Name Nothing "SALES_DATE" ] ]
          , Just (Name Nothing "WEEK")
          )
        , ( App
              [ Name Nothing "DAYOFWEEK" ] [ Iden [ Name Nothing "SALES_DATE" ] ]
          , Just (Name Nothing "DAY_WEEK")
          )
        , ( App
              [ Name Nothing "MONTH" ] [ Iden [ Name Nothing "SALES_DATE" ] ]
          , Just (Name Nothing "MONTH")
          )
        , ( Iden [ Name Nothing "REGION" ] , Nothing )
        , ( App [ Name Nothing "SUM" ] [ Iden [ Name Nothing "SALES" ] ]
          , Just (Name Nothing "UNITS_SOLD")
          )
        ]
    , qeFrom = [ TRSimple [ Name Nothing "SALES" ] ]
    , qeWhere = Nothing
    , qeGroupBy =
        [ GroupingSets
            [ Rollup
                [ SimpleGroup
                    (App
                       [ Name Nothing "WEEK" ] [ Iden [ Name Nothing "SALES_DATE" ] ])
                , SimpleGroup
                    (App
                       [ Name Nothing "DAYOFWEEK" ]
                       [ Iden [ Name Nothing "SALES_DATE" ] ])
                ]
            , Rollup
                [ SimpleGroup
                    (App
                       [ Name Nothing "MONTH" ] [ Iden [ Name Nothing "SALES_DATE" ] ])
                , SimpleGroup (Iden [ Name Nothing "REGION" ])
                ]
            ]
        ]
    , qeHaving = Nothing
    , qeOrderBy =
        [ SortSpec
            (Iden [ Name Nothing "WEEK" ]) DirDefault NullsOrderDefault
        , SortSpec
            (Iden [ Name Nothing "DAY_WEEK" ]) DirDefault NullsOrderDefault
        , SortSpec
            (Iden [ Name Nothing "MONTH" ]) DirDefault NullsOrderDefault
        , SortSpec
            (Iden [ Name Nothing "REGION" ]) DirDefault NullsOrderDefault
        ]
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
SELECT R1, R2,
WEEK(SALES_DATE) AS WEEK,
DAYOFWEEK(SALES_DATE) AS DAY_WEEK,
MONTH(SALES_DATE) AS MONTH,
REGION, SUM(SALES) AS UNITS_SOLD
FROM SALES,(VALUES('GROUP 1','GROUP 2')) AS X(R1,R2)
GROUP BY GROUPING SETS ((R1, ROLLUP(WEEK(SALES_DATE),
DAYOFWEEK(SALES_DATE))),
(R2,ROLLUP( MONTH(SALES_DATE), REGION ) ))
ORDER BY WEEK, DAY_WEEK, MONTH, REGION
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList =
        [ ( Iden [ Name Nothing "R1" ] , Nothing )
        , ( Iden [ Name Nothing "R2" ] , Nothing )
        , ( App
              [ Name Nothing "WEEK" ] [ Iden [ Name Nothing "SALES_DATE" ] ]
          , Just (Name Nothing "WEEK")
          )
        , ( App
              [ Name Nothing "DAYOFWEEK" ] [ Iden [ Name Nothing "SALES_DATE" ] ]
          , Just (Name Nothing "DAY_WEEK")
          )
        , ( App
              [ Name Nothing "MONTH" ] [ Iden [ Name Nothing "SALES_DATE" ] ]
          , Just (Name Nothing "MONTH")
          )
        , ( Iden [ Name Nothing "REGION" ] , Nothing )
        , ( App [ Name Nothing "SUM" ] [ Iden [ Name Nothing "SALES" ] ]
          , Just (Name Nothing "UNITS_SOLD")
          )
        ]
    , qeFrom =
        [ TRSimple [ Name Nothing "SALES" ]
        , TRAlias
            (TRQueryExpr
               (Values
                  [ [ StringLit "'" "'" "GROUP 1" , StringLit "'" "'" "GROUP 2" ] ]))
            (Alias
               (Name Nothing "X")
               (Just [ Name Nothing "R1" , Name Nothing "R2" ]))
        ]
    , qeWhere = Nothing
    , qeGroupBy =
        [ GroupingSets
            [ GroupingParens
                [ SimpleGroup (Iden [ Name Nothing "R1" ])
                , Rollup
                    [ SimpleGroup
                        (App
                           [ Name Nothing "WEEK" ] [ Iden [ Name Nothing "SALES_DATE" ] ])
                    , SimpleGroup
                        (App
                           [ Name Nothing "DAYOFWEEK" ]
                           [ Iden [ Name Nothing "SALES_DATE" ] ])
                    ]
                ]
            , GroupingParens
                [ SimpleGroup (Iden [ Name Nothing "R2" ])
                , Rollup
                    [ SimpleGroup
                        (App
                           [ Name Nothing "MONTH" ] [ Iden [ Name Nothing "SALES_DATE" ] ])
                    , SimpleGroup (Iden [ Name Nothing "REGION" ])
                    ]
                ]
            ]
        ]
    , qeHaving = Nothing
    , qeOrderBy =
        [ SortSpec
            (Iden [ Name Nothing "WEEK" ]) DirDefault NullsOrderDefault
        , SortSpec
            (Iden [ Name Nothing "DAY_WEEK" ]) DirDefault NullsOrderDefault
        , SortSpec
            (Iden [ Name Nothing "MONTH" ]) DirDefault NullsOrderDefault
        , SortSpec
            (Iden [ Name Nothing "REGION" ]) DirDefault NullsOrderDefault
        ]
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
SELECT MONTH(SALES_DATE) AS MONTH,
REGION,
SUM(SALES) AS UNITS_SOLD,
MAX(SALES) AS BEST_SALE,
CAST(ROUND(AVG(DECIMALx(SALES)),2) AS DECIMAL(5,2)) AS AVG_UNITS_SOLD
FROM SALES
GROUP BY CUBE(MONTH(SALES_DATE),REGION)
ORDER BY MONTH, REGION
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList =
        [ ( App
              [ Name Nothing "MONTH" ] [ Iden [ Name Nothing "SALES_DATE" ] ]
          , Just (Name Nothing "MONTH")
          )
        , ( Iden [ Name Nothing "REGION" ] , Nothing )
        , ( App [ Name Nothing "SUM" ] [ Iden [ Name Nothing "SALES" ] ]
          , Just (Name Nothing "UNITS_SOLD")
          )
        , ( App [ Name Nothing "MAX" ] [ Iden [ Name Nothing "SALES" ] ]
          , Just (Name Nothing "BEST_SALE")
          )
        , ( Cast
              (App
                 [ Name Nothing "ROUND" ]
                 [ App
                     [ Name Nothing "AVG" ]
                     [ App [ Name Nothing "DECIMALx" ] [ Iden [ Name Nothing "SALES" ] ]
                     ]
                 , NumLit "2"
                 ])
              (PrecScaleTypeName [ Name Nothing "decimal" ] 5 2)
          , Just (Name Nothing "AVG_UNITS_SOLD")
          )
        ]
    , qeFrom = [ TRSimple [ Name Nothing "SALES" ] ]
    , qeWhere = Nothing
    , qeGroupBy =
        [ Cube
            [ SimpleGroup
                (App
                   [ Name Nothing "MONTH" ] [ Iden [ Name Nothing "SALES_DATE" ] ])
            , SimpleGroup (Iden [ Name Nothing "REGION" ])
            ]
        ]
    , qeHaving = Nothing
    , qeOrderBy =
        [ SortSpec
            (Iden [ Name Nothing "MONTH" ]) DirDefault NullsOrderDefault
        , SortSpec
            (Iden [ Name Nothing "REGION" ]) DirDefault NullsOrderDefault
        ]
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }

8. queries

select count(*) from t
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList =
      [ ( App [ Name Nothing "count" ] [ Star ] , Nothing ) ]
  , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
  , qeWhere = Nothing
  , qeGroupBy = []
  , qeHaving = Nothing
  , qeOrderBy = []
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }
select a, sum(c+d) as s
  from t,u
  where a > 5
  group by a
  having count(1) > 5
  order by s
Select
  { qeSetQuantifier = SQDefault
  , qeSelectList =
      [ ( Iden [ Name Nothing "a" ] , Nothing )
      , ( App
            [ Name Nothing "sum" ]
            [ BinOp
                (Iden [ Name Nothing "c" ])
                [ Name Nothing "+" ]
                (Iden [ Name Nothing "d" ])
            ]
        , Just (Name Nothing "s")
        )
      ]
  , qeFrom =
      [ TRSimple [ Name Nothing "t" ] , TRSimple [ Name Nothing "u" ] ]
  , qeWhere =
      Just
        (BinOp
           (Iden [ Name Nothing "a" ]) [ Name Nothing ">" ] (NumLit "5"))
  , qeGroupBy = [ SimpleGroup (Iden [ Name Nothing "a" ]) ]
  , qeHaving =
      Just
        (BinOp
           (App [ Name Nothing "count" ] [ NumLit "1" ])
           [ Name Nothing ">" ]
           (NumLit "5"))
  , qeOrderBy =
      [ SortSpec (Iden [ Name Nothing "s" ]) DirDefault NullsOrderDefault
      ]
  , qeOffset = Nothing
  , qeFetchFirst = Nothing
  }

9. postgresTests

SELECT name, (SELECT max(pop) FROM cities
 WHERE cities.state = states.name)
    FROM states;
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList =
        [ ( Iden [ Name Nothing "name" ] , Nothing )
        , ( SubQueryExpr
              SqSq
              Select
                { qeSetQuantifier = SQDefault
                , qeSelectList =
                    [ ( App [ Name Nothing "max" ] [ Iden [ Name Nothing "pop" ] ]
                      , Nothing
                      )
                    ]
                , qeFrom = [ TRSimple [ Name Nothing "cities" ] ]
                , qeWhere =
                    Just
                      (BinOp
                         (Iden [ Name Nothing "cities" , Name Nothing "state" ])
                         [ Name Nothing "=" ]
                         (Iden [ Name Nothing "states" , Name Nothing "name" ]))
                , qeGroupBy = []
                , qeHaving = Nothing
                , qeOrderBy = []
                , qeOffset = Nothing
                , qeFetchFirst = Nothing
                }
          , Nothing
          )
        ]
    , qeFrom = [ TRSimple [ Name Nothing "states" ] ]
    , qeWhere = Nothing
    , qeGroupBy = []
    , qeHaving = Nothing
    , qeOrderBy = []
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
SELECT ROW(1,2.5,'this is a test');
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList =
        [ ( App
              [ Name Nothing "ROW" ]
              [ NumLit "1" , NumLit "2.5" , StringLit "'" "'" "this is a test" ]
          , Nothing
          )
        ]
    , qeFrom = []
    , qeWhere = Nothing
    , qeGroupBy = []
    , qeHaving = Nothing
    , qeOrderBy = []
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
SELECT ROW(t.*, 42) FROM t;
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList =
        [ ( App
              [ Name Nothing "ROW" ]
              [ BinOp (Iden [ Name Nothing "t" ]) [ Name Nothing "." ] Star
              , NumLit "42"
              ]
          , Nothing
          )
        ]
    , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
    , qeWhere = Nothing
    , qeGroupBy = []
    , qeHaving = Nothing
    , qeOrderBy = []
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
SELECT ROW(t.f1, t.f2, 42) FROM t;
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList =
        [ ( App
              [ Name Nothing "ROW" ]
              [ Iden [ Name Nothing "t" , Name Nothing "f1" ]
              , Iden [ Name Nothing "t" , Name Nothing "f2" ]
              , NumLit "42"
              ]
          , Nothing
          )
        ]
    , qeFrom = [ TRSimple [ Name Nothing "t" ] ]
    , qeWhere = Nothing
    , qeGroupBy = []
    , qeHaving = Nothing
    , qeOrderBy = []
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
SELECT getf1(CAST(ROW(11,'this is a test',2.5) AS myrowtype));
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList =
        [ ( App
              [ Name Nothing "getf1" ]
              [ Cast
                  (App
                     [ Name Nothing "ROW" ]
                     [ NumLit "11"
                     , StringLit "'" "'" "this is a test"
                     , NumLit "2.5"
                     ])
                  (TypeName [ Name Nothing "myrowtype" ])
              ]
          , Nothing
          )
        ]
    , qeFrom = []
    , qeWhere = Nothing
    , qeGroupBy = []
    , qeHaving = Nothing
    , qeOrderBy = []
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
SELECT ROW(1,2.5,'this is a test') = ROW(1, 3, 'not the same');
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList =
        [ ( BinOp
              (App
                 [ Name Nothing "ROW" ]
                 [ NumLit "1" , NumLit "2.5" , StringLit "'" "'" "this is a test" ])
              [ Name Nothing "=" ]
              (App
                 [ Name Nothing "ROW" ]
                 [ NumLit "1" , NumLit "3" , StringLit "'" "'" "not the same" ])
          , Nothing
          )
        ]
    , qeFrom = []
    , qeWhere = Nothing
    , qeGroupBy = []
    , qeHaving = Nothing
    , qeOrderBy = []
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
SELECT ROW(tablex.*) IS NULL FROM tablex;
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList =
        [ ( PostfixOp
              [ Name Nothing "is null" ]
              (App
                 [ Name Nothing "ROW" ]
                 [ BinOp (Iden [ Name Nothing "tablex" ]) [ Name Nothing "." ] Star
                 ])
          , Nothing
          )
        ]
    , qeFrom = [ TRSimple [ Name Nothing "tablex" ] ]
    , qeWhere = Nothing
    , qeGroupBy = []
    , qeHaving = Nothing
    , qeOrderBy = []
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
SELECT true OR somefunc();
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList =
        [ ( BinOp
              (Iden [ Name Nothing "true" ])
              [ Name Nothing "or" ]
              (App [ Name Nothing "somefunc" ] [])
          , Nothing
          )
        ]
    , qeFrom = []
    , qeWhere = Nothing
    , qeGroupBy = []
    , qeHaving = Nothing
    , qeOrderBy = []
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
SELECT somefunc() OR true;
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList =
        [ ( BinOp
              (App [ Name Nothing "somefunc" ] [])
              [ Name Nothing "or" ]
              (Iden [ Name Nothing "true" ])
          , Nothing
          )
        ]
    , qeFrom = []
    , qeWhere = Nothing
    , qeGroupBy = []
    , qeHaving = Nothing
    , qeOrderBy = []
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
SELECT * FROM t1 CROSS JOIN t2;
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList = [ ( Star , Nothing ) ]
    , qeFrom =
        [ TRJoin
            (TRSimple [ Name Nothing "t1" ])
            False
            JCross
            (TRSimple [ Name Nothing "t2" ])
            Nothing
        ]
    , qeWhere = Nothing
    , qeGroupBy = []
    , qeHaving = Nothing
    , qeOrderBy = []
    , qeOffset = Nothing
    , qeFetchFirst = Nothing
    }
SELECT * FROM t1 INNER JOIN t2 ON t1.num = t2.num;
Right
  Select
    { qeSetQuantifier = SQDefault
    , qeSelectList = [ ( Star , Nothing ) ]
    , qeFrom =
        [ TRJoin
            (TRSimple [ Name Nothing "t1" ])
            False
            JInner
            (TRSimple [ Name Nothing "t2" ])
            (Just