parserTest

valueExprTests

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 "interval"]) "3 weeks"

identifiers

iden1
Iden [Name "iden1"]
"quoted identifier"
Iden [QName "quoted identifier"]

star

*
Star

parameter

?
Parameter

dot

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

app

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

caseexp

case a when 1 then 2 end
Case{caseTest = Just (Iden [Name "a"]),
     caseWhens = [([NumLit "1"], NumLit "2")], caseElse = Nothing}
case a when 1 then 2 when 3 then 4 end
Case{caseTest = Just (Iden [Name "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 "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 "a"]) [Name "="] (NumLit "1")], NumLit "2"),
        ([BinOp (Iden [Name "a"]) [Name "="] (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 "a"]),
     caseWhens =
       [([NumLit "1", NumLit "2"], NumLit "10"),
        ([NumLit "3", NumLit "4"], NumLit "20")],
     caseElse = Nothing}

operators

binaryOperators

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

unaryOperators

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

operators

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

unaryOperators

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

parens

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

unaryOperators

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

aggregates

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

windowFunctions

max(a) over ()
WindowApp{wnName = [Name "max"], wnArgs = [Iden [Name "a"]],
          wnPartition = [], wnOrderBy = [], wnFrame = Nothing}
count(*) over ()
WindowApp{wnName = [Name "count"], wnArgs = [Star],
          wnPartition = [], wnOrderBy = [], wnFrame = Nothing}
max(a) over (partition by b)
WindowApp{wnName = [Name "max"], wnArgs = [Iden [Name "a"]],
          wnPartition = [Iden [Name "b"]], wnOrderBy = [], wnFrame = Nothing}
max(a) over (partition by b,c)
WindowApp{wnName = [Name "max"], wnArgs = [Iden [Name "a"]],
          wnPartition = [Iden [Name "b"], Iden [Name "c"]], wnOrderBy = [],
          wnFrame = Nothing}
sum(a) over (order by b)
WindowApp{wnName = [Name "sum"], wnArgs = [Iden [Name "a"]],
          wnPartition = [],
          wnOrderBy =
            [SortSpec (Iden [Name "b"]) DirDefault NullsOrderDefault],
          wnFrame = Nothing}
sum(a) over (order by b desc,c)
WindowApp{wnName = [Name "sum"], wnArgs = [Iden [Name "a"]],
          wnPartition = [],
          wnOrderBy =
            [SortSpec (Iden [Name "b"]) Desc NullsOrderDefault,
             SortSpec (Iden [Name "c"]) DirDefault NullsOrderDefault],
          wnFrame = Nothing}
sum(a) over (partition by b order by c)
WindowApp{wnName = [Name "sum"], wnArgs = [Iden [Name "a"]],
          wnPartition = [Iden [Name "b"]],
          wnOrderBy =
            [SortSpec (Iden [Name "c"]) DirDefault NullsOrderDefault],
          wnFrame = Nothing}
sum(a) over (partition by b order by c range unbounded preceding)
WindowApp{wnName = [Name "sum"], wnArgs = [Iden [Name "a"]],
          wnPartition = [Iden [Name "b"]],
          wnOrderBy =
            [SortSpec (Iden [Name "c"]) DirDefault NullsOrderDefault],
          wnFrame = Just (FrameFrom FrameRange UnboundedPreceding)}
sum(a) over (partition by b order by c range 5 preceding)
WindowApp{wnName = [Name "sum"], wnArgs = [Iden [Name "a"]],
          wnPartition = [Iden [Name "b"]],
          wnOrderBy =
            [SortSpec (Iden [Name "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 "sum"], wnArgs = [Iden [Name "a"]],
          wnPartition = [Iden [Name "b"]],
          wnOrderBy =
            [SortSpec (Iden [Name "c"]) DirDefault NullsOrderDefault],
          wnFrame = Just (FrameFrom FrameRange Current)}
sum(a) over (partition by b order by c rows 5 following)
WindowApp{wnName = [Name "sum"], wnArgs = [Iden [Name "a"]],
          wnPartition = [Iden [Name "b"]],
          wnOrderBy =
            [SortSpec (Iden [Name "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 "sum"], wnArgs = [Iden [Name "a"]],
          wnPartition = [Iden [Name "b"]],
          wnOrderBy =
            [SortSpec (Iden [Name "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 "sum"], wnArgs = [Iden [Name "a"]],
          wnPartition = [Iden [Name "b"]],
          wnOrderBy =
            [SortSpec (Iden [Name "c"]) DirDefault NullsOrderDefault],
          wnFrame =
            Just
              (FrameBetween FrameRange (Preceding (NumLit "5"))
                 (Following (NumLit "5")))}

queryExprComponentTests

duplicates

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

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 "a"], Nothing)], qeFrom = [],
       qeWhere = Nothing, qeGroupBy = [], qeHaving = Nothing,
       qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing}
select a,b
Select{qeSetQuantifier = SQDefault,
       qeSelectList =
         [(Iden [Name "a"], Nothing), (Iden [Name "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 "+"] (NumLit "2"), Nothing),
          (BinOp (NumLit "3") [Name "+"] (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 "a"], Just (Name "a")),
          (Iden [Name "b"], Just (Name "b"))],
       qeFrom = [], qeWhere = Nothing, qeGroupBy = [], qeHaving = Nothing,
       qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing}
select a a, b b
Select{qeSetQuantifier = SQDefault,
       qeSelectList =
         [(Iden [Name "a"], Just (Name "a")),
          (Iden [Name "b"], Just (Name "b"))],
       qeFrom = [], qeWhere = Nothing, qeGroupBy = [], qeHaving = Nothing,
       qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing}
select a + b * c
Select{qeSetQuantifier = SQDefault,
       qeSelectList =
         [(BinOp (Iden [Name "a"]) [Name "+"]
             (BinOp (Iden [Name "b"]) [Name "*"] (Iden [Name "c"])),
           Nothing)],
       qeFrom = [], qeWhere = Nothing, qeGroupBy = [], qeHaving = Nothing,
       qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing}

whereClause

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

having

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

orderBy

select a from t order by a
Select{qeSetQuantifier = SQDefault,
       qeSelectList = [(Iden [Name "a"], Nothing)],
       qeFrom = [TRSimple [Name "t"]], qeWhere = Nothing, qeGroupBy = [],
       qeHaving = Nothing,
       qeOrderBy =
         [SortSpec (Iden [Name "a"]) DirDefault NullsOrderDefault],
       qeOffset = Nothing, qeFetchFirst = Nothing}
select a from t order by a, b
Select{qeSetQuantifier = SQDefault,
       qeSelectList = [(Iden [Name "a"], Nothing)],
       qeFrom = [TRSimple [Name "t"]], qeWhere = Nothing, qeGroupBy = [],
       qeHaving = Nothing,
       qeOrderBy =
         [SortSpec (Iden [Name "a"]) DirDefault NullsOrderDefault,
          SortSpec (Iden [Name "b"]) DirDefault NullsOrderDefault],
       qeOffset = Nothing, qeFetchFirst = Nothing}
select a from t order by a asc
Select{qeSetQuantifier = SQDefault,
       qeSelectList = [(Iden [Name "a"], Nothing)],
       qeFrom = [TRSimple [Name "t"]], qeWhere = Nothing, qeGroupBy = [],
       qeHaving = Nothing,
       qeOrderBy = [SortSpec (Iden [Name "a"]) Asc NullsOrderDefault],
       qeOffset = Nothing, qeFetchFirst = Nothing}
select a from t order by a desc, b desc
Select{qeSetQuantifier = SQDefault,
       qeSelectList = [(Iden [Name "a"], Nothing)],
       qeFrom = [TRSimple [Name "t"]], qeWhere = Nothing, qeGroupBy = [],
       qeHaving = Nothing,
       qeOrderBy =
         [SortSpec (Iden [Name "a"]) Desc NullsOrderDefault,
          SortSpec (Iden [Name "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 "a"], Nothing)],
       qeFrom = [TRSimple [Name "t"]], qeWhere = Nothing, qeGroupBy = [],
       qeHaving = Nothing,
       qeOrderBy =
         [SortSpec (Iden [Name "a"]) Desc NullsFirst,
          SortSpec (Iden [Name "b"]) Desc NullsLast],
       qeOffset = Nothing, qeFetchFirst = Nothing}

offsetFetch

select a from t offset 5 rows fetch next 10 rows only
Select{qeSetQuantifier = SQDefault,
       qeSelectList = [(Iden [Name "a"], Nothing)],
       qeFrom = [TRSimple [Name "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 "a"], Nothing)],
       qeFrom = [TRSimple [Name "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 "a"], Nothing)],
       qeFrom = [TRSimple [Name "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 "a"], Nothing)],
       qeFrom = [TRSimple [Name "t"]], qeWhere = Nothing, qeGroupBy = [],
       qeHaving = Nothing, qeOrderBy = [], qeOffset = Just (NumLit "5"),
       qeFetchFirst = Just (NumLit "10")}

combos

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

with queries

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

values

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

tables

table tbl
Table [Name "tbl"]

query exprs

select 1
[Select{qeSetQuantifier = SQDefault,
        qeSelectList = [(NumLit "1", Nothing)], qeFrom = [],
        qeWhere = Nothing, qeGroupBy = [], qeHaving = Nothing,
        qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing}]
select 1;
[Select{qeSetQuantifier = SQDefault,
        qeSelectList = [(NumLit "1", Nothing)], qeFrom = [],
        qeWhere = Nothing, qeGroupBy = [], qeHaving = Nothing,
        qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing}]
select 1;select 1
[Select{qeSetQuantifier = SQDefault,
        qeSelectList = [(NumLit "1", Nothing)], qeFrom = [],
        qeWhere = Nothing, qeGroupBy = [], qeHaving = Nothing,
        qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing},
 Select{qeSetQuantifier = SQDefault,
        qeSelectList = [(NumLit "1", Nothing)], qeFrom = [],
        qeWhere = Nothing, qeGroupBy = [], qeHaving = Nothing,
        qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing}]
 select 1;select 1; 
[Select{qeSetQuantifier = SQDefault,
        qeSelectList = [(NumLit "1", Nothing)], qeFrom = [],
        qeWhere = Nothing, qeGroupBy = [], qeHaving = Nothing,
        qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing},
 Select{qeSetQuantifier = SQDefault,
        qeSelectList = [(NumLit "1", Nothing)], qeFrom = [],
        qeWhere = Nothing, qeGroupBy = [], qeHaving = Nothing,
        qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing}]

tableRefTests

select a from t
Select{qeSetQuantifier = SQDefault,
       qeSelectList = [(Iden [Name "a"], Nothing)],
       qeFrom = [TRSimple [Name "t"]], qeWhere = Nothing, qeGroupBy = [],
       qeHaving = Nothing, qeOrderBy = [], qeOffset = Nothing,
       qeFetchFirst = Nothing}
select a from f(a)
Select{qeSetQuantifier = SQDefault,
       qeSelectList = [(Iden [Name "a"], Nothing)],
       qeFrom = [TRFunction [Name "f"] [Iden [Name "a"]]],
       qeWhere = Nothing, qeGroupBy = [], qeHaving = Nothing,
       qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing}
select a from t,u
Select{qeSetQuantifier = SQDefault,
       qeSelectList = [(Iden [Name "a"], Nothing)],
       qeFrom = [TRSimple [Name "t"], TRSimple [Name "u"]],
       qeWhere = Nothing, qeGroupBy = [], qeHaving = Nothing,
       qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing}
select a from s.t
Select{qeSetQuantifier = SQDefault,
       qeSelectList = [(Iden [Name "a"], Nothing)],
       qeFrom = [TRSimple [Name "s", Name "t"]], qeWhere = Nothing,
       qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
       qeOffset = Nothing, qeFetchFirst = Nothing}
select a from lateral a
Select{qeSetQuantifier = SQDefault,
       qeSelectList = [(Iden [Name "a"], Nothing)],
       qeFrom = [TRLateral (TRSimple [Name "a"])], qeWhere = Nothing,
       qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
       qeOffset = Nothing, qeFetchFirst = Nothing}
select a from lateral a,b
Select{qeSetQuantifier = SQDefault,
       qeSelectList = [(Iden [Name "a"], Nothing)],
       qeFrom = [TRLateral (TRSimple [Name "a"]), TRSimple [Name "b"]],
       qeWhere = Nothing, qeGroupBy = [], qeHaving = Nothing,
       qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing}
select a from a, lateral b
Select{qeSetQuantifier = SQDefault,
       qeSelectList = [(Iden [Name "a"], Nothing)],
       qeFrom = [TRSimple [Name "a"], TRLateral (TRSimple [Name "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 "a"], Nothing)],
       qeFrom =
         [TRJoin (TRSimple [Name "a"]) True JInner
            (TRLateral (TRSimple [Name "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 "a"], Nothing)],
       qeFrom =
         [TRJoin (TRLateral (TRSimple [Name "a"])) True JInner
            (TRLateral (TRSimple [Name "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 "a"], Nothing)],
       qeFrom =
         [TRJoin (TRSimple [Name "t"]) False JInner (TRSimple [Name "u"])
            (Just (JoinOn (Iden [Name "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 "a"], Nothing)],
       qeFrom =
         [TRJoin (TRSimple [Name "t"]) False JInner (TRSimple [Name "u"])
            (Just (JoinOn (Iden [Name "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 "a"], Nothing)],
       qeFrom =
         [TRJoin (TRSimple [Name "t"]) False JLeft (TRSimple [Name "u"])
            (Just (JoinOn (Iden [Name "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 "a"], Nothing)],
       qeFrom =
         [TRJoin (TRSimple [Name "t"]) False JRight (TRSimple [Name "u"])
            (Just (JoinOn (Iden [Name "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 "a"], Nothing)],
       qeFrom =
         [TRJoin (TRSimple [Name "t"]) False JFull (TRSimple [Name "u"])
            (Just (JoinOn (Iden [Name "expr"])))],
       qeWhere = Nothing, qeGroupBy = [], qeHaving = Nothing,
       qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing}
select a from t cross join u
Select{qeSetQuantifier = SQDefault,
       qeSelectList = [(Iden [Name "a"], Nothing)],
       qeFrom =
         [TRJoin (TRSimple [Name "t"]) False JCross (TRSimple [Name "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 "a"], Nothing)],
       qeFrom =
         [TRJoin (TRSimple [Name "t"]) True JInner (TRSimple [Name "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 "a"], Nothing)],
       qeFrom =
         [TRJoin (TRSimple [Name "t"]) False JInner (TRSimple [Name "u"])
            (Just (JoinUsing [Name "a", Name "b"]))],
       qeWhere = Nothing, qeGroupBy = [], qeHaving = Nothing,
       qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing}
select a from (select a from t)
Select{qeSetQuantifier = SQDefault,
       qeSelectList = [(Iden [Name "a"], Nothing)],
       qeFrom =
         [TRQueryExpr
            (Select{qeSetQuantifier = SQDefault,
                    qeSelectList = [(Iden [Name "a"], Nothing)],
                    qeFrom = [TRSimple [Name "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 "a"], Nothing)],
       qeFrom =
         [TRAlias (TRSimple [Name "t"]) (Alias (Name "u") Nothing)],
       qeWhere = Nothing, qeGroupBy = [], qeHaving = Nothing,
       qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing}
select a from t u
Select{qeSetQuantifier = SQDefault,
       qeSelectList = [(Iden [Name "a"], Nothing)],
       qeFrom =
         [TRAlias (TRSimple [Name "t"]) (Alias (Name "u") Nothing)],
       qeWhere = Nothing, qeGroupBy = [], qeHaving = Nothing,
       qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing}
select a from t u(b)
Select{qeSetQuantifier = SQDefault,
       qeSelectList = [(Iden [Name "a"], Nothing)],
       qeFrom =
         [TRAlias (TRSimple [Name "t"])
            (Alias (Name "u") (Just [Name "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 "a"], Nothing)],
       qeFrom =
         [TRAlias
            (TRParens
               (TRJoin (TRSimple [Name "t"]) False JCross (TRSimple [Name "u"])
                  Nothing))
            (Alias (Name "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 "a"], Nothing)],
       qeFrom =
         [TRJoin
            (TRJoin (TRSimple [Name "t"]) False JCross (TRSimple [Name "u"])
               Nothing)
            False
            JCross
            (TRSimple [Name "v"])
            Nothing],
       qeWhere = Nothing, qeGroupBy = [], qeHaving = Nothing,
       qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing}

groupByTests

simpleGroupBy

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

newGroupBy

select * from t group by ()
Select{qeSetQuantifier = SQDefault,
       qeSelectList = [(Star, Nothing)], qeFrom = [TRSimple [Name "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 "t"]],
       qeWhere = Nothing,
       qeGroupBy =
         [GroupingSets
            [GroupingParens [],
             GroupingParens [SimpleGroup (Iden [Name "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 "t"]],
       qeWhere = Nothing,
       qeGroupBy =
         [Cube
            [SimpleGroup (Iden [Name "a"]), SimpleGroup (Iden [Name "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 "t"]],
       qeWhere = Nothing,
       qeGroupBy =
         [Rollup
            [SimpleGroup (Iden [Name "a"]), SimpleGroup (Iden [Name "b"])]],
       qeHaving = Nothing, qeOrderBy = [], qeOffset = Nothing,
       qeFetchFirst = Nothing}

randomGroupBy

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

queries

select count(*) from t
Select{qeSetQuantifier = SQDefault,
       qeSelectList = [(App [Name "count"] [Star], Nothing)],
       qeFrom = [TRSimple [Name "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 "a"], Nothing),
          (App [Name "sum"]
             [BinOp (Iden [Name "c"]) [Name "+"] (Iden [Name "d"])],
           Just (Name "s"))],
       qeFrom = [TRSimple [Name "t"], TRSimple [Name "u"]],
       qeWhere = Just (BinOp (Iden [Name "a"]) [Name ">"] (NumLit "5")),
       qeGroupBy = [SimpleGroup (Iden [Name "a"])],
       qeHaving =
         Just
           (BinOp (App [Name "count"] [NumLit "1"]) [Name ">"] (NumLit "5")),
       qeOrderBy =
         [SortSpec (Iden [Name "s"]) DirDefault NullsOrderDefault],
       qeOffset = Nothing, qeFetchFirst = Nothing}

postgresTests

SELECT name, (SELECT max(pop) FROM cities
 WHERE cities.state = states.name)
    FROM states;
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList =
            [(Iden [Name "name"], Nothing),
             (SubQueryExpr SqSq
                (Select{qeSetQuantifier = SQDefault,
                        qeSelectList = [(App [Name "max"] [Iden [Name "pop"]], Nothing)],
                        qeFrom = [TRSimple [Name "cities"]],
                        qeWhere =
                          Just
                            (BinOp (Iden [Name "cities", Name "state"]) [Name "="]
                               (Iden [Name "states", Name "name"])),
                        qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
                        qeOffset = Nothing, qeFetchFirst = Nothing}),
              Nothing)],
          qeFrom = [TRSimple [Name "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 "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 "ROW"]
                [BinOp (Iden [Name "t"]) [Name "."] Star, NumLit "42"],
              Nothing)],
          qeFrom = [TRSimple [Name "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 "ROW"]
                [Iden [Name "t", Name "f1"], Iden [Name "t", Name "f2"],
                 NumLit "42"],
              Nothing)],
          qeFrom = [TRSimple [Name "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 "getf1"]
                [Cast
                   (App [Name "ROW"]
                      [NumLit "11", StringLit "this is a test", NumLit "2.5"])
                   (TypeName [Name "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 "ROW"]
                   [NumLit "1", NumLit "2.5", StringLit "this is a test"])
                [Name "="]
                (App [Name "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 "is null"]
                (App [Name "ROW"] [BinOp (Iden [Name "tablex"]) [Name "."] Star]),
              Nothing)],
          qeFrom = [TRSimple [Name "tablex"]], qeWhere = Nothing,
          qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
          qeOffset = Nothing, qeFetchFirst = Nothing})
SELECT true OR somefunc();
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList =
            [(BinOp (Iden [Name "true"]) [Name "or"]
                (App [Name "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 "somefunc"] []) [Name "or"]
                (Iden [Name "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 "t1"]) False JCross (TRSimple [Name "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 "t1"]) False JInner (TRSimple [Name "t2"])
               (Just
                  (JoinOn
                     (BinOp (Iden [Name "t1", Name "num"]) [Name "="]
                        (Iden [Name "t2", Name "num"]))))],
          qeWhere = Nothing, qeGroupBy = [], qeHaving = Nothing,
          qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing})
SELECT * FROM t1 INNER JOIN t2 USING (num);
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList = [(Star, Nothing)],
          qeFrom =
            [TRJoin (TRSimple [Name "t1"]) False JInner (TRSimple [Name "t2"])
               (Just (JoinUsing [Name "num"]))],
          qeWhere = Nothing, qeGroupBy = [], qeHaving = Nothing,
          qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing})
SELECT * FROM t1 NATURAL INNER JOIN t2;
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList = [(Star, Nothing)],
          qeFrom =
            [TRJoin (TRSimple [Name "t1"]) True JInner (TRSimple [Name "t2"])
               Nothing],
          qeWhere = Nothing, qeGroupBy = [], qeHaving = Nothing,
          qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing})
SELECT * FROM t1 LEFT JOIN t2 ON t1.num = t2.num;
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList = [(Star, Nothing)],
          qeFrom =
            [TRJoin (TRSimple [Name "t1"]) False JLeft (TRSimple [Name "t2"])
               (Just
                  (JoinOn
                     (BinOp (Iden [Name "t1", Name "num"]) [Name "="]
                        (Iden [Name "t2", Name "num"]))))],
          qeWhere = Nothing, qeGroupBy = [], qeHaving = Nothing,
          qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing})
SELECT * FROM t1 LEFT JOIN t2 USING (num);
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList = [(Star, Nothing)],
          qeFrom =
            [TRJoin (TRSimple [Name "t1"]) False JLeft (TRSimple [Name "t2"])
               (Just (JoinUsing [Name "num"]))],
          qeWhere = Nothing, qeGroupBy = [], qeHaving = Nothing,
          qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing})
SELECT * FROM t1 RIGHT JOIN t2 ON t1.num = t2.num;
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList = [(Star, Nothing)],
          qeFrom =
            [TRJoin (TRSimple [Name "t1"]) False JRight (TRSimple [Name "t2"])
               (Just
                  (JoinOn
                     (BinOp (Iden [Name "t1", Name "num"]) [Name "="]
                        (Iden [Name "t2", Name "num"]))))],
          qeWhere = Nothing, qeGroupBy = [], qeHaving = Nothing,
          qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing})
SELECT * FROM t1 FULL JOIN t2 ON t1.num = t2.num;
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList = [(Star, Nothing)],
          qeFrom =
            [TRJoin (TRSimple [Name "t1"]) False JFull (TRSimple [Name "t2"])
               (Just
                  (JoinOn
                     (BinOp (Iden [Name "t1", Name "num"]) [Name "="]
                        (Iden [Name "t2", Name "num"]))))],
          qeWhere = Nothing, qeGroupBy = [], qeHaving = Nothing,
          qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing})
SELECT * FROM t1 LEFT JOIN t2 ON t1.num = t2.num AND t2.value = 'xxx';
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList = [(Star, Nothing)],
          qeFrom =
            [TRJoin (TRSimple [Name "t1"]) False JLeft (TRSimple [Name "t2"])
               (Just
                  (JoinOn
                     (BinOp
                        (BinOp (Iden [Name "t1", Name "num"]) [Name "="]
                           (Iden [Name "t2", Name "num"]))
                        [Name "and"]
                        (BinOp (Iden [Name "t2", Name "value"]) [Name "="]
                           (StringLit "xxx")))))],
          qeWhere = Nothing, qeGroupBy = [], qeHaving = Nothing,
          qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing})
SELECT * FROM t1 LEFT JOIN t2 ON t1.num = t2.num WHERE t2.value = 'xxx';
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList = [(Star, Nothing)],
          qeFrom =
            [TRJoin (TRSimple [Name "t1"]) False JLeft (TRSimple [Name "t2"])
               (Just
                  (JoinOn
                     (BinOp (Iden [Name "t1", Name "num"]) [Name "="]
                        (Iden [Name "t2", Name "num"]))))],
          qeWhere =
            Just
              (BinOp (Iden [Name "t2", Name "value"]) [Name "="]
                 (StringLit "xxx")),
          qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
          qeOffset = Nothing, qeFetchFirst = Nothing})
SELECT * FROM some_very_long_table_name s
JOIN another_fairly_long_name a ON s.id = a.num;
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList = [(Star, Nothing)],
          qeFrom =
            [TRJoin
               (TRAlias (TRSimple [Name "some_very_long_table_name"])
                  (Alias (Name "s") Nothing))
               False
               JInner
               (TRAlias (TRSimple [Name "another_fairly_long_name"])
                  (Alias (Name "a") Nothing))
               (Just
                  (JoinOn
                     (BinOp (Iden [Name "s", Name "id"]) [Name "="]
                        (Iden [Name "a", Name "num"]))))],
          qeWhere = Nothing, qeGroupBy = [], qeHaving = Nothing,
          qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing})
SELECT * FROM people AS mother JOIN people AS child
 ON mother.id = child.mother_id;
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList = [(Star, Nothing)],
          qeFrom =
            [TRJoin
               (TRAlias (TRSimple [Name "people"])
                  (Alias (Name "mother") Nothing))
               False
               JInner
               (TRAlias (TRSimple [Name "people"]) (Alias (Name "child") Nothing))
               (Just
                  (JoinOn
                     (BinOp (Iden [Name "mother", Name "id"]) [Name "="]
                        (Iden [Name "child", Name "mother_id"]))))],
          qeWhere = Nothing, qeGroupBy = [], qeHaving = Nothing,
          qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing})
SELECT * FROM my_table AS a CROSS JOIN my_table AS b;
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList = [(Star, Nothing)],
          qeFrom =
            [TRJoin
               (TRAlias (TRSimple [Name "my_table"]) (Alias (Name "a") Nothing))
               False
               JCross
               (TRAlias (TRSimple [Name "my_table"]) (Alias (Name "b") Nothing))
               Nothing],
          qeWhere = Nothing, qeGroupBy = [], qeHaving = Nothing,
          qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing})
SELECT * FROM (my_table AS a CROSS JOIN my_table) AS b;
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList = [(Star, Nothing)],
          qeFrom =
            [TRAlias
               (TRParens
                  (TRJoin
                     (TRAlias (TRSimple [Name "my_table"]) (Alias (Name "a") Nothing))
                     False
                     JCross
                     (TRSimple [Name "my_table"])
                     Nothing))
               (Alias (Name "b") Nothing)],
          qeWhere = Nothing, qeGroupBy = [], qeHaving = Nothing,
          qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing})
SELECT * FROM getfoo(1) AS t1;
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList = [(Star, Nothing)],
          qeFrom =
            [TRAlias (TRFunction [Name "getfoo"] [NumLit "1"])
               (Alias (Name "t1") Nothing)],
          qeWhere = Nothing, qeGroupBy = [], qeHaving = Nothing,
          qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing})
SELECT * FROM foo
    WHERE foosubid IN (
                        SELECT foosubid
                        FROM getfoo(foo.fooid) z
                        WHERE z.fooid = foo.fooid
                      );
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList = [(Star, Nothing)], qeFrom = [TRSimple [Name "foo"]],
          qeWhere =
            Just
              (In True (Iden [Name "foosubid"])
                 (InQueryExpr
                    (Select{qeSetQuantifier = SQDefault,
                            qeSelectList = [(Iden [Name "foosubid"], Nothing)],
                            qeFrom =
                              [TRAlias
                                 (TRFunction [Name "getfoo"] [Iden [Name "foo", Name "fooid"]])
                                 (Alias (Name "z") Nothing)],
                            qeWhere =
                              Just
                                (BinOp (Iden [Name "z", Name "fooid"]) [Name "="]
                                   (Iden [Name "foo", Name "fooid"])),
                            qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
                            qeOffset = Nothing, qeFetchFirst = Nothing}))),
          qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
          qeOffset = Nothing, qeFetchFirst = Nothing})
SELECT * FROM foo, LATERAL (SELECT * FROM bar WHERE bar.id = foo.bar_id) ss;
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList = [(Star, Nothing)],
          qeFrom =
            [TRSimple [Name "foo"],
             TRLateral
               (TRAlias
                  (TRQueryExpr
                     (Select{qeSetQuantifier = SQDefault,
                             qeSelectList = [(Star, Nothing)], qeFrom = [TRSimple [Name "bar"]],
                             qeWhere =
                               Just
                                 (BinOp (Iden [Name "bar", Name "id"]) [Name "="]
                                    (Iden [Name "foo", Name "bar_id"])),
                             qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
                             qeOffset = Nothing, qeFetchFirst = Nothing}))
                  (Alias (Name "ss") Nothing))],
          qeWhere = Nothing, qeGroupBy = [], qeHaving = Nothing,
          qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing})
SELECT * FROM foo, bar WHERE bar.id = foo.bar_id;
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList = [(Star, Nothing)],
          qeFrom = [TRSimple [Name "foo"], TRSimple [Name "bar"]],
          qeWhere =
            Just
              (BinOp (Iden [Name "bar", Name "id"]) [Name "="]
                 (Iden [Name "foo", Name "bar_id"])),
          qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
          qeOffset = Nothing, qeFetchFirst = Nothing})
SELECT m.name
FROM manufacturers m LEFT JOIN LATERAL get_product_names(m.id) pname ON true
WHERE pname IS NULL;
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList = [(Iden [Name "m", Name "name"], Nothing)],
          qeFrom =
            [TRJoin
               (TRAlias (TRSimple [Name "manufacturers"])
                  (Alias (Name "m") Nothing))
               False
               JLeft
               (TRLateral
                  (TRAlias
                     (TRFunction [Name "get_product_names"]
                        [Iden [Name "m", Name "id"]])
                     (Alias (Name "pname") Nothing)))
               (Just (JoinOn (Iden [Name "true"])))],
          qeWhere = Just (PostfixOp [Name "is null"] (Iden [Name "pname"])),
          qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
          qeOffset = Nothing, qeFetchFirst = Nothing})
SELECT * FROM fdt WHERE c1 > 5
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList = [(Star, Nothing)], qeFrom = [TRSimple [Name "fdt"]],
          qeWhere = Just (BinOp (Iden [Name "c1"]) [Name ">"] (NumLit "5")),
          qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
          qeOffset = Nothing, qeFetchFirst = Nothing})
SELECT * FROM fdt WHERE c1 IN (1, 2, 3)
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList = [(Star, Nothing)], qeFrom = [TRSimple [Name "fdt"]],
          qeWhere =
            Just
              (In True (Iden [Name "c1"])
                 (InList [NumLit "1", NumLit "2", NumLit "3"])),
          qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
          qeOffset = Nothing, qeFetchFirst = Nothing})
SELECT * FROM fdt WHERE c1 IN (SELECT c1 FROM t2)
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList = [(Star, Nothing)], qeFrom = [TRSimple [Name "fdt"]],
          qeWhere =
            Just
              (In True (Iden [Name "c1"])
                 (InQueryExpr
                    (Select{qeSetQuantifier = SQDefault,
                            qeSelectList = [(Iden [Name "c1"], Nothing)],
                            qeFrom = [TRSimple [Name "t2"]], qeWhere = Nothing, qeGroupBy = [],
                            qeHaving = Nothing, qeOrderBy = [], qeOffset = Nothing,
                            qeFetchFirst = Nothing}))),
          qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
          qeOffset = Nothing, qeFetchFirst = Nothing})
SELECT * FROM fdt WHERE c1 IN (SELECT c3 FROM t2 WHERE c2 = fdt.c1 + 10)
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList = [(Star, Nothing)], qeFrom = [TRSimple [Name "fdt"]],
          qeWhere =
            Just
              (In True (Iden [Name "c1"])
                 (InQueryExpr
                    (Select{qeSetQuantifier = SQDefault,
                            qeSelectList = [(Iden [Name "c3"], Nothing)],
                            qeFrom = [TRSimple [Name "t2"]],
                            qeWhere =
                              Just
                                (BinOp (Iden [Name "c2"]) [Name "="]
                                   (BinOp (Iden [Name "fdt", Name "c1"]) [Name "+"] (NumLit "10"))),
                            qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
                            qeOffset = Nothing, qeFetchFirst = Nothing}))),
          qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
          qeOffset = Nothing, qeFetchFirst = Nothing})
SELECT * FROM fdt WHERE c1 BETWEEN 
    (SELECT c3 FROM t2 WHERE c2 = fdt.c1 + 10) AND 100
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList = [(Star, Nothing)], qeFrom = [TRSimple [Name "fdt"]],
          qeWhere =
            Just
              (SpecialOp [Name "between"]
                 [Iden [Name "c1"],
                  SubQueryExpr SqSq
                    (Select{qeSetQuantifier = SQDefault,
                            qeSelectList = [(Iden [Name "c3"], Nothing)],
                            qeFrom = [TRSimple [Name "t2"]],
                            qeWhere =
                              Just
                                (BinOp (Iden [Name "c2"]) [Name "="]
                                   (BinOp (Iden [Name "fdt", Name "c1"]) [Name "+"] (NumLit "10"))),
                            qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
                            qeOffset = Nothing, qeFetchFirst = Nothing}),
                  NumLit "100"]),
          qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
          qeOffset = Nothing, qeFetchFirst = Nothing})
SELECT * FROM fdt WHERE EXISTS (SELECT c1 FROM t2 WHERE c2 > fdt.c1)
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList = [(Star, Nothing)], qeFrom = [TRSimple [Name "fdt"]],
          qeWhere =
            Just
              (SubQueryExpr SqExists
                 (Select{qeSetQuantifier = SQDefault,
                         qeSelectList = [(Iden [Name "c1"], Nothing)],
                         qeFrom = [TRSimple [Name "t2"]],
                         qeWhere =
                           Just
                             (BinOp (Iden [Name "c2"]) [Name ">"]
                                (Iden [Name "fdt", Name "c1"])),
                         qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
                         qeOffset = Nothing, qeFetchFirst = Nothing})),
          qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
          qeOffset = Nothing, qeFetchFirst = Nothing})
SELECT * FROM test1;
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList = [(Star, Nothing)],
          qeFrom = [TRSimple [Name "test1"]], qeWhere = Nothing,
          qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
          qeOffset = Nothing, qeFetchFirst = Nothing})
SELECT x FROM test1 GROUP BY x;
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList = [(Iden [Name "x"], Nothing)],
          qeFrom = [TRSimple [Name "test1"]], qeWhere = Nothing,
          qeGroupBy = [SimpleGroup (Iden [Name "x"])], qeHaving = Nothing,
          qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing})
SELECT x, sum(y) FROM test1 GROUP BY x;
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList =
            [(Iden [Name "x"], Nothing),
             (App [Name "sum"] [Iden [Name "y"]], Nothing)],
          qeFrom = [TRSimple [Name "test1"]], qeWhere = Nothing,
          qeGroupBy = [SimpleGroup (Iden [Name "x"])], qeHaving = Nothing,
          qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing})
SELECT product_id, p.name, (sum(s.units) * p.price) AS sales
    FROM products p LEFT JOIN sales s USING (product_id)
    GROUP BY product_id, p.name, p.price;
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList =
            [(Iden [Name "product_id"], Nothing),
             (Iden [Name "p", Name "name"], Nothing),
             (Parens
                (BinOp (App [Name "sum"] [Iden [Name "s", Name "units"]])
                   [Name "*"]
                   (Iden [Name "p", Name "price"])),
              Just (Name "sales"))],
          qeFrom =
            [TRJoin
               (TRAlias (TRSimple [Name "products"]) (Alias (Name "p") Nothing))
               False
               JLeft
               (TRAlias (TRSimple [Name "sales"]) (Alias (Name "s") Nothing))
               (Just (JoinUsing [Name "product_id"]))],
          qeWhere = Nothing,
          qeGroupBy =
            [SimpleGroup (Iden [Name "product_id"]),
             SimpleGroup (Iden [Name "p", Name "name"]),
             SimpleGroup (Iden [Name "p", Name "price"])],
          qeHaving = Nothing, qeOrderBy = [], qeOffset = Nothing,
          qeFetchFirst = Nothing})
SELECT x, sum(y) FROM test1 GROUP BY x HAVING sum(y) > 3;
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList =
            [(Iden [Name "x"], Nothing),
             (App [Name "sum"] [Iden [Name "y"]], Nothing)],
          qeFrom = [TRSimple [Name "test1"]], qeWhere = Nothing,
          qeGroupBy = [SimpleGroup (Iden [Name "x"])],
          qeHaving =
            Just
              (BinOp (App [Name "sum"] [Iden [Name "y"]]) [Name ">"]
                 (NumLit "3")),
          qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing})
SELECT x, sum(y) FROM test1 GROUP BY x HAVING x < 'c';
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList =
            [(Iden [Name "x"], Nothing),
             (App [Name "sum"] [Iden [Name "y"]], Nothing)],
          qeFrom = [TRSimple [Name "test1"]], qeWhere = Nothing,
          qeGroupBy = [SimpleGroup (Iden [Name "x"])],
          qeHaving =
            Just (BinOp (Iden [Name "x"]) [Name "<"] (StringLit "c")),
          qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing})
SELECT product_id, p.name, (sum(s.units) * (p.price - p.cost)) AS profit
    FROM products p LEFT JOIN sales s USING (product_id)
    WHERE s.datex > CURRENT_DATE - INTERVAL '4 weeks'
    GROUP BY product_id, p.name, p.price, p.cost
    HAVING sum(p.price * s.units) > 5000;
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList =
            [(Iden [Name "product_id"], Nothing),
             (Iden [Name "p", Name "name"], Nothing),
             (Parens
                (BinOp (App [Name "sum"] [Iden [Name "s", Name "units"]])
                   [Name "*"]
                   (Parens
                      (BinOp (Iden [Name "p", Name "price"]) [Name "-"]
                         (Iden [Name "p", Name "cost"])))),
              Just (Name "profit"))],
          qeFrom =
            [TRJoin
               (TRAlias (TRSimple [Name "products"]) (Alias (Name "p") Nothing))
               False
               JLeft
               (TRAlias (TRSimple [Name "sales"]) (Alias (Name "s") Nothing))
               (Just (JoinUsing [Name "product_id"]))],
          qeWhere =
            Just
              (BinOp (Iden [Name "s", Name "datex"]) [Name ">"]
                 (BinOp (Iden [Name "CURRENT_DATE"]) [Name "-"]
                    (TypedLit (TypeName [Name "interval"]) "4 weeks"))),
          qeGroupBy =
            [SimpleGroup (Iden [Name "product_id"]),
             SimpleGroup (Iden [Name "p", Name "name"]),
             SimpleGroup (Iden [Name "p", Name "price"]),
             SimpleGroup (Iden [Name "p", Name "cost"])],
          qeHaving =
            Just
              (BinOp
                 (App [Name "sum"]
                    [BinOp (Iden [Name "p", Name "price"]) [Name "*"]
                       (Iden [Name "s", Name "units"])])
                 [Name ">"]
                 (NumLit "5000")),
          qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing})
SELECT a, b, c FROM t
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList =
            [(Iden [Name "a"], Nothing), (Iden [Name "b"], Nothing),
             (Iden [Name "c"], Nothing)],
          qeFrom = [TRSimple [Name "t"]], qeWhere = Nothing, qeGroupBy = [],
          qeHaving = Nothing, qeOrderBy = [], qeOffset = Nothing,
          qeFetchFirst = Nothing})
SELECT tbl1.a, tbl2.a, tbl1.b FROM t
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList =
            [(Iden [Name "tbl1", Name "a"], Nothing),
             (Iden [Name "tbl2", Name "a"], Nothing),
             (Iden [Name "tbl1", Name "b"], Nothing)],
          qeFrom = [TRSimple [Name "t"]], qeWhere = Nothing, qeGroupBy = [],
          qeHaving = Nothing, qeOrderBy = [], qeOffset = Nothing,
          qeFetchFirst = Nothing})
SELECT tbl1.*, tbl2.a FROM t
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList =
            [(BinOp (Iden [Name "tbl1"]) [Name "."] Star, Nothing),
             (Iden [Name "tbl2", Name "a"], Nothing)],
          qeFrom = [TRSimple [Name "t"]], qeWhere = Nothing, qeGroupBy = [],
          qeHaving = Nothing, qeOrderBy = [], qeOffset = Nothing,
          qeFetchFirst = Nothing})
SELECT a AS value, b + c AS sum FROM t
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList =
            [(Iden [Name "a"], Just (Name "value")),
             (BinOp (Iden [Name "b"]) [Name "+"] (Iden [Name "c"]),
              Just (Name "sum"))],
          qeFrom = [TRSimple [Name "t"]], qeWhere = Nothing, qeGroupBy = [],
          qeHaving = Nothing, qeOrderBy = [], qeOffset = Nothing,
          qeFetchFirst = Nothing})
SELECT a "value", b + c AS sum FROM t
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList =
            [(Iden [Name "a"], Just (QName "value")),
             (BinOp (Iden [Name "b"]) [Name "+"] (Iden [Name "c"]),
              Just (Name "sum"))],
          qeFrom = [TRSimple [Name "t"]], qeWhere = Nothing, qeGroupBy = [],
          qeHaving = Nothing, qeOrderBy = [], qeOffset = Nothing,
          qeFetchFirst = Nothing})
SELECT DISTINCT select_list t
Right
  (Select{qeSetQuantifier = Distinct,
          qeSelectList = [(Iden [Name "select_list"], Just (Name "t"))],
          qeFrom = [], qeWhere = Nothing, qeGroupBy = [], qeHaving = Nothing,
          qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing})
VALUES (1, 'one'), (2, 'two'), (3, 'three');
Right
  (Values
     [[NumLit "1", StringLit "one"], [NumLit "2", StringLit "two"],
      [NumLit "3", StringLit "three"]])
SELECT 1 AS column1, 'one' AS column2
UNION ALL
SELECT 2, 'two'
UNION ALL
SELECT 3, 'three';
Right
  (CombineQueryExpr{qe0 =
                      Select{qeSetQuantifier = SQDefault,
                             qeSelectList =
                               [(NumLit "1", Just (Name "column1")),
                                (StringLit "one", Just (Name "column2"))],
                             qeFrom = [], qeWhere = Nothing, qeGroupBy = [], qeHaving = Nothing,
                             qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing},
                    qeCombOp = Union, qeSetQuantifier = All,
                    qeCorresponding = Respectively,
                    qe1 =
                      CombineQueryExpr{qe0 =
                                         Select{qeSetQuantifier = SQDefault,
                                                qeSelectList =
                                                  [(NumLit "2", Nothing),
                                                   (StringLit "two", Nothing)],
                                                qeFrom = [], qeWhere = Nothing, qeGroupBy = [],
                                                qeHaving = Nothing, qeOrderBy = [],
                                                qeOffset = Nothing, qeFetchFirst = Nothing},
                                       qeCombOp = Union, qeSetQuantifier = All,
                                       qeCorresponding = Respectively,
                                       qe1 =
                                         Select{qeSetQuantifier = SQDefault,
                                                qeSelectList =
                                                  [(NumLit "3", Nothing),
                                                   (StringLit "three", Nothing)],
                                                qeFrom = [], qeWhere = Nothing, qeGroupBy = [],
                                                qeHaving = Nothing, qeOrderBy = [],
                                                qeOffset = Nothing, qeFetchFirst = Nothing}}})
SELECT * FROM (VALUES (1, 'one'), (2, 'two'), (3, 'three')) AS t (num,letter);
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList = [(Star, Nothing)],
          qeFrom =
            [TRAlias
               (TRQueryExpr
                  (Values
                     [[NumLit "1", StringLit "one"], [NumLit "2", StringLit "two"],
                      [NumLit "3", StringLit "three"]]))
               (Alias (Name "t") (Just [Name "num", Name "letter"]))],
          qeWhere = Nothing, qeGroupBy = [], qeHaving = Nothing,
          qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing})
WITH regional_sales AS (
        SELECT region, SUM(amount) AS total_sales
        FROM orders
        GROUP BY region
     ), top_regions AS (
        SELECT region
        FROM regional_sales
        WHERE total_sales > (SELECT SUM(total_sales)/10 FROM regional_sales)
     )
SELECT region,
       product,
       SUM(quantity) AS product_units,
       SUM(amount) AS product_sales
FROM orders
WHERE region IN (SELECT region FROM top_regions)
GROUP BY region, product;
Right
  (With{qeWithRecursive = False,
        qeViews =
          [(Alias (Name "regional_sales") Nothing,
            Select{qeSetQuantifier = SQDefault,
                   qeSelectList =
                     [(Iden [Name "region"], Nothing),
                      (App [Name "SUM"] [Iden [Name "amount"]],
                       Just (Name "total_sales"))],
                   qeFrom = [TRSimple [Name "orders"]], qeWhere = Nothing,
                   qeGroupBy = [SimpleGroup (Iden [Name "region"])],
                   qeHaving = Nothing, qeOrderBy = [], qeOffset = Nothing,
                   qeFetchFirst = Nothing}),
           (Alias (Name "top_regions") Nothing,
            Select{qeSetQuantifier = SQDefault,
                   qeSelectList = [(Iden [Name "region"], Nothing)],
                   qeFrom = [TRSimple [Name "regional_sales"]],
                   qeWhere =
                     Just
                       (BinOp (Iden [Name "total_sales"]) [Name ">"]
                          (SubQueryExpr SqSq
                             (Select{qeSetQuantifier = SQDefault,
                                     qeSelectList =
                                       [(BinOp (App [Name "SUM"] [Iden [Name "total_sales"]])
                                           [Name "/"]
                                           (NumLit "10"),
                                         Nothing)],
                                     qeFrom = [TRSimple [Name "regional_sales"]], qeWhere = Nothing,
                                     qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
                                     qeOffset = Nothing, qeFetchFirst = Nothing}))),
                   qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
                   qeOffset = Nothing, qeFetchFirst = Nothing})],
        qeQueryExpression =
          Select{qeSetQuantifier = SQDefault,
                 qeSelectList =
                   [(Iden [Name "region"], Nothing), (Iden [Name "product"], Nothing),
                    (App [Name "SUM"] [Iden [Name "quantity"]],
                     Just (Name "product_units")),
                    (App [Name "SUM"] [Iden [Name "amount"]],
                     Just (Name "product_sales"))],
                 qeFrom = [TRSimple [Name "orders"]],
                 qeWhere =
                   Just
                     (In True (Iden [Name "region"])
                        (InQueryExpr
                           (Select{qeSetQuantifier = SQDefault,
                                   qeSelectList = [(Iden [Name "region"], Nothing)],
                                   qeFrom = [TRSimple [Name "top_regions"]], qeWhere = Nothing,
                                   qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
                                   qeOffset = Nothing, qeFetchFirst = Nothing}))),
                 qeGroupBy =
                   [SimpleGroup (Iden [Name "region"]),
                    SimpleGroup (Iden [Name "product"])],
                 qeHaving = Nothing, qeOrderBy = [], qeOffset = Nothing,
                 qeFetchFirst = Nothing}})
WITH RECURSIVE t(n) AS (
    VALUES (1)
  UNION ALL
    SELECT n+1 FROM t WHERE n < 100
)
SELECT sum(n) FROM t
Right
  (With{qeWithRecursive = True,
        qeViews =
          [(Alias (Name "t") (Just [Name "n"]),
            CombineQueryExpr{qe0 = Values [[NumLit "1"]], qeCombOp = Union,
                             qeSetQuantifier = All, qeCorresponding = Respectively,
                             qe1 =
                               Select{qeSetQuantifier = SQDefault,
                                      qeSelectList =
                                        [(BinOp (Iden [Name "n"]) [Name "+"] (NumLit "1"),
                                          Nothing)],
                                      qeFrom = [TRSimple [Name "t"]],
                                      qeWhere =
                                        Just (BinOp (Iden [Name "n"]) [Name "<"] (NumLit "100")),
                                      qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
                                      qeOffset = Nothing, qeFetchFirst = Nothing}})],
        qeQueryExpression =
          Select{qeSetQuantifier = SQDefault,
                 qeSelectList = [(App [Name "sum"] [Iden [Name "n"]], Nothing)],
                 qeFrom = [TRSimple [Name "t"]], qeWhere = Nothing, qeGroupBy = [],
                 qeHaving = Nothing, qeOrderBy = [], qeOffset = Nothing,
                 qeFetchFirst = Nothing}})
WITH RECURSIVE included_parts(sub_part, part, quantity) AS (
    SELECT sub_part, part, quantity FROM parts WHERE part = 'our_product'
  UNION ALL
    SELECT p.sub_part, p.part, p.quantity
    FROM included_parts pr, parts p
    WHERE p.part = pr.sub_part
  )
SELECT sub_part, SUM(quantity) as total_quantity
FROM included_parts
GROUP BY sub_part
Right
  (With{qeWithRecursive = True,
        qeViews =
          [(Alias (Name "included_parts")
              (Just [Name "sub_part", Name "part", Name "quantity"]),
            CombineQueryExpr{qe0 =
                               Select{qeSetQuantifier = SQDefault,
                                      qeSelectList =
                                        [(Iden [Name "sub_part"], Nothing),
                                         (Iden [Name "part"], Nothing),
                                         (Iden [Name "quantity"], Nothing)],
                                      qeFrom = [TRSimple [Name "parts"]],
                                      qeWhere =
                                        Just
                                          (BinOp (Iden [Name "part"]) [Name "="]
                                             (StringLit "our_product")),
                                      qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
                                      qeOffset = Nothing, qeFetchFirst = Nothing},
                             qeCombOp = Union, qeSetQuantifier = All,
                             qeCorresponding = Respectively,
                             qe1 =
                               Select{qeSetQuantifier = SQDefault,
                                      qeSelectList =
                                        [(Iden [Name "p", Name "sub_part"], Nothing),
                                         (Iden [Name "p", Name "part"], Nothing),
                                         (Iden [Name "p", Name "quantity"], Nothing)],
                                      qeFrom =
                                        [TRAlias (TRSimple [Name "included_parts"])
                                           (Alias (Name "pr") Nothing),
                                         TRAlias (TRSimple [Name "parts"])
                                           (Alias (Name "p") Nothing)],
                                      qeWhere =
                                        Just
                                          (BinOp (Iden [Name "p", Name "part"]) [Name "="]
                                             (Iden [Name "pr", Name "sub_part"])),
                                      qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
                                      qeOffset = Nothing, qeFetchFirst = Nothing}})],
        qeQueryExpression =
          Select{qeSetQuantifier = SQDefault,
                 qeSelectList =
                   [(Iden [Name "sub_part"], Nothing),
                    (App [Name "SUM"] [Iden [Name "quantity"]],
                     Just (Name "total_quantity"))],
                 qeFrom = [TRSimple [Name "included_parts"]], qeWhere = Nothing,
                 qeGroupBy = [SimpleGroup (Iden [Name "sub_part"])],
                 qeHaving = Nothing, qeOrderBy = [], qeOffset = Nothing,
                 qeFetchFirst = Nothing}})
WITH RECURSIVE search_graph(id, link, data, depth) AS (
        SELECT g.id, g.link, g.data, 1
        FROM graph g
      UNION ALL
        SELECT g.id, g.link, g.data, sg.depth + 1
        FROM graph g, search_graph sg
        WHERE g.id = sg.link
)
SELECT * FROM search_graph;
Right
  (With{qeWithRecursive = True,
        qeViews =
          [(Alias (Name "search_graph")
              (Just [Name "id", Name "link", Name "data", Name "depth"]),
            CombineQueryExpr{qe0 =
                               Select{qeSetQuantifier = SQDefault,
                                      qeSelectList =
                                        [(Iden [Name "g", Name "id"], Nothing),
                                         (Iden [Name "g", Name "link"], Nothing),
                                         (Iden [Name "g", Name "data"], Nothing),
                                         (NumLit "1", Nothing)],
                                      qeFrom =
                                        [TRAlias (TRSimple [Name "graph"])
                                           (Alias (Name "g") Nothing)],
                                      qeWhere = Nothing, qeGroupBy = [], qeHaving = Nothing,
                                      qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing},
                             qeCombOp = Union, qeSetQuantifier = All,
                             qeCorresponding = Respectively,
                             qe1 =
                               Select{qeSetQuantifier = SQDefault,
                                      qeSelectList =
                                        [(Iden [Name "g", Name "id"], Nothing),
                                         (Iden [Name "g", Name "link"], Nothing),
                                         (Iden [Name "g", Name "data"], Nothing),
                                         (BinOp (Iden [Name "sg", Name "depth"]) [Name "+"]
                                            (NumLit "1"),
                                          Nothing)],
                                      qeFrom =
                                        [TRAlias (TRSimple [Name "graph"])
                                           (Alias (Name "g") Nothing),
                                         TRAlias (TRSimple [Name "search_graph"])
                                           (Alias (Name "sg") Nothing)],
                                      qeWhere =
                                        Just
                                          (BinOp (Iden [Name "g", Name "id"]) [Name "="]
                                             (Iden [Name "sg", Name "link"])),
                                      qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
                                      qeOffset = Nothing, qeFetchFirst = Nothing}})],
        qeQueryExpression =
          Select{qeSetQuantifier = SQDefault,
                 qeSelectList = [(Star, Nothing)],
                 qeFrom = [TRSimple [Name "search_graph"]], qeWhere = Nothing,
                 qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
                 qeOffset = Nothing, qeFetchFirst = Nothing}})
WITH RECURSIVE t(n) AS (
    SELECT 1
  UNION ALL
    SELECT n+1 FROM t
)
SELECT n FROM t --LIMIT 100;
Right
  (With{qeWithRecursive = True,
        qeViews =
          [(Alias (Name "t") (Just [Name "n"]),
            CombineQueryExpr{qe0 =
                               Select{qeSetQuantifier = SQDefault,
                                      qeSelectList = [(NumLit "1", Nothing)], qeFrom = [],
                                      qeWhere = Nothing, qeGroupBy = [], qeHaving = Nothing,
                                      qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing},
                             qeCombOp = Union, qeSetQuantifier = All,
                             qeCorresponding = Respectively,
                             qe1 =
                               Select{qeSetQuantifier = SQDefault,
                                      qeSelectList =
                                        [(BinOp (Iden [Name "n"]) [Name "+"] (NumLit "1"),
                                          Nothing)],
                                      qeFrom = [TRSimple [Name "t"]], qeWhere = Nothing,
                                      qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
                                      qeOffset = Nothing, qeFetchFirst = Nothing}})],
        qeQueryExpression =
          Select{qeSetQuantifier = SQDefault,
                 qeSelectList = [(Iden [Name "n"], Nothing)],
                 qeFrom = [TRSimple [Name "t"]], qeWhere = Nothing, qeGroupBy = [],
                 qeHaving = Nothing, qeOrderBy = [], qeOffset = Nothing,
                 qeFetchFirst = Nothing}})
SELECT f.title, f.did, d.name, f.date_prod, f.kind
    FROM distributors d, films f
    WHERE f.did = d.did
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList =
            [(Iden [Name "f", Name "title"], Nothing),
             (Iden [Name "f", Name "did"], Nothing),
             (Iden [Name "d", Name "name"], Nothing),
             (Iden [Name "f", Name "date_prod"], Nothing),
             (Iden [Name "f", Name "kind"], Nothing)],
          qeFrom =
            [TRAlias (TRSimple [Name "distributors"])
               (Alias (Name "d") Nothing),
             TRAlias (TRSimple [Name "films"]) (Alias (Name "f") Nothing)],
          qeWhere =
            Just
              (BinOp (Iden [Name "f", Name "did"]) [Name "="]
                 (Iden [Name "d", Name "did"])),
          qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
          qeOffset = Nothing, qeFetchFirst = Nothing})
SELECT kind, sum(len) AS total
    FROM films
    GROUP BY kind
    HAVING sum(len) < interval '5 hours';
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList =
            [(Iden [Name "kind"], Nothing),
             (App [Name "sum"] [Iden [Name "len"]], Just (Name "total"))],
          qeFrom = [TRSimple [Name "films"]], qeWhere = Nothing,
          qeGroupBy = [SimpleGroup (Iden [Name "kind"])],
          qeHaving =
            Just
              (BinOp (App [Name "sum"] [Iden [Name "len"]]) [Name "<"]
                 (TypedLit (TypeName [Name "interval"]) "5 hours")),
          qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing})
SELECT * FROM distributors ORDER BY name;
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList = [(Star, Nothing)],
          qeFrom = [TRSimple [Name "distributors"]], qeWhere = Nothing,
          qeGroupBy = [], qeHaving = Nothing,
          qeOrderBy =
            [SortSpec (Iden [Name "name"]) DirDefault NullsOrderDefault],
          qeOffset = Nothing, qeFetchFirst = Nothing})
SELECT * FROM distributors ORDER BY 2;
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList = [(Star, Nothing)],
          qeFrom = [TRSimple [Name "distributors"]], qeWhere = Nothing,
          qeGroupBy = [], qeHaving = Nothing,
          qeOrderBy = [SortSpec (NumLit "2") DirDefault NullsOrderDefault],
          qeOffset = Nothing, qeFetchFirst = Nothing})
SELECT distributors.name
    FROM distributors
    WHERE distributors.name LIKE 'W%'
UNION
SELECT actors.name
    FROM actors
    WHERE actors.name LIKE 'W%';
Right
  (CombineQueryExpr{qe0 =
                      Select{qeSetQuantifier = SQDefault,
                             qeSelectList =
                               [(Iden [Name "distributors", Name "name"], Nothing)],
                             qeFrom = [TRSimple [Name "distributors"]],
                             qeWhere =
                               Just
                                 (BinOp (Iden [Name "distributors", Name "name"]) [Name "like"]
                                    (StringLit "W%")),
                             qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
                             qeOffset = Nothing, qeFetchFirst = Nothing},
                    qeCombOp = Union, qeSetQuantifier = SQDefault,
                    qeCorresponding = Respectively,
                    qe1 =
                      Select{qeSetQuantifier = SQDefault,
                             qeSelectList = [(Iden [Name "actors", Name "name"], Nothing)],
                             qeFrom = [TRSimple [Name "actors"]],
                             qeWhere =
                               Just
                                 (BinOp (Iden [Name "actors", Name "name"]) [Name "like"]
                                    (StringLit "W%")),
                             qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
                             qeOffset = Nothing, qeFetchFirst = Nothing}})
WITH t AS (
    SELECT random() as x FROM generate_series(1, 3)
  )
SELECT * FROM t
UNION ALL
SELECT * FROM t
Right
  (With{qeWithRecursive = False,
        qeViews =
          [(Alias (Name "t") Nothing,
            Select{qeSetQuantifier = SQDefault,
                   qeSelectList = [(App [Name "random"] [], Just (Name "x"))],
                   qeFrom =
                     [TRFunction [Name "generate_series"] [NumLit "1", NumLit "3"]],
                   qeWhere = Nothing, qeGroupBy = [], qeHaving = Nothing,
                   qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing})],
        qeQueryExpression =
          CombineQueryExpr{qe0 =
                             Select{qeSetQuantifier = SQDefault,
                                    qeSelectList = [(Star, Nothing)],
                                    qeFrom = [TRSimple [Name "t"]], qeWhere = Nothing,
                                    qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
                                    qeOffset = Nothing, qeFetchFirst = Nothing},
                           qeCombOp = Union, qeSetQuantifier = All,
                           qeCorresponding = Respectively,
                           qe1 =
                             Select{qeSetQuantifier = SQDefault,
                                    qeSelectList = [(Star, Nothing)],
                                    qeFrom = [TRSimple [Name "t"]], qeWhere = Nothing,
                                    qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
                                    qeOffset = Nothing, qeFetchFirst = Nothing}}})
WITH RECURSIVE employee_recursive(distance, employee_name, manager_name) AS (
    SELECT 1, employee_name, manager_name
    FROM employee
    WHERE manager_name = 'Mary'
  UNION ALL
    SELECT er.distance + 1, e.employee_name, e.manager_name
    FROM employee_recursive er, employee e
    WHERE er.employee_name = e.manager_name
  )
SELECT distance, employee_name FROM employee_recursive;
Right
  (With{qeWithRecursive = True,
        qeViews =
          [(Alias (Name "employee_recursive")
              (Just
                 [Name "distance", Name "employee_name", Name "manager_name"]),
            CombineQueryExpr{qe0 =
                               Select{qeSetQuantifier = SQDefault,
                                      qeSelectList =
                                        [(NumLit "1", Nothing),
                                         (Iden [Name "employee_name"], Nothing),
                                         (Iden [Name "manager_name"], Nothing)],
                                      qeFrom = [TRSimple [Name "employee"]],
                                      qeWhere =
                                        Just
                                          (BinOp (Iden [Name "manager_name"]) [Name "="]
                                             (StringLit "Mary")),
                                      qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
                                      qeOffset = Nothing, qeFetchFirst = Nothing},
                             qeCombOp = Union, qeSetQuantifier = All,
                             qeCorresponding = Respectively,
                             qe1 =
                               Select{qeSetQuantifier = SQDefault,
                                      qeSelectList =
                                        [(BinOp (Iden [Name "er", Name "distance"]) [Name "+"]
                                            (NumLit "1"),
                                          Nothing),
                                         (Iden [Name "e", Name "employee_name"], Nothing),
                                         (Iden [Name "e", Name "manager_name"], Nothing)],
                                      qeFrom =
                                        [TRAlias (TRSimple [Name "employee_recursive"])
                                           (Alias (Name "er") Nothing),
                                         TRAlias (TRSimple [Name "employee"])
                                           (Alias (Name "e") Nothing)],
                                      qeWhere =
                                        Just
                                          (BinOp (Iden [Name "er", Name "employee_name"]) [Name "="]
                                             (Iden [Name "e", Name "manager_name"])),
                                      qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
                                      qeOffset = Nothing, qeFetchFirst = Nothing}})],
        qeQueryExpression =
          Select{qeSetQuantifier = SQDefault,
                 qeSelectList =
                   [(Iden [Name "distance"], Nothing),
                    (Iden [Name "employee_name"], Nothing)],
                 qeFrom = [TRSimple [Name "employee_recursive"]], qeWhere = Nothing,
                 qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
                 qeOffset = Nothing, qeFetchFirst = Nothing}})
SELECT m.name AS mname, pname
FROM manufacturers m, LATERAL get_product_names(m.id) pname;
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList =
            [(Iden [Name "m", Name "name"], Just (Name "mname")),
             (Iden [Name "pname"], Nothing)],
          qeFrom =
            [TRAlias (TRSimple [Name "manufacturers"])
               (Alias (Name "m") Nothing),
             TRLateral
               (TRAlias
                  (TRFunction [Name "get_product_names"]
                     [Iden [Name "m", Name "id"]])
                  (Alias (Name "pname") Nothing))],
          qeWhere = Nothing, qeGroupBy = [], qeHaving = Nothing,
          qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing})
SELECT m.name AS mname, pname
FROM manufacturers m LEFT JOIN LATERAL get_product_names(m.id) pname ON true;
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList =
            [(Iden [Name "m", Name "name"], Just (Name "mname")),
             (Iden [Name "pname"], Nothing)],
          qeFrom =
            [TRJoin
               (TRAlias (TRSimple [Name "manufacturers"])
                  (Alias (Name "m") Nothing))
               False
               JLeft
               (TRLateral
                  (TRAlias
                     (TRFunction [Name "get_product_names"]
                        [Iden [Name "m", Name "id"]])
                     (Alias (Name "pname") Nothing)))
               (Just (JoinOn (Iden [Name "true"])))],
          qeWhere = Nothing, qeGroupBy = [], qeHaving = Nothing,
          qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing})
SELECT 2+2;
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList =
            [(BinOp (NumLit "2") [Name "+"] (NumLit "2"), Nothing)],
          qeFrom = [], qeWhere = Nothing, qeGroupBy = [], qeHaving = Nothing,
          qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing})

parse tpch


select
        l_returnflag,
        l_linestatus,
        sum(l_quantity) as sum_qty,
        sum(l_extendedprice) as sum_base_price,
        sum(l_extendedprice * (1 - l_discount)) as sum_disc_price,
        sum(l_extendedprice * (1 - l_discount) * (1 + l_tax)) as sum_charge,
        avg(l_quantity) as avg_qty,
        avg(l_extendedprice) as avg_price,
        avg(l_discount) as avg_disc,
        count(*) as count_order
from
        lineitem
where
        l_shipdate <= date '1998-12-01' - interval '63' day (3)
group by
        l_returnflag,
        l_linestatus
order by
        l_returnflag,
        l_linestatus
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList =
            [(Iden [Name "l_returnflag"], Nothing),
             (Iden [Name "l_linestatus"], Nothing),
             (App [Name "sum"] [Iden [Name "l_quantity"]],
              Just (Name "sum_qty")),
             (App [Name "sum"] [Iden [Name "l_extendedprice"]],
              Just (Name "sum_base_price")),
             (App [Name "sum"]
                [BinOp (Iden [Name "l_extendedprice"]) [Name "*"]
                   (Parens
                      (BinOp (NumLit "1") [Name "-"] (Iden [Name "l_discount"])))],
              Just (Name "sum_disc_price")),
             (App [Name "sum"]
                [BinOp
                   (BinOp (Iden [Name "l_extendedprice"]) [Name "*"]
                      (Parens
                         (BinOp (NumLit "1") [Name "-"] (Iden [Name "l_discount"]))))
                   [Name "*"]
                   (Parens (BinOp (NumLit "1") [Name "+"] (Iden [Name "l_tax"])))],
              Just (Name "sum_charge")),
             (App [Name "avg"] [Iden [Name "l_quantity"]],
              Just (Name "avg_qty")),
             (App [Name "avg"] [Iden [Name "l_extendedprice"]],
              Just (Name "avg_price")),
             (App [Name "avg"] [Iden [Name "l_discount"]],
              Just (Name "avg_disc")),
             (App [Name "count"] [Star], Just (Name "count_order"))],
          qeFrom = [TRSimple [Name "lineitem"]],
          qeWhere =
            Just
              (BinOp (Iden [Name "l_shipdate"]) [Name "<="]
                 (BinOp (TypedLit (TypeName [Name "date"]) "1998-12-01") [Name "-"]
                    (IntervalLit{ilSign = Nothing, ilLiteral = "63",
                                 ilFrom = Itf "day" (Just (3, Nothing)), ilTo = Nothing}))),
          qeGroupBy =
            [SimpleGroup (Iden [Name "l_returnflag"]),
             SimpleGroup (Iden [Name "l_linestatus"])],
          qeHaving = Nothing,
          qeOrderBy =
            [SortSpec (Iden [Name "l_returnflag"]) DirDefault
               NullsOrderDefault,
             SortSpec (Iden [Name "l_linestatus"]) DirDefault
               NullsOrderDefault],
          qeOffset = Nothing, qeFetchFirst = Nothing})

select
        s_acctbal,
        s_name,
        n_name,
        p_partkey,
        p_mfgr,
        s_address,
        s_phone,
        s_comment
from
        part,
        supplier,
        partsupp,
        nation,
        region
where
        p_partkey = ps_partkey
        and s_suppkey = ps_suppkey
        and p_size = 15
        and p_type like '%BRASS'
        and s_nationkey = n_nationkey
        and n_regionkey = r_regionkey
        and r_name = 'EUROPE'
        and ps_supplycost = (
                select
                        min(ps_supplycost)
                from
                        partsupp,
                        supplier,
                        nation,
                        region
                where
                        p_partkey = ps_partkey
                        and s_suppkey = ps_suppkey
                        and s_nationkey = n_nationkey
                        and n_regionkey = r_regionkey
                        and r_name = 'EUROPE'
        )
order by
        s_acctbal desc,
        n_name,
        s_name,
        p_partkey
fetch first 100 rows only
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList =
            [(Iden [Name "s_acctbal"], Nothing),
             (Iden [Name "s_name"], Nothing), (Iden [Name "n_name"], Nothing),
             (Iden [Name "p_partkey"], Nothing),
             (Iden [Name "p_mfgr"], Nothing),
             (Iden [Name "s_address"], Nothing),
             (Iden [Name "s_phone"], Nothing),
             (Iden [Name "s_comment"], Nothing)],
          qeFrom =
            [TRSimple [Name "part"], TRSimple [Name "supplier"],
             TRSimple [Name "partsupp"], TRSimple [Name "nation"],
             TRSimple [Name "region"]],
          qeWhere =
            Just
              (BinOp
                 (BinOp
                    (BinOp
                       (BinOp
                          (BinOp
                             (BinOp
                                (BinOp
                                   (BinOp (Iden [Name "p_partkey"]) [Name "="]
                                      (Iden [Name "ps_partkey"]))
                                   [Name "and"]
                                   (BinOp (Iden [Name "s_suppkey"]) [Name "="]
                                      (Iden [Name "ps_suppkey"])))
                                [Name "and"]
                                (BinOp (Iden [Name "p_size"]) [Name "="] (NumLit "15")))
                             [Name "and"]
                             (BinOp (Iden [Name "p_type"]) [Name "like"] (StringLit "%BRASS")))
                          [Name "and"]
                          (BinOp (Iden [Name "s_nationkey"]) [Name "="]
                             (Iden [Name "n_nationkey"])))
                       [Name "and"]
                       (BinOp (Iden [Name "n_regionkey"]) [Name "="]
                          (Iden [Name "r_regionkey"])))
                    [Name "and"]
                    (BinOp (Iden [Name "r_name"]) [Name "="] (StringLit "EUROPE")))
                 [Name "and"]
                 (BinOp (Iden [Name "ps_supplycost"]) [Name "="]
                    (SubQueryExpr SqSq
                       (Select{qeSetQuantifier = SQDefault,
                               qeSelectList =
                                 [(App [Name "min"] [Iden [Name "ps_supplycost"]], Nothing)],
                               qeFrom =
                                 [TRSimple [Name "partsupp"], TRSimple [Name "supplier"],
                                  TRSimple [Name "nation"], TRSimple [Name "region"]],
                               qeWhere =
                                 Just
                                   (BinOp
                                      (BinOp
                                         (BinOp
                                            (BinOp
                                               (BinOp (Iden [Name "p_partkey"]) [Name "="]
                                                  (Iden [Name "ps_partkey"]))
                                               [Name "and"]
                                               (BinOp (Iden [Name "s_suppkey"]) [Name "="]
                                                  (Iden [Name "ps_suppkey"])))
                                            [Name "and"]
                                            (BinOp (Iden [Name "s_nationkey"]) [Name "="]
                                               (Iden [Name "n_nationkey"])))
                                         [Name "and"]
                                         (BinOp (Iden [Name "n_regionkey"]) [Name "="]
                                            (Iden [Name "r_regionkey"])))
                                      [Name "and"]
                                      (BinOp (Iden [Name "r_name"]) [Name "="]
                                         (StringLit "EUROPE"))),
                               qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
                               qeOffset = Nothing, qeFetchFirst = Nothing})))),
          qeGroupBy = [], qeHaving = Nothing,
          qeOrderBy =
            [SortSpec (Iden [Name "s_acctbal"]) Desc NullsOrderDefault,
             SortSpec (Iden [Name "n_name"]) DirDefault NullsOrderDefault,
             SortSpec (Iden [Name "s_name"]) DirDefault NullsOrderDefault,
             SortSpec (Iden [Name "p_partkey"]) DirDefault NullsOrderDefault],
          qeOffset = Nothing, qeFetchFirst = Just (NumLit "100")})

 select
         l_orderkey,
         sum(l_extendedprice * (1 - l_discount)) as revenue,
         o_orderdate,
         o_shippriority
 from
         customer,
         orders,
         lineitem
 where
         c_mktsegment = 'MACHINERY'
         and c_custkey = o_custkey
         and l_orderkey = o_orderkey
         and o_orderdate < date '1995-03-21'
         and l_shipdate > date '1995-03-21'
 group by
         l_orderkey,
         o_orderdate,
         o_shippriority
 order by
         revenue desc,
         o_orderdate
 fetch first 10 rows only
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList =
            [(Iden [Name "l_orderkey"], Nothing),
             (App [Name "sum"]
                [BinOp (Iden [Name "l_extendedprice"]) [Name "*"]
                   (Parens
                      (BinOp (NumLit "1") [Name "-"] (Iden [Name "l_discount"])))],
              Just (Name "revenue")),
             (Iden [Name "o_orderdate"], Nothing),
             (Iden [Name "o_shippriority"], Nothing)],
          qeFrom =
            [TRSimple [Name "customer"], TRSimple [Name "orders"],
             TRSimple [Name "lineitem"]],
          qeWhere =
            Just
              (BinOp
                 (BinOp
                    (BinOp
                       (BinOp
                          (BinOp (Iden [Name "c_mktsegment"]) [Name "="]
                             (StringLit "MACHINERY"))
                          [Name "and"]
                          (BinOp (Iden [Name "c_custkey"]) [Name "="]
                             (Iden [Name "o_custkey"])))
                       [Name "and"]
                       (BinOp (Iden [Name "l_orderkey"]) [Name "="]
                          (Iden [Name "o_orderkey"])))
                    [Name "and"]
                    (BinOp (Iden [Name "o_orderdate"]) [Name "<"]
                       (TypedLit (TypeName [Name "date"]) "1995-03-21")))
                 [Name "and"]
                 (BinOp (Iden [Name "l_shipdate"]) [Name ">"]
                    (TypedLit (TypeName [Name "date"]) "1995-03-21"))),
          qeGroupBy =
            [SimpleGroup (Iden [Name "l_orderkey"]),
             SimpleGroup (Iden [Name "o_orderdate"]),
             SimpleGroup (Iden [Name "o_shippriority"])],
          qeHaving = Nothing,
          qeOrderBy =
            [SortSpec (Iden [Name "revenue"]) Desc NullsOrderDefault,
             SortSpec (Iden [Name "o_orderdate"]) DirDefault NullsOrderDefault],
          qeOffset = Nothing, qeFetchFirst = Just (NumLit "10")})

 select
         o_orderpriority,
         count(*) as order_count
 from
         orders
 where
         o_orderdate >= date '1996-03-01'
         and o_orderdate < date '1996-03-01' + interval '3' month
         and exists (
                 select
                         *
                 from
                         lineitem
                 where
                         l_orderkey = o_orderkey
                         and l_commitdate < l_receiptdate
         )
 group by
         o_orderpriority
 order by
         o_orderpriority
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList =
            [(Iden [Name "o_orderpriority"], Nothing),
             (App [Name "count"] [Star], Just (Name "order_count"))],
          qeFrom = [TRSimple [Name "orders"]],
          qeWhere =
            Just
              (BinOp
                 (BinOp
                    (BinOp (Iden [Name "o_orderdate"]) [Name ">="]
                       (TypedLit (TypeName [Name "date"]) "1996-03-01"))
                    [Name "and"]
                    (BinOp (Iden [Name "o_orderdate"]) [Name "<"]
                       (BinOp (TypedLit (TypeName [Name "date"]) "1996-03-01") [Name "+"]
                          (IntervalLit{ilSign = Nothing, ilLiteral = "3",
                                       ilFrom = Itf "month" Nothing, ilTo = Nothing}))))
                 [Name "and"]
                 (SubQueryExpr SqExists
                    (Select{qeSetQuantifier = SQDefault,
                            qeSelectList = [(Star, Nothing)],
                            qeFrom = [TRSimple [Name "lineitem"]],
                            qeWhere =
                              Just
                                (BinOp
                                   (BinOp (Iden [Name "l_orderkey"]) [Name "="]
                                      (Iden [Name "o_orderkey"]))
                                   [Name "and"]
                                   (BinOp (Iden [Name "l_commitdate"]) [Name "<"]
                                      (Iden [Name "l_receiptdate"]))),
                            qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
                            qeOffset = Nothing, qeFetchFirst = Nothing}))),
          qeGroupBy = [SimpleGroup (Iden [Name "o_orderpriority"])],
          qeHaving = Nothing,
          qeOrderBy =
            [SortSpec (Iden [Name "o_orderpriority"]) DirDefault
               NullsOrderDefault],
          qeOffset = Nothing, qeFetchFirst = Nothing})

 select
         n_name,
         sum(l_extendedprice * (1 - l_discount)) as revenue
 from
         customer,
         orders,
         lineitem,
         supplier,
         nation,
         region
 where
         c_custkey = o_custkey
         and l_orderkey = o_orderkey
         and l_suppkey = s_suppkey
         and c_nationkey = s_nationkey
         and s_nationkey = n_nationkey
         and n_regionkey = r_regionkey
         and r_name = 'EUROPE'
         and o_orderdate >= date '1997-01-01'
         and o_orderdate < date '1997-01-01' + interval '1' year
 group by
         n_name
 order by
         revenue desc
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList =
            [(Iden [Name "n_name"], Nothing),
             (App [Name "sum"]
                [BinOp (Iden [Name "l_extendedprice"]) [Name "*"]
                   (Parens
                      (BinOp (NumLit "1") [Name "-"] (Iden [Name "l_discount"])))],
              Just (Name "revenue"))],
          qeFrom =
            [TRSimple [Name "customer"], TRSimple [Name "orders"],
             TRSimple [Name "lineitem"], TRSimple [Name "supplier"],
             TRSimple [Name "nation"], TRSimple [Name "region"]],
          qeWhere =
            Just
              (BinOp
                 (BinOp
                    (BinOp
                       (BinOp
                          (BinOp
                             (BinOp
                                (BinOp
                                   (BinOp
                                      (BinOp (Iden [Name "c_custkey"]) [Name "="]
                                         (Iden [Name "o_custkey"]))
                                      [Name "and"]
                                      (BinOp (Iden [Name "l_orderkey"]) [Name "="]
                                         (Iden [Name "o_orderkey"])))
                                   [Name "and"]
                                   (BinOp (Iden [Name "l_suppkey"]) [Name "="]
                                      (Iden [Name "s_suppkey"])))
                                [Name "and"]
                                (BinOp (Iden [Name "c_nationkey"]) [Name "="]
                                   (Iden [Name "s_nationkey"])))
                             [Name "and"]
                             (BinOp (Iden [Name "s_nationkey"]) [Name "="]
                                (Iden [Name "n_nationkey"])))
                          [Name "and"]
                          (BinOp (Iden [Name "n_regionkey"]) [Name "="]
                             (Iden [Name "r_regionkey"])))
                       [Name "and"]
                       (BinOp (Iden [Name "r_name"]) [Name "="] (StringLit "EUROPE")))
                    [Name "and"]
                    (BinOp (Iden [Name "o_orderdate"]) [Name ">="]
                       (TypedLit (TypeName [Name "date"]) "1997-01-01")))
                 [Name "and"]
                 (BinOp (Iden [Name "o_orderdate"]) [Name "<"]
                    (BinOp (TypedLit (TypeName [Name "date"]) "1997-01-01") [Name "+"]
                       (IntervalLit{ilSign = Nothing, ilLiteral = "1",
                                    ilFrom = Itf "year" Nothing, ilTo = Nothing})))),
          qeGroupBy = [SimpleGroup (Iden [Name "n_name"])],
          qeHaving = Nothing,
          qeOrderBy =
            [SortSpec (Iden [Name "revenue"]) Desc NullsOrderDefault],
          qeOffset = Nothing, qeFetchFirst = Nothing})

 select
         sum(l_extendedprice * l_discount) as revenue
 from
         lineitem
 where
         l_shipdate >= date '1997-01-01'
         and l_shipdate < date '1997-01-01' + interval '1' year
         and l_discount between 0.07 - 0.01 and 0.07 + 0.01
         and l_quantity < 24
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList =
            [(App [Name "sum"]
                [BinOp (Iden [Name "l_extendedprice"]) [Name "*"]
                   (Iden [Name "l_discount"])],
              Just (Name "revenue"))],
          qeFrom = [TRSimple [Name "lineitem"]],
          qeWhere =
            Just
              (BinOp
                 (BinOp
                    (BinOp
                       (BinOp (Iden [Name "l_shipdate"]) [Name ">="]
                          (TypedLit (TypeName [Name "date"]) "1997-01-01"))
                       [Name "and"]
                       (BinOp (Iden [Name "l_shipdate"]) [Name "<"]
                          (BinOp (TypedLit (TypeName [Name "date"]) "1997-01-01") [Name "+"]
                             (IntervalLit{ilSign = Nothing, ilLiteral = "1",
                                          ilFrom = Itf "year" Nothing, ilTo = Nothing}))))
                    [Name "and"]
                    (SpecialOp [Name "between"]
                       [Iden [Name "l_discount"],
                        BinOp (NumLit "0.07") [Name "-"] (NumLit "0.01"),
                        BinOp (NumLit "0.07") [Name "+"] (NumLit "0.01")]))
                 [Name "and"]
                 (BinOp (Iden [Name "l_quantity"]) [Name "<"] (NumLit "24"))),
          qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
          qeOffset = Nothing, qeFetchFirst = Nothing})

 select
         supp_nation,
         cust_nation,
         l_year,
         sum(volume) as revenue
 from
         (
                 select
                         n1.n_name as supp_nation,
                         n2.n_name as cust_nation,
                         extract(year from l_shipdate) as l_year,
                         l_extendedprice * (1 - l_discount) as volume
                 from
                         supplier,
                         lineitem,
                         orders,
                         customer,
                         nation n1,
                         nation n2
                 where
                         s_suppkey = l_suppkey
                         and o_orderkey = l_orderkey
                         and c_custkey = o_custkey
                         and s_nationkey = n1.n_nationkey
                         and c_nationkey = n2.n_nationkey
                         and (
                                 (n1.n_name = 'PERU' and n2.n_name = 'IRAQ')
                                 or (n1.n_name = 'IRAQ' and n2.n_name = 'PERU')
                         )
                         and l_shipdate between date '1995-01-01' and date '1996-12-31'
         ) as shipping
 group by
         supp_nation,
         cust_nation,
         l_year
 order by
         supp_nation,
         cust_nation,
         l_year
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList =
            [(Iden [Name "supp_nation"], Nothing),
             (Iden [Name "cust_nation"], Nothing),
             (Iden [Name "l_year"], Nothing),
             (App [Name "sum"] [Iden [Name "volume"]], Just (Name "revenue"))],
          qeFrom =
            [TRAlias
               (TRQueryExpr
                  (Select{qeSetQuantifier = SQDefault,
                          qeSelectList =
                            [(Iden [Name "n1", Name "n_name"], Just (Name "supp_nation")),
                             (Iden [Name "n2", Name "n_name"], Just (Name "cust_nation")),
                             (SpecialOpK [Name "extract"] (Just (Iden [Name "year"]))
                                [("from", Iden [Name "l_shipdate"])],
                              Just (Name "l_year")),
                             (BinOp (Iden [Name "l_extendedprice"]) [Name "*"]
                                (Parens
                                   (BinOp (NumLit "1") [Name "-"] (Iden [Name "l_discount"]))),
                              Just (Name "volume"))],
                          qeFrom =
                            [TRSimple [Name "supplier"], TRSimple [Name "lineitem"],
                             TRSimple [Name "orders"], TRSimple [Name "customer"],
                             TRAlias (TRSimple [Name "nation"]) (Alias (Name "n1") Nothing),
                             TRAlias (TRSimple [Name "nation"]) (Alias (Name "n2") Nothing)],
                          qeWhere =
                            Just
                              (BinOp
                                 (BinOp
                                    (BinOp
                                       (BinOp
                                          (BinOp
                                             (BinOp
                                                (BinOp (Iden [Name "s_suppkey"]) [Name "="]
                                                   (Iden [Name "l_suppkey"]))
                                                [Name "and"]
                                                (BinOp (Iden [Name "o_orderkey"]) [Name "="]
                                                   (Iden [Name "l_orderkey"])))
                                             [Name "and"]
                                             (BinOp (Iden [Name "c_custkey"]) [Name "="]
                                                (Iden [Name "o_custkey"])))
                                          [Name "and"]
                                          (BinOp (Iden [Name "s_nationkey"]) [Name "="]
                                             (Iden [Name "n1", Name "n_nationkey"])))
                                       [Name "and"]
                                       (BinOp (Iden [Name "c_nationkey"]) [Name "="]
                                          (Iden [Name "n2", Name "n_nationkey"])))
                                    [Name "and"]
                                    (Parens
                                       (BinOp
                                          (Parens
                                             (BinOp
                                                (BinOp (Iden [Name "n1", Name "n_name"]) [Name "="]
                                                   (StringLit "PERU"))
                                                [Name "and"]
                                                (BinOp (Iden [Name "n2", Name "n_name"]) [Name "="]
                                                   (StringLit "IRAQ"))))
                                          [Name "or"]
                                          (Parens
                                             (BinOp
                                                (BinOp (Iden [Name "n1", Name "n_name"]) [Name "="]
                                                   (StringLit "IRAQ"))
                                                [Name "and"]
                                                (BinOp (Iden [Name "n2", Name "n_name"]) [Name "="]
                                                   (StringLit "PERU")))))))
                                 [Name "and"]
                                 (SpecialOp [Name "between"]
                                    [Iden [Name "l_shipdate"],
                                     TypedLit (TypeName [Name "date"]) "1995-01-01",
                                     TypedLit (TypeName [Name "date"]) "1996-12-31"])),
                          qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
                          qeOffset = Nothing, qeFetchFirst = Nothing}))
               (Alias (Name "shipping") Nothing)],
          qeWhere = Nothing,
          qeGroupBy =
            [SimpleGroup (Iden [Name "supp_nation"]),
             SimpleGroup (Iden [Name "cust_nation"]),
             SimpleGroup (Iden [Name "l_year"])],
          qeHaving = Nothing,
          qeOrderBy =
            [SortSpec (Iden [Name "supp_nation"]) DirDefault NullsOrderDefault,
             SortSpec (Iden [Name "cust_nation"]) DirDefault NullsOrderDefault,
             SortSpec (Iden [Name "l_year"]) DirDefault NullsOrderDefault],
          qeOffset = Nothing, qeFetchFirst = Nothing})

 select
         o_year,
         sum(case
                 when nation = 'IRAQ' then volume
                 else 0
         end) / sum(volume) as mkt_share
 from
         (
                 select
                         extract(year from o_orderdate) as o_year,
                         l_extendedprice * (1 - l_discount) as volume,
                         n2.n_name as nation
                 from
                         part,
                         supplier,
                         lineitem,
                         orders,
                         customer,
                         nation n1,
                         nation n2,
                         region
                 where
                         p_partkey = l_partkey
                         and s_suppkey = l_suppkey
                         and l_orderkey = o_orderkey
                         and o_custkey = c_custkey
                         and c_nationkey = n1.n_nationkey
                         and n1.n_regionkey = r_regionkey
                         and r_name = 'MIDDLE EAST'
                         and s_nationkey = n2.n_nationkey
                         and o_orderdate between date '1995-01-01' and date '1996-12-31'
                         and p_type = 'STANDARD ANODIZED BRASS'
         ) as all_nations
 group by
         o_year
 order by
         o_year
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList =
            [(Iden [Name "o_year"], Nothing),
             (BinOp
                (App [Name "sum"]
                   [Case{caseTest = Nothing,
                         caseWhens =
                           [([BinOp (Iden [Name "nation"]) [Name "="] (StringLit "IRAQ")],
                             Iden [Name "volume"])],
                         caseElse = Just (NumLit "0")}])
                [Name "/"]
                (App [Name "sum"] [Iden [Name "volume"]]),
              Just (Name "mkt_share"))],
          qeFrom =
            [TRAlias
               (TRQueryExpr
                  (Select{qeSetQuantifier = SQDefault,
                          qeSelectList =
                            [(SpecialOpK [Name "extract"] (Just (Iden [Name "year"]))
                                [("from", Iden [Name "o_orderdate"])],
                              Just (Name "o_year")),
                             (BinOp (Iden [Name "l_extendedprice"]) [Name "*"]
                                (Parens
                                   (BinOp (NumLit "1") [Name "-"] (Iden [Name "l_discount"]))),
                              Just (Name "volume")),
                             (Iden [Name "n2", Name "n_name"], Just (Name "nation"))],
                          qeFrom =
                            [TRSimple [Name "part"], TRSimple [Name "supplier"],
                             TRSimple [Name "lineitem"], TRSimple [Name "orders"],
                             TRSimple [Name "customer"],
                             TRAlias (TRSimple [Name "nation"]) (Alias (Name "n1") Nothing),
                             TRAlias (TRSimple [Name "nation"]) (Alias (Name "n2") Nothing),
                             TRSimple [Name "region"]],
                          qeWhere =
                            Just
                              (BinOp
                                 (BinOp
                                    (BinOp
                                       (BinOp
                                          (BinOp
                                             (BinOp
                                                (BinOp
                                                   (BinOp
                                                      (BinOp
                                                         (BinOp (Iden [Name "p_partkey"]) [Name "="]
                                                            (Iden [Name "l_partkey"]))
                                                         [Name "and"]
                                                         (BinOp (Iden [Name "s_suppkey"]) [Name "="]
                                                            (Iden [Name "l_suppkey"])))
                                                      [Name "and"]
                                                      (BinOp (Iden [Name "l_orderkey"]) [Name "="]
                                                         (Iden [Name "o_orderkey"])))
                                                   [Name "and"]
                                                   (BinOp (Iden [Name "o_custkey"]) [Name "="]
                                                      (Iden [Name "c_custkey"])))
                                                [Name "and"]
                                                (BinOp (Iden [Name "c_nationkey"]) [Name "="]
                                                   (Iden [Name "n1", Name "n_nationkey"])))
                                             [Name "and"]
                                             (BinOp (Iden [Name "n1", Name "n_regionkey"])
                                                [Name "="]
                                                (Iden [Name "r_regionkey"])))
                                          [Name "and"]
                                          (BinOp (Iden [Name "r_name"]) [Name "="]
                                             (StringLit "MIDDLE EAST")))
                                       [Name "and"]
                                       (BinOp (Iden [Name "s_nationkey"]) [Name "="]
                                          (Iden [Name "n2", Name "n_nationkey"])))
                                    [Name "and"]
                                    (SpecialOp [Name "between"]
                                       [Iden [Name "o_orderdate"],
                                        TypedLit (TypeName [Name "date"]) "1995-01-01",
                                        TypedLit (TypeName [Name "date"]) "1996-12-31"]))
                                 [Name "and"]
                                 (BinOp (Iden [Name "p_type"]) [Name "="]
                                    (StringLit "STANDARD ANODIZED BRASS"))),
                          qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
                          qeOffset = Nothing, qeFetchFirst = Nothing}))
               (Alias (Name "all_nations") Nothing)],
          qeWhere = Nothing,
          qeGroupBy = [SimpleGroup (Iden [Name "o_year"])],
          qeHaving = Nothing,
          qeOrderBy =
            [SortSpec (Iden [Name "o_year"]) DirDefault NullsOrderDefault],
          qeOffset = Nothing, qeFetchFirst = Nothing})

 select
         nation,
         o_year,
         sum(amount) as sum_profit
 from
         (
                 select
                         n_name as nation,
                         extract(year from o_orderdate) as o_year,
                         l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity as amount
                 from
                         part,
                         supplier,
                         lineitem,
                         partsupp,
                         orders,
                         nation
                 where
                         s_suppkey = l_suppkey
                         and ps_suppkey = l_suppkey
                         and ps_partkey = l_partkey
                         and p_partkey = l_partkey
                         and o_orderkey = l_orderkey
                         and s_nationkey = n_nationkey
                         and p_name like '%antique%'
         ) as profit
 group by
         nation,
         o_year
 order by
         nation,
         o_year desc
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList =
            [(Iden [Name "nation"], Nothing), (Iden [Name "o_year"], Nothing),
             (App [Name "sum"] [Iden [Name "amount"]],
              Just (Name "sum_profit"))],
          qeFrom =
            [TRAlias
               (TRQueryExpr
                  (Select{qeSetQuantifier = SQDefault,
                          qeSelectList =
                            [(Iden [Name "n_name"], Just (Name "nation")),
                             (SpecialOpK [Name "extract"] (Just (Iden [Name "year"]))
                                [("from", Iden [Name "o_orderdate"])],
                              Just (Name "o_year")),
                             (BinOp
                                (BinOp (Iden [Name "l_extendedprice"]) [Name "*"]
                                   (Parens
                                      (BinOp (NumLit "1") [Name "-"] (Iden [Name "l_discount"]))))
                                [Name "-"]
                                (BinOp (Iden [Name "ps_supplycost"]) [Name "*"]
                                   (Iden [Name "l_quantity"])),
                              Just (Name "amount"))],
                          qeFrom =
                            [TRSimple [Name "part"], TRSimple [Name "supplier"],
                             TRSimple [Name "lineitem"], TRSimple [Name "partsupp"],
                             TRSimple [Name "orders"], TRSimple [Name "nation"]],
                          qeWhere =
                            Just
                              (BinOp
                                 (BinOp
                                    (BinOp
                                       (BinOp
                                          (BinOp
                                             (BinOp
                                                (BinOp (Iden [Name "s_suppkey"]) [Name "="]
                                                   (Iden [Name "l_suppkey"]))
                                                [Name "and"]
                                                (BinOp (Iden [Name "ps_suppkey"]) [Name "="]
                                                   (Iden [Name "l_suppkey"])))
                                             [Name "and"]
                                             (BinOp (Iden [Name "ps_partkey"]) [Name "="]
                                                (Iden [Name "l_partkey"])))
                                          [Name "and"]
                                          (BinOp (Iden [Name "p_partkey"]) [Name "="]
                                             (Iden [Name "l_partkey"])))
                                       [Name "and"]
                                       (BinOp (Iden [Name "o_orderkey"]) [Name "="]
                                          (Iden [Name "l_orderkey"])))
                                    [Name "and"]
                                    (BinOp (Iden [Name "s_nationkey"]) [Name "="]
                                       (Iden [Name "n_nationkey"])))
                                 [Name "and"]
                                 (BinOp (Iden [Name "p_name"]) [Name "like"]
                                    (StringLit "%antique%"))),
                          qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
                          qeOffset = Nothing, qeFetchFirst = Nothing}))
               (Alias (Name "profit") Nothing)],
          qeWhere = Nothing,
          qeGroupBy =
            [SimpleGroup (Iden [Name "nation"]),
             SimpleGroup (Iden [Name "o_year"])],
          qeHaving = Nothing,
          qeOrderBy =
            [SortSpec (Iden [Name "nation"]) DirDefault NullsOrderDefault,
             SortSpec (Iden [Name "o_year"]) Desc NullsOrderDefault],
          qeOffset = Nothing, qeFetchFirst = Nothing})

 select
         c_custkey,
         c_name,
         sum(l_extendedprice * (1 - l_discount)) as revenue,
         c_acctbal,
         n_name,
         c_address,
         c_phone,
         c_comment
 from
         customer,
         orders,
         lineitem,
         nation
 where
         c_custkey = o_custkey
         and l_orderkey = o_orderkey
         and o_orderdate >= date '1993-12-01'
         and o_orderdate < date '1993-12-01' + interval '3' month
         and l_returnflag = 'R'
         and c_nationkey = n_nationkey
 group by
         c_custkey,
         c_name,
         c_acctbal,
         c_phone,
         n_name,
         c_address,
         c_comment
 order by
         revenue desc
 fetch first 20 rows only
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList =
            [(Iden [Name "c_custkey"], Nothing),
             (Iden [Name "c_name"], Nothing),
             (App [Name "sum"]
                [BinOp (Iden [Name "l_extendedprice"]) [Name "*"]
                   (Parens
                      (BinOp (NumLit "1") [Name "-"] (Iden [Name "l_discount"])))],
              Just (Name "revenue")),
             (Iden [Name "c_acctbal"], Nothing),
             (Iden [Name "n_name"], Nothing),
             (Iden [Name "c_address"], Nothing),
             (Iden [Name "c_phone"], Nothing),
             (Iden [Name "c_comment"], Nothing)],
          qeFrom =
            [TRSimple [Name "customer"], TRSimple [Name "orders"],
             TRSimple [Name "lineitem"], TRSimple [Name "nation"]],
          qeWhere =
            Just
              (BinOp
                 (BinOp
                    (BinOp
                       (BinOp
                          (BinOp
                             (BinOp (Iden [Name "c_custkey"]) [Name "="]
                                (Iden [Name "o_custkey"]))
                             [Name "and"]
                             (BinOp (Iden [Name "l_orderkey"]) [Name "="]
                                (Iden [Name "o_orderkey"])))
                          [Name "and"]
                          (BinOp (Iden [Name "o_orderdate"]) [Name ">="]
                             (TypedLit (TypeName [Name "date"]) "1993-12-01")))
                       [Name "and"]
                       (BinOp (Iden [Name "o_orderdate"]) [Name "<"]
                          (BinOp (TypedLit (TypeName [Name "date"]) "1993-12-01") [Name "+"]
                             (IntervalLit{ilSign = Nothing, ilLiteral = "3",
                                          ilFrom = Itf "month" Nothing, ilTo = Nothing}))))
                    [Name "and"]
                    (BinOp (Iden [Name "l_returnflag"]) [Name "="] (StringLit "R")))
                 [Name "and"]
                 (BinOp (Iden [Name "c_nationkey"]) [Name "="]
                    (Iden [Name "n_nationkey"]))),
          qeGroupBy =
            [SimpleGroup (Iden [Name "c_custkey"]),
             SimpleGroup (Iden [Name "c_name"]),
             SimpleGroup (Iden [Name "c_acctbal"]),
             SimpleGroup (Iden [Name "c_phone"]),
             SimpleGroup (Iden [Name "n_name"]),
             SimpleGroup (Iden [Name "c_address"]),
             SimpleGroup (Iden [Name "c_comment"])],
          qeHaving = Nothing,
          qeOrderBy =
            [SortSpec (Iden [Name "revenue"]) Desc NullsOrderDefault],
          qeOffset = Nothing, qeFetchFirst = Just (NumLit "20")})

 select
         ps_partkey,
         sum(ps_supplycost * ps_availqty) as value
 from
         partsupp,
         supplier,
         nation
 where
         ps_suppkey = s_suppkey
         and s_nationkey = n_nationkey
         and n_name = 'CHINA'
 group by
         ps_partkey having
                 sum(ps_supplycost * ps_availqty) > (
                         select
                                 sum(ps_supplycost * ps_availqty) * 0.0001000000
                         from
                                 partsupp,
                                 supplier,
                                 nation
                         where
                                 ps_suppkey = s_suppkey
                                 and s_nationkey = n_nationkey
                                 and n_name = 'CHINA'
                 )
 order by
         value desc
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList =
            [(Iden [Name "ps_partkey"], Nothing),
             (App [Name "sum"]
                [BinOp (Iden [Name "ps_supplycost"]) [Name "*"]
                   (Iden [Name "ps_availqty"])],
              Just (Name "value"))],
          qeFrom =
            [TRSimple [Name "partsupp"], TRSimple [Name "supplier"],
             TRSimple [Name "nation"]],
          qeWhere =
            Just
              (BinOp
                 (BinOp
                    (BinOp (Iden [Name "ps_suppkey"]) [Name "="]
                       (Iden [Name "s_suppkey"]))
                    [Name "and"]
                    (BinOp (Iden [Name "s_nationkey"]) [Name "="]
                       (Iden [Name "n_nationkey"])))
                 [Name "and"]
                 (BinOp (Iden [Name "n_name"]) [Name "="] (StringLit "CHINA"))),
          qeGroupBy = [SimpleGroup (Iden [Name "ps_partkey"])],
          qeHaving =
            Just
              (BinOp
                 (App [Name "sum"]
                    [BinOp (Iden [Name "ps_supplycost"]) [Name "*"]
                       (Iden [Name "ps_availqty"])])
                 [Name ">"]
                 (SubQueryExpr SqSq
                    (Select{qeSetQuantifier = SQDefault,
                            qeSelectList =
                              [(BinOp
                                  (App [Name "sum"]
                                     [BinOp (Iden [Name "ps_supplycost"]) [Name "*"]
                                        (Iden [Name "ps_availqty"])])
                                  [Name "*"]
                                  (NumLit "0.0001000000"),
                                Nothing)],
                            qeFrom =
                              [TRSimple [Name "partsupp"], TRSimple [Name "supplier"],
                               TRSimple [Name "nation"]],
                            qeWhere =
                              Just
                                (BinOp
                                   (BinOp
                                      (BinOp (Iden [Name "ps_suppkey"]) [Name "="]
                                         (Iden [Name "s_suppkey"]))
                                      [Name "and"]
                                      (BinOp (Iden [Name "s_nationkey"]) [Name "="]
                                         (Iden [Name "n_nationkey"])))
                                   [Name "and"]
                                   (BinOp (Iden [Name "n_name"]) [Name "="] (StringLit "CHINA"))),
                            qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
                            qeOffset = Nothing, qeFetchFirst = Nothing}))),
          qeOrderBy =
            [SortSpec (Iden [Name "value"]) Desc NullsOrderDefault],
          qeOffset = Nothing, qeFetchFirst = Nothing})

 select
         l_shipmode,
         sum(case
                 when o_orderpriority = '1-URGENT'
                         or o_orderpriority = '2-HIGH'
                         then 1
                 else 0
         end) as high_line_count,
         sum(case
                 when o_orderpriority <> '1-URGENT'
                         and o_orderpriority <> '2-HIGH'
                         then 1
                 else 0
         end) as low_line_count
 from
         orders,
         lineitem
 where
         o_orderkey = l_orderkey
         and l_shipmode in ('AIR', 'RAIL')
         and l_commitdate < l_receiptdate
         and l_shipdate < l_commitdate
         and l_receiptdate >= date '1994-01-01'
         and l_receiptdate < date '1994-01-01' + interval '1' year
 group by
         l_shipmode
 order by
         l_shipmode
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList =
            [(Iden [Name "l_shipmode"], Nothing),
             (App [Name "sum"]
                [Case{caseTest = Nothing,
                      caseWhens =
                        [([BinOp
                             (BinOp (Iden [Name "o_orderpriority"]) [Name "="]
                                (StringLit "1-URGENT"))
                             [Name "or"]
                             (BinOp (Iden [Name "o_orderpriority"]) [Name "="]
                                (StringLit "2-HIGH"))],
                          NumLit "1")],
                      caseElse = Just (NumLit "0")}],
              Just (Name "high_line_count")),
             (App [Name "sum"]
                [Case{caseTest = Nothing,
                      caseWhens =
                        [([BinOp
                             (BinOp (Iden [Name "o_orderpriority"]) [Name "<>"]
                                (StringLit "1-URGENT"))
                             [Name "and"]
                             (BinOp (Iden [Name "o_orderpriority"]) [Name "<>"]
                                (StringLit "2-HIGH"))],
                          NumLit "1")],
                      caseElse = Just (NumLit "0")}],
              Just (Name "low_line_count"))],
          qeFrom = [TRSimple [Name "orders"], TRSimple [Name "lineitem"]],
          qeWhere =
            Just
              (BinOp
                 (BinOp
                    (BinOp
                       (BinOp
                          (BinOp
                             (BinOp (Iden [Name "o_orderkey"]) [Name "="]
                                (Iden [Name "l_orderkey"]))
                             [Name "and"]
                             (In True (Iden [Name "l_shipmode"])
                                (InList [StringLit "AIR", StringLit "RAIL"])))
                          [Name "and"]
                          (BinOp (Iden [Name "l_commitdate"]) [Name "<"]
                             (Iden [Name "l_receiptdate"])))
                       [Name "and"]
                       (BinOp (Iden [Name "l_shipdate"]) [Name "<"]
                          (Iden [Name "l_commitdate"])))
                    [Name "and"]
                    (BinOp (Iden [Name "l_receiptdate"]) [Name ">="]
                       (TypedLit (TypeName [Name "date"]) "1994-01-01")))
                 [Name "and"]
                 (BinOp (Iden [Name "l_receiptdate"]) [Name "<"]
                    (BinOp (TypedLit (TypeName [Name "date"]) "1994-01-01") [Name "+"]
                       (IntervalLit{ilSign = Nothing, ilLiteral = "1",
                                    ilFrom = Itf "year" Nothing, ilTo = Nothing})))),
          qeGroupBy = [SimpleGroup (Iden [Name "l_shipmode"])],
          qeHaving = Nothing,
          qeOrderBy =
            [SortSpec (Iden [Name "l_shipmode"]) DirDefault NullsOrderDefault],
          qeOffset = Nothing, qeFetchFirst = Nothing})

 select
         c_count,
         count(*) as custdist
 from
         (
                 select
                         c_custkey,
                         count(o_orderkey)
                 from
                         customer left outer join orders on
                                 c_custkey = o_custkey
                                 and o_comment not like '%pending%requests%'
                 group by
                         c_custkey
         ) as c_orders (c_custkey, c_count)
 group by
         c_count
 order by
         custdist desc,
         c_count desc
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList =
            [(Iden [Name "c_count"], Nothing),
             (App [Name "count"] [Star], Just (Name "custdist"))],
          qeFrom =
            [TRAlias
               (TRQueryExpr
                  (Select{qeSetQuantifier = SQDefault,
                          qeSelectList =
                            [(Iden [Name "c_custkey"], Nothing),
                             (App [Name "count"] [Iden [Name "o_orderkey"]], Nothing)],
                          qeFrom =
                            [TRJoin (TRSimple [Name "customer"]) False JLeft
                               (TRSimple [Name "orders"])
                               (Just
                                  (JoinOn
                                     (BinOp
                                        (BinOp (Iden [Name "c_custkey"]) [Name "="]
                                           (Iden [Name "o_custkey"]))
                                        [Name "and"]
                                        (BinOp (Iden [Name "o_comment"]) [Name "not like"]
                                           (StringLit "%pending%requests%")))))],
                          qeWhere = Nothing,
                          qeGroupBy = [SimpleGroup (Iden [Name "c_custkey"])],
                          qeHaving = Nothing, qeOrderBy = [], qeOffset = Nothing,
                          qeFetchFirst = Nothing}))
               (Alias (Name "c_orders")
                  (Just [Name "c_custkey", Name "c_count"]))],
          qeWhere = Nothing,
          qeGroupBy = [SimpleGroup (Iden [Name "c_count"])],
          qeHaving = Nothing,
          qeOrderBy =
            [SortSpec (Iden [Name "custdist"]) Desc NullsOrderDefault,
             SortSpec (Iden [Name "c_count"]) Desc NullsOrderDefault],
          qeOffset = Nothing, qeFetchFirst = Nothing})

 select
         100.00 * sum(case
                 when p_type like 'PROMO%'
                         then l_extendedprice * (1 - l_discount)
                 else 0
         end) / sum(l_extendedprice * (1 - l_discount)) as promo_revenue
 from
         lineitem,
         part
 where
         l_partkey = p_partkey
         and l_shipdate >= date '1994-12-01'
         and l_shipdate < date '1994-12-01' + interval '1' month
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList =
            [(BinOp
                (BinOp (NumLit "100.00") [Name "*"]
                   (App [Name "sum"]
                      [Case{caseTest = Nothing,
                            caseWhens =
                              [([BinOp (Iden [Name "p_type"]) [Name "like"]
                                   (StringLit "PROMO%")],
                                BinOp (Iden [Name "l_extendedprice"]) [Name "*"]
                                  (Parens
                                     (BinOp (NumLit "1") [Name "-"] (Iden [Name "l_discount"]))))],
                            caseElse = Just (NumLit "0")}]))
                [Name "/"]
                (App [Name "sum"]
                   [BinOp (Iden [Name "l_extendedprice"]) [Name "*"]
                      (Parens
                         (BinOp (NumLit "1") [Name "-"] (Iden [Name "l_discount"])))]),
              Just (Name "promo_revenue"))],
          qeFrom = [TRSimple [Name "lineitem"], TRSimple [Name "part"]],
          qeWhere =
            Just
              (BinOp
                 (BinOp
                    (BinOp (Iden [Name "l_partkey"]) [Name "="]
                       (Iden [Name "p_partkey"]))
                    [Name "and"]
                    (BinOp (Iden [Name "l_shipdate"]) [Name ">="]
                       (TypedLit (TypeName [Name "date"]) "1994-12-01")))
                 [Name "and"]
                 (BinOp (Iden [Name "l_shipdate"]) [Name "<"]
                    (BinOp (TypedLit (TypeName [Name "date"]) "1994-12-01") [Name "+"]
                       (IntervalLit{ilSign = Nothing, ilLiteral = "1",
                                    ilFrom = Itf "month" Nothing, ilTo = Nothing})))),
          qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
          qeOffset = Nothing, qeFetchFirst = Nothing})

 /*create view revenue0 (supplier_no, total_revenue) as
         select
                 l_suppkey,
                 sum(l_extendedprice * (1 - l_discount))
         from
                 lineitem
         where
                 l_shipdate >= date '1995-06-01'
                 and l_shipdate < date '1995-06-01' + interval '3' month
         group by
                 l_suppkey;*/
 with
 revenue0 as
         (select
                 l_suppkey as supplier_no,
                 sum(l_extendedprice * (1 - l_discount)) as total_revenue
         from
                 lineitem
         where
                 l_shipdate >= date '1995-06-01'
                 and l_shipdate < date '1995-06-01' + interval '3' month
         group by
                 l_suppkey)
 select
         s_suppkey,
         s_name,
         s_address,
         s_phone,
         total_revenue
 from
         supplier,
         revenue0
 where
         s_suppkey = supplier_no
         and total_revenue = (
                 select
                         max(total_revenue)
                 from
                         revenue0
         )
 order by
         s_suppkey
Right
  (With{qeWithRecursive = False,
        qeViews =
          [(Alias (Name "revenue0") Nothing,
            Select{qeSetQuantifier = SQDefault,
                   qeSelectList =
                     [(Iden [Name "l_suppkey"], Just (Name "supplier_no")),
                      (App [Name "sum"]
                         [BinOp (Iden [Name "l_extendedprice"]) [Name "*"]
                            (Parens
                               (BinOp (NumLit "1") [Name "-"] (Iden [Name "l_discount"])))],
                       Just (Name "total_revenue"))],
                   qeFrom = [TRSimple [Name "lineitem"]],
                   qeWhere =
                     Just
                       (BinOp
                          (BinOp (Iden [Name "l_shipdate"]) [Name ">="]
                             (TypedLit (TypeName [Name "date"]) "1995-06-01"))
                          [Name "and"]
                          (BinOp (Iden [Name "l_shipdate"]) [Name "<"]
                             (BinOp (TypedLit (TypeName [Name "date"]) "1995-06-01") [Name "+"]
                                (IntervalLit{ilSign = Nothing, ilLiteral = "3",
                                             ilFrom = Itf "month" Nothing, ilTo = Nothing})))),
                   qeGroupBy = [SimpleGroup (Iden [Name "l_suppkey"])],
                   qeHaving = Nothing, qeOrderBy = [], qeOffset = Nothing,
                   qeFetchFirst = Nothing})],
        qeQueryExpression =
          Select{qeSetQuantifier = SQDefault,
                 qeSelectList =
                   [(Iden [Name "s_suppkey"], Nothing),
                    (Iden [Name "s_name"], Nothing),
                    (Iden [Name "s_address"], Nothing),
                    (Iden [Name "s_phone"], Nothing),
                    (Iden [Name "total_revenue"], Nothing)],
                 qeFrom = [TRSimple [Name "supplier"], TRSimple [Name "revenue0"]],
                 qeWhere =
                   Just
                     (BinOp
                        (BinOp (Iden [Name "s_suppkey"]) [Name "="]
                           (Iden [Name "supplier_no"]))
                        [Name "and"]
                        (BinOp (Iden [Name "total_revenue"]) [Name "="]
                           (SubQueryExpr SqSq
                              (Select{qeSetQuantifier = SQDefault,
                                      qeSelectList =
                                        [(App [Name "max"] [Iden [Name "total_revenue"]], Nothing)],
                                      qeFrom = [TRSimple [Name "revenue0"]], qeWhere = Nothing,
                                      qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
                                      qeOffset = Nothing, qeFetchFirst = Nothing})))),
                 qeGroupBy = [], qeHaving = Nothing,
                 qeOrderBy =
                   [SortSpec (Iden [Name "s_suppkey"]) DirDefault NullsOrderDefault],
                 qeOffset = Nothing, qeFetchFirst = Nothing}})

 select
         p_brand,
         p_type,
         p_size,
         count(distinct ps_suppkey) as supplier_cnt
 from
         partsupp,
         part
 where
         p_partkey = ps_partkey
         and p_brand <> 'Brand#15'
         and p_type not like 'MEDIUM BURNISHED%'
         and p_size in (39, 26, 18, 45, 19, 1, 3, 9)
         and ps_suppkey not in (
                 select
                         s_suppkey
                 from
                         supplier
                 where
                         s_comment like '%Customer%Complaints%'
         )
 group by
         p_brand,
         p_type,
         p_size
 order by
         supplier_cnt desc,
         p_brand,
         p_type,
         p_size
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList =
            [(Iden [Name "p_brand"], Nothing), (Iden [Name "p_type"], Nothing),
             (Iden [Name "p_size"], Nothing),
             (AggregateApp{aggName = [Name "count"], aggDistinct = Distinct,
                           aggArgs = [Iden [Name "ps_suppkey"]], aggOrderBy = [],
                           aggFilter = Nothing},
              Just (Name "supplier_cnt"))],
          qeFrom = [TRSimple [Name "partsupp"], TRSimple [Name "part"]],
          qeWhere =
            Just
              (BinOp
                 (BinOp
                    (BinOp
                       (BinOp
                          (BinOp (Iden [Name "p_partkey"]) [Name "="]
                             (Iden [Name "ps_partkey"]))
                          [Name "and"]
                          (BinOp (Iden [Name "p_brand"]) [Name "<>"] (StringLit "Brand#15")))
                       [Name "and"]
                       (BinOp (Iden [Name "p_type"]) [Name "not like"]
                          (StringLit "MEDIUM BURNISHED%")))
                    [Name "and"]
                    (In True (Iden [Name "p_size"])
                       (InList
                          [NumLit "39", NumLit "26", NumLit "18", NumLit "45", NumLit "19",
                           NumLit "1", NumLit "3", NumLit "9"])))
                 [Name "and"]
                 (In False (Iden [Name "ps_suppkey"])
                    (InQueryExpr
                       (Select{qeSetQuantifier = SQDefault,
                               qeSelectList = [(Iden [Name "s_suppkey"], Nothing)],
                               qeFrom = [TRSimple [Name "supplier"]],
                               qeWhere =
                                 Just
                                   (BinOp (Iden [Name "s_comment"]) [Name "like"]
                                      (StringLit "%Customer%Complaints%")),
                               qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
                               qeOffset = Nothing, qeFetchFirst = Nothing})))),
          qeGroupBy =
            [SimpleGroup (Iden [Name "p_brand"]),
             SimpleGroup (Iden [Name "p_type"]),
             SimpleGroup (Iden [Name "p_size"])],
          qeHaving = Nothing,
          qeOrderBy =
            [SortSpec (Iden [Name "supplier_cnt"]) Desc NullsOrderDefault,
             SortSpec (Iden [Name "p_brand"]) DirDefault NullsOrderDefault,
             SortSpec (Iden [Name "p_type"]) DirDefault NullsOrderDefault,
             SortSpec (Iden [Name "p_size"]) DirDefault NullsOrderDefault],
          qeOffset = Nothing, qeFetchFirst = Nothing})

 select
         sum(l_extendedprice) / 7.0 as avg_yearly
 from
         lineitem,
         part
 where
         p_partkey = l_partkey
         and p_brand = 'Brand#52'
         and p_container = 'JUMBO CAN'
         and l_quantity < (
                 select
                         0.2 * avg(l_quantity)
                 from
                         lineitem
                 where
                         l_partkey = p_partkey
         )
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList =
            [(BinOp (App [Name "sum"] [Iden [Name "l_extendedprice"]])
                [Name "/"]
                (NumLit "7.0"),
              Just (Name "avg_yearly"))],
          qeFrom = [TRSimple [Name "lineitem"], TRSimple [Name "part"]],
          qeWhere =
            Just
              (BinOp
                 (BinOp
                    (BinOp
                       (BinOp (Iden [Name "p_partkey"]) [Name "="]
                          (Iden [Name "l_partkey"]))
                       [Name "and"]
                       (BinOp (Iden [Name "p_brand"]) [Name "="] (StringLit "Brand#52")))
                    [Name "and"]
                    (BinOp (Iden [Name "p_container"]) [Name "="]
                       (StringLit "JUMBO CAN")))
                 [Name "and"]
                 (BinOp (Iden [Name "l_quantity"]) [Name "<"]
                    (SubQueryExpr SqSq
                       (Select{qeSetQuantifier = SQDefault,
                               qeSelectList =
                                 [(BinOp (NumLit "0.2") [Name "*"]
                                     (App [Name "avg"] [Iden [Name "l_quantity"]]),
                                   Nothing)],
                               qeFrom = [TRSimple [Name "lineitem"]],
                               qeWhere =
                                 Just
                                   (BinOp (Iden [Name "l_partkey"]) [Name "="]
                                      (Iden [Name "p_partkey"])),
                               qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
                               qeOffset = Nothing, qeFetchFirst = Nothing})))),
          qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
          qeOffset = Nothing, qeFetchFirst = Nothing})

 select
         c_name,
         c_custkey,
         o_orderkey,
         o_orderdate,
         o_totalprice,
         sum(l_quantity)
 from
         customer,
         orders,
         lineitem
 where
         o_orderkey in (
                 select
                         l_orderkey
                 from
                         lineitem
                 group by
                         l_orderkey having
                                 sum(l_quantity) > 313
         )
         and c_custkey = o_custkey
         and o_orderkey = l_orderkey
 group by
         c_name,
         c_custkey,
         o_orderkey,
         o_orderdate,
         o_totalprice
 order by
         o_totalprice desc,
         o_orderdate
 fetch first 100 rows only
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList =
            [(Iden [Name "c_name"], Nothing),
             (Iden [Name "c_custkey"], Nothing),
             (Iden [Name "o_orderkey"], Nothing),
             (Iden [Name "o_orderdate"], Nothing),
             (Iden [Name "o_totalprice"], Nothing),
             (App [Name "sum"] [Iden [Name "l_quantity"]], Nothing)],
          qeFrom =
            [TRSimple [Name "customer"], TRSimple [Name "orders"],
             TRSimple [Name "lineitem"]],
          qeWhere =
            Just
              (BinOp
                 (BinOp
                    (In True (Iden [Name "o_orderkey"])
                       (InQueryExpr
                          (Select{qeSetQuantifier = SQDefault,
                                  qeSelectList = [(Iden [Name "l_orderkey"], Nothing)],
                                  qeFrom = [TRSimple [Name "lineitem"]], qeWhere = Nothing,
                                  qeGroupBy = [SimpleGroup (Iden [Name "l_orderkey"])],
                                  qeHaving =
                                    Just
                                      (BinOp (App [Name "sum"] [Iden [Name "l_quantity"]])
                                         [Name ">"]
                                         (NumLit "313")),
                                  qeOrderBy = [], qeOffset = Nothing, qeFetchFirst = Nothing})))
                    [Name "and"]
                    (BinOp (Iden [Name "c_custkey"]) [Name "="]
                       (Iden [Name "o_custkey"])))
                 [Name "and"]
                 (BinOp (Iden [Name "o_orderkey"]) [Name "="]
                    (Iden [Name "l_orderkey"]))),
          qeGroupBy =
            [SimpleGroup (Iden [Name "c_name"]),
             SimpleGroup (Iden [Name "c_custkey"]),
             SimpleGroup (Iden [Name "o_orderkey"]),
             SimpleGroup (Iden [Name "o_orderdate"]),
             SimpleGroup (Iden [Name "o_totalprice"])],
          qeHaving = Nothing,
          qeOrderBy =
            [SortSpec (Iden [Name "o_totalprice"]) Desc NullsOrderDefault,
             SortSpec (Iden [Name "o_orderdate"]) DirDefault NullsOrderDefault],
          qeOffset = Nothing, qeFetchFirst = Just (NumLit "100")})

 select
         sum(l_extendedprice* (1 - l_discount)) as revenue
 from
         lineitem,
         part
 where
         (
                 p_partkey = l_partkey
                 and p_brand = 'Brand#43'
                 and p_container in ('SM CASE', 'SM BOX', 'SM PACK', 'SM PKG')
                 and l_quantity >= 3 and l_quantity <= 3 + 10
                 and p_size between 1 and 5
                 and l_shipmode in ('AIR', 'AIR REG')
                 and l_shipinstruct = 'DELIVER IN PERSON'
         )
         or
         (
                 p_partkey = l_partkey
                 and p_brand = 'Brand#25'
                 and p_container in ('MED BAG', 'MED BOX', 'MED PKG', 'MED PACK')
                 and l_quantity >= 10 and l_quantity <= 10 + 10
                 and p_size between 1 and 10
                 and l_shipmode in ('AIR', 'AIR REG')
                 and l_shipinstruct = 'DELIVER IN PERSON'
         )
         or
         (
                 p_partkey = l_partkey
                 and p_brand = 'Brand#24'
                 and p_container in ('LG CASE', 'LG BOX', 'LG PACK', 'LG PKG')
                 and l_quantity >= 22 and l_quantity <= 22 + 10
                 and p_size between 1 and 15
                 and l_shipmode in ('AIR', 'AIR REG')
                 and l_shipinstruct = 'DELIVER IN PERSON'
         )
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList =
            [(App [Name "sum"]
                [BinOp (Iden [Name "l_extendedprice"]) [Name "*"]
                   (Parens
                      (BinOp (NumLit "1") [Name "-"] (Iden [Name "l_discount"])))],
              Just (Name "revenue"))],
          qeFrom = [TRSimple [Name "lineitem"], TRSimple [Name "part"]],
          qeWhere =
            Just
              (BinOp
                 (BinOp
                    (Parens
                       (BinOp
                          (BinOp
                             (BinOp
                                (BinOp
                                   (BinOp
                                      (BinOp
                                         (BinOp
                                            (BinOp (Iden [Name "p_partkey"]) [Name "="]
                                               (Iden [Name "l_partkey"]))
                                            [Name "and"]
                                            (BinOp (Iden [Name "p_brand"]) [Name "="]
                                               (StringLit "Brand#43")))
                                         [Name "and"]
                                         (In True (Iden [Name "p_container"])
                                            (InList
                                               [StringLit "SM CASE", StringLit "SM BOX",
                                                StringLit "SM PACK", StringLit "SM PKG"])))
                                      [Name "and"]
                                      (BinOp (Iden [Name "l_quantity"]) [Name ">="] (NumLit "3")))
                                   [Name "and"]
                                   (BinOp (Iden [Name "l_quantity"]) [Name "<="]
                                      (BinOp (NumLit "3") [Name "+"] (NumLit "10"))))
                                [Name "and"]
                                (SpecialOp [Name "between"]
                                   [Iden [Name "p_size"], NumLit "1", NumLit "5"]))
                             [Name "and"]
                             (In True (Iden [Name "l_shipmode"])
                                (InList [StringLit "AIR", StringLit "AIR REG"])))
                          [Name "and"]
                          (BinOp (Iden [Name "l_shipinstruct"]) [Name "="]
                             (StringLit "DELIVER IN PERSON"))))
                    [Name "or"]
                    (Parens
                       (BinOp
                          (BinOp
                             (BinOp
                                (BinOp
                                   (BinOp
                                      (BinOp
                                         (BinOp
                                            (BinOp (Iden [Name "p_partkey"]) [Name "="]
                                               (Iden [Name "l_partkey"]))
                                            [Name "and"]
                                            (BinOp (Iden [Name "p_brand"]) [Name "="]
                                               (StringLit "Brand#25")))
                                         [Name "and"]
                                         (In True (Iden [Name "p_container"])
                                            (InList
                                               [StringLit "MED BAG", StringLit "MED BOX",
                                                StringLit "MED PKG", StringLit "MED PACK"])))
                                      [Name "and"]
                                      (BinOp (Iden [Name "l_quantity"]) [Name ">="] (NumLit "10")))
                                   [Name "and"]
                                   (BinOp (Iden [Name "l_quantity"]) [Name "<="]
                                      (BinOp (NumLit "10") [Name "+"] (NumLit "10"))))
                                [Name "and"]
                                (SpecialOp [Name "between"]
                                   [Iden [Name "p_size"], NumLit "1", NumLit "10"]))
                             [Name "and"]
                             (In True (Iden [Name "l_shipmode"])
                                (InList [StringLit "AIR", StringLit "AIR REG"])))
                          [Name "and"]
                          (BinOp (Iden [Name "l_shipinstruct"]) [Name "="]
                             (StringLit "DELIVER IN PERSON")))))
                 [Name "or"]
                 (Parens
                    (BinOp
                       (BinOp
                          (BinOp
                             (BinOp
                                (BinOp
                                   (BinOp
                                      (BinOp
                                         (BinOp (Iden [Name "p_partkey"]) [Name "="]
                                            (Iden [Name "l_partkey"]))
                                         [Name "and"]
                                         (BinOp (Iden [Name "p_brand"]) [Name "="]
                                            (StringLit "Brand#24")))
                                      [Name "and"]
                                      (In True (Iden [Name "p_container"])
                                         (InList
                                            [StringLit "LG CASE", StringLit "LG BOX",
                                             StringLit "LG PACK", StringLit "LG PKG"])))
                                   [Name "and"]
                                   (BinOp (Iden [Name "l_quantity"]) [Name ">="] (NumLit "22")))
                                [Name "and"]
                                (BinOp (Iden [Name "l_quantity"]) [Name "<="]
                                   (BinOp (NumLit "22") [Name "+"] (NumLit "10"))))
                             [Name "and"]
                             (SpecialOp [Name "between"]
                                [Iden [Name "p_size"], NumLit "1", NumLit "15"]))
                          [Name "and"]
                          (In True (Iden [Name "l_shipmode"])
                             (InList [StringLit "AIR", StringLit "AIR REG"])))
                       [Name "and"]
                       (BinOp (Iden [Name "l_shipinstruct"]) [Name "="]
                          (StringLit "DELIVER IN PERSON"))))),
          qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
          qeOffset = Nothing, qeFetchFirst = Nothing})

 select
         s_name,
         s_address
 from
         supplier,
         nation
 where
         s_suppkey in (
                 select
                         ps_suppkey
                 from
                         partsupp
                 where
                         ps_partkey in (
                                 select
                                         p_partkey
                                 from
                                         part
                                 where
                                         p_name like 'lime%'
                         )
                         and ps_availqty > (
                                 select
                                         0.5 * sum(l_quantity)
                                 from
                                         lineitem
                                 where
                                         l_partkey = ps_partkey
                                         and l_suppkey = ps_suppkey
                                         and l_shipdate >= date '1994-01-01'
                                         and l_shipdate < date '1994-01-01' + interval '1' year
                         )
         )
         and s_nationkey = n_nationkey
         and n_name = 'VIETNAM'
 order by
         s_name
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList =
            [(Iden [Name "s_name"], Nothing),
             (Iden [Name "s_address"], Nothing)],
          qeFrom = [TRSimple [Name "supplier"], TRSimple [Name "nation"]],
          qeWhere =
            Just
              (BinOp
                 (BinOp
                    (In True (Iden [Name "s_suppkey"])
                       (InQueryExpr
                          (Select{qeSetQuantifier = SQDefault,
                                  qeSelectList = [(Iden [Name "ps_suppkey"], Nothing)],
                                  qeFrom = [TRSimple [Name "partsupp"]],
                                  qeWhere =
                                    Just
                                      (BinOp
                                         (In True (Iden [Name "ps_partkey"])
                                            (InQueryExpr
                                               (Select{qeSetQuantifier = SQDefault,
                                                       qeSelectList =
                                                         [(Iden [Name "p_partkey"], Nothing)],
                                                       qeFrom = [TRSimple [Name "part"]],
                                                       qeWhere =
                                                         Just
                                                           (BinOp (Iden [Name "p_name"])
                                                              [Name "like"]
                                                              (StringLit "lime%")),
                                                       qeGroupBy = [], qeHaving = Nothing,
                                                       qeOrderBy = [], qeOffset = Nothing,
                                                       qeFetchFirst = Nothing})))
                                         [Name "and"]
                                         (BinOp (Iden [Name "ps_availqty"]) [Name ">"]
                                            (SubQueryExpr SqSq
                                               (Select{qeSetQuantifier = SQDefault,
                                                       qeSelectList =
                                                         [(BinOp (NumLit "0.5") [Name "*"]
                                                             (App [Name "sum"]
                                                                [Iden [Name "l_quantity"]]),
                                                           Nothing)],
                                                       qeFrom = [TRSimple [Name "lineitem"]],
                                                       qeWhere =
                                                         Just
                                                           (BinOp
                                                              (BinOp
                                                                 (BinOp
                                                                    (BinOp (Iden [Name "l_partkey"])
                                                                       [Name "="]
                                                                       (Iden [Name "ps_partkey"]))
                                                                    [Name "and"]
                                                                    (BinOp (Iden [Name "l_suppkey"])
                                                                       [Name "="]
                                                                       (Iden [Name "ps_suppkey"])))
                                                                 [Name "and"]
                                                                 (BinOp (Iden [Name "l_shipdate"])
                                                                    [Name ">="]
                                                                    (TypedLit
                                                                       (TypeName [Name "date"])
                                                                       "1994-01-01")))
                                                              [Name "and"]
                                                              (BinOp (Iden [Name "l_shipdate"])
                                                                 [Name "<"]
                                                                 (BinOp
                                                                    (TypedLit
                                                                       (TypeName [Name "date"])
                                                                       "1994-01-01")
                                                                    [Name "+"]
                                                                    (IntervalLit{ilSign = Nothing,
                                                                                 ilLiteral = "1",
                                                                                 ilFrom =
                                                                                   Itf "year"
                                                                                     Nothing,
                                                                                 ilTo =
                                                                                   Nothing})))),
                                                       qeGroupBy = [], qeHaving = Nothing,
                                                       qeOrderBy = [], qeOffset = Nothing,
                                                       qeFetchFirst = Nothing})))),
                                  qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
                                  qeOffset = Nothing, qeFetchFirst = Nothing})))
                    [Name "and"]
                    (BinOp (Iden [Name "s_nationkey"]) [Name "="]
                       (Iden [Name "n_nationkey"])))
                 [Name "and"]
                 (BinOp (Iden [Name "n_name"]) [Name "="] (StringLit "VIETNAM"))),
          qeGroupBy = [], qeHaving = Nothing,
          qeOrderBy =
            [SortSpec (Iden [Name "s_name"]) DirDefault NullsOrderDefault],
          qeOffset = Nothing, qeFetchFirst = Nothing})

 select
         s_name,
         count(*) as numwait
 from
         supplier,
         lineitem l1,
         orders,
         nation
 where
         s_suppkey = l1.l_suppkey
         and o_orderkey = l1.l_orderkey
         and o_orderstatus = 'F'
         and l1.l_receiptdate > l1.l_commitdate
         and exists (
                 select
                         *
                 from
                         lineitem l2
                 where
                         l2.l_orderkey = l1.l_orderkey
                         and l2.l_suppkey <> l1.l_suppkey
         )
         and not exists (
                 select
                         *
                 from
                         lineitem l3
                 where
                         l3.l_orderkey = l1.l_orderkey
                         and l3.l_suppkey <> l1.l_suppkey
                         and l3.l_receiptdate > l3.l_commitdate
         )
         and s_nationkey = n_nationkey
         and n_name = 'INDIA'
 group by
         s_name
 order by
         numwait desc,
         s_name
 fetch first 100 rows only
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList =
            [(Iden [Name "s_name"], Nothing),
             (App [Name "count"] [Star], Just (Name "numwait"))],
          qeFrom =
            [TRSimple [Name "supplier"],
             TRAlias (TRSimple [Name "lineitem"]) (Alias (Name "l1") Nothing),
             TRSimple [Name "orders"], TRSimple [Name "nation"]],
          qeWhere =
            Just
              (BinOp
                 (BinOp
                    (BinOp
                       (BinOp
                          (BinOp
                             (BinOp
                                (BinOp
                                   (BinOp (Iden [Name "s_suppkey"]) [Name "="]
                                      (Iden [Name "l1", Name "l_suppkey"]))
                                   [Name "and"]
                                   (BinOp (Iden [Name "o_orderkey"]) [Name "="]
                                      (Iden [Name "l1", Name "l_orderkey"])))
                                [Name "and"]
                                (BinOp (Iden [Name "o_orderstatus"]) [Name "="] (StringLit "F")))
                             [Name "and"]
                             (BinOp (Iden [Name "l1", Name "l_receiptdate"]) [Name ">"]
                                (Iden [Name "l1", Name "l_commitdate"])))
                          [Name "and"]
                          (SubQueryExpr SqExists
                             (Select{qeSetQuantifier = SQDefault,
                                     qeSelectList = [(Star, Nothing)],
                                     qeFrom =
                                       [TRAlias (TRSimple [Name "lineitem"])
                                          (Alias (Name "l2") Nothing)],
                                     qeWhere =
                                       Just
                                         (BinOp
                                            (BinOp (Iden [Name "l2", Name "l_orderkey"]) [Name "="]
                                               (Iden [Name "l1", Name "l_orderkey"]))
                                            [Name "and"]
                                            (BinOp (Iden [Name "l2", Name "l_suppkey"]) [Name "<>"]
                                               (Iden [Name "l1", Name "l_suppkey"]))),
                                     qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
                                     qeOffset = Nothing, qeFetchFirst = Nothing})))
                       [Name "and"]
                       (PrefixOp [Name "not"]
                          (SubQueryExpr SqExists
                             (Select{qeSetQuantifier = SQDefault,
                                     qeSelectList = [(Star, Nothing)],
                                     qeFrom =
                                       [TRAlias (TRSimple [Name "lineitem"])
                                          (Alias (Name "l3") Nothing)],
                                     qeWhere =
                                       Just
                                         (BinOp
                                            (BinOp
                                               (BinOp (Iden [Name "l3", Name "l_orderkey"])
                                                  [Name "="]
                                                  (Iden [Name "l1", Name "l_orderkey"]))
                                               [Name "and"]
                                               (BinOp (Iden [Name "l3", Name "l_suppkey"])
                                                  [Name "<>"]
                                                  (Iden [Name "l1", Name "l_suppkey"])))
                                            [Name "and"]
                                            (BinOp (Iden [Name "l3", Name "l_receiptdate"])
                                               [Name ">"]
                                               (Iden [Name "l3", Name "l_commitdate"]))),
                                     qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
                                     qeOffset = Nothing, qeFetchFirst = Nothing}))))
                    [Name "and"]
                    (BinOp (Iden [Name "s_nationkey"]) [Name "="]
                       (Iden [Name "n_nationkey"])))
                 [Name "and"]
                 (BinOp (Iden [Name "n_name"]) [Name "="] (StringLit "INDIA"))),
          qeGroupBy = [SimpleGroup (Iden [Name "s_name"])],
          qeHaving = Nothing,
          qeOrderBy =
            [SortSpec (Iden [Name "numwait"]) Desc NullsOrderDefault,
             SortSpec (Iden [Name "s_name"]) DirDefault NullsOrderDefault],
          qeOffset = Nothing, qeFetchFirst = Just (NumLit "100")})

 select
         cntrycode,
         count(*) as numcust,
         sum(c_acctbal) as totacctbal
 from
         (
                 select
                         substring(c_phone from 1 for 2) as cntrycode,
                         c_acctbal
                 from
                         customer
                 where
                         substring(c_phone from 1 for 2) in
                                 ('41', '28', '39', '21', '24', '29', '44')
                         and c_acctbal > (
                                 select
                                         avg(c_acctbal)
                                 from
                                         customer
                                 where
                                         c_acctbal > 0.00
                                         and substring(c_phone from 1 for 2) in
                                                 ('41', '28', '39', '21', '24', '29', '44')
                         )
                         and not exists (
                                 select
                                         *
                                 from
                                         orders
                                 where
                                         o_custkey = c_custkey
                         )
         ) as custsale
 group by
         cntrycode
 order by
         cntrycode
Right
  (Select{qeSetQuantifier = SQDefault,
          qeSelectList =
            [(Iden [Name "cntrycode"], Nothing),
             (App [Name "count"] [Star], Just (Name "numcust")),
             (App [Name "sum"] [Iden [Name "c_acctbal"]],
              Just (Name "totacctbal"))],
          qeFrom =
            [TRAlias
               (TRQueryExpr
                  (Select{qeSetQuantifier = SQDefault,
                          qeSelectList =
                            [(SpecialOpK [Name "substring"] (Just (Iden [Name "c_phone"]))
                                [("from", NumLit "1"), ("for", NumLit "2")],
                              Just (Name "cntrycode")),
                             (Iden [Name "c_acctbal"], Nothing)],
                          qeFrom = [TRSimple [Name "customer"]],
                          qeWhere =
                            Just
                              (BinOp
                                 (BinOp
                                    (In True
                                       (SpecialOpK [Name "substring"] (Just (Iden [Name "c_phone"]))
                                          [("from", NumLit "1"), ("for", NumLit "2")])
                                       (InList
                                          [StringLit "41", StringLit "28", StringLit "39",
                                           StringLit "21", StringLit "24", StringLit "29",
                                           StringLit "44"]))
                                    [Name "and"]
                                    (BinOp (Iden [Name "c_acctbal"]) [Name ">"]
                                       (SubQueryExpr SqSq
                                          (Select{qeSetQuantifier = SQDefault,
                                                  qeSelectList =
                                                    [(App [Name "avg"] [Iden [Name "c_acctbal"]],
                                                      Nothing)],
                                                  qeFrom = [TRSimple [Name "customer"]],
                                                  qeWhere =
                                                    Just
                                                      (BinOp
                                                         (BinOp (Iden [Name "c_acctbal"]) [Name ">"]
                                                            (NumLit "0.00"))
                                                         [Name "and"]
                                                         (In True
                                                            (SpecialOpK [Name "substring"]
                                                               (Just (Iden [Name "c_phone"]))
                                                               [("from", NumLit "1"),
                                                                ("for", NumLit "2")])
                                                            (InList
                                                               [StringLit "41", StringLit "28",
                                                                StringLit "39", StringLit "21",
                                                                StringLit "24", StringLit "29",
                                                                StringLit "44"]))),
                                                  qeGroupBy = [], qeHaving = Nothing,
                                                  qeOrderBy = [], qeOffset = Nothing,
                                                  qeFetchFirst = Nothing}))))
                                 [Name "and"]
                                 (PrefixOp [Name "not"]
                                    (SubQueryExpr SqExists
                                       (Select{qeSetQuantifier = SQDefault,
                                               qeSelectList = [(Star, Nothing)],
                                               qeFrom = [TRSimple [Name "orders"]],
                                               qeWhere =
                                                 Just
                                                   (BinOp (Iden [Name "o_custkey"]) [Name "="]
                                                      (Iden [Name "c_custkey"])),
                                               qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
                                               qeOffset = Nothing, qeFetchFirst = Nothing})))),
                          qeGroupBy = [], qeHaving = Nothing, qeOrderBy = [],
                          qeOffset = Nothing, qeFetchFirst = Nothing}))
               (Alias (Name "custsale") Nothing)],
          qeWhere = Nothing,
          qeGroupBy = [SimpleGroup (Iden [Name "cntrycode"])],
          qeHaving = Nothing,
          qeOrderBy =
            [SortSpec (Iden [Name "cntrycode"]) DirDefault NullsOrderDefault],
          qeOffset = Nothing, qeFetchFirst = Nothing})

sql 2011 tests

literals

numeric literals

11
NumLit "11"
11.11
NumLit "11.11"
11E23
NumLit "11E23"
11E+23
NumLit "11E+23"
11E-23
NumLit "11E-23"
11.11E23
NumLit "11.11E23"
11.11E+23
NumLit "11.11E+23"
11.11E-23
NumLit "11.11E-23"
+11E23
PrefixOp [Name "+"] (NumLit "11E23")
+11E+23
PrefixOp [Name "+"] (NumLit "11E+23")
+11E-23
PrefixOp [Name "+"] (NumLit "11E-23")
+11.11E23
PrefixOp [Name "+"] (NumLit "11.11E23")
+11.11E+23
PrefixOp [Name "+"] (NumLit "11.11E+23")
+11.11E-23
PrefixOp [Name "+"] (NumLit "11.11E-23")
-11E23
PrefixOp [Name "-"] (NumLit "11E23")
-11E+23
PrefixOp [Name "-"] (NumLit "11E+23")
-11E-23
PrefixOp [Name "-"] (NumLit "11E-23")
-11.11E23
PrefixOp [Name "-"] (NumLit "11.11E23")
-11.11E+23
PrefixOp [Name "-"] (NumLit "11.11E+23")
-11.11E-23
PrefixOp [Name "-"] (NumLit "11.11E-23")
11.11e23
NumLit "11.11e23"

general literals

character string literals
'a regular string literal'
StringLit "a regular string literal"
'something' ' some more' 'and more'
StringLit "something some moreand more"
'something' 
 ' some more'    'and more'
StringLit "something some moreand more"
'something' -- a comment
 ' some more' /*another comment*/ 'and more'
StringLit "something some moreand more"
'a quote: '', stuff'
StringLit "a quote: ', stuff"
''
StringLit ""
_francais 'fran├žais'
TypedLit (TypeName [Name "_francais"]) "fran\231ais"
national character string literals
N'something'
CSStringLit "N" "something"
n'something'
CSStringLit "n" "something"
unicode character string literals
U&'something'
CSStringLit "U&" "something"
u&'something' escape =
Escape (CSStringLit "u&" "something") '='
u&'something' uescape =
UEscape (CSStringLit "u&" "something") '='
binary string literals
X'7f7f7f'
CSStringLit "X" "7f7f7f"
X'7f7f7f' escape z
Escape (CSStringLit "X" "7f7f7f") 'z'
datetime literals
intervalLiterals literals
interval '1'
TypedLit (TypeName [Name "interval"]) "1"
interval '1' day
IntervalLit{ilSign = Nothing, ilLiteral = "1",
            ilFrom = Itf "day" Nothing, ilTo = Nothing}
interval '1' day(3)
IntervalLit{ilSign = Nothing, ilLiteral = "1",
            ilFrom = Itf "day" (Just (3, Nothing)), ilTo = Nothing}
interval + '1' day(3)
IntervalLit{ilSign = Just True, ilLiteral = "1",
            ilFrom = Itf "day" (Just (3, Nothing)), ilTo = Nothing}
interval - '1' second(2,2)
IntervalLit{ilSign = Just False, ilLiteral = "1",
            ilFrom = Itf "second" (Just (2, Just 2)), ilTo = Nothing}
interval '1' year to month
IntervalLit{ilSign = Nothing, ilLiteral = "1",
            ilFrom = Itf "year" Nothing, ilTo = Just (Itf "month" Nothing)}
interval '1' year(4) to second(2,3) 
IntervalLit{ilSign = Nothing, ilLiteral = "1",
            ilFrom = Itf "year" (Just (4, Nothing)),
            ilTo = Just (Itf "second" (Just (2, Just 3)))}
boolean literals
true
Iden [Name "true"]
false
Iden [Name "false"]
unknown
Iden [Name "unknown"]

identifiers

test
Iden [Name "test"]
_test
Iden [Name "_test"]
t1
Iden [Name "t1"]
a.b
Iden [Name "a", Name "b"]
a.b.c
Iden [Name "a", Name "b", Name "c"]
"quoted iden"
Iden [QName "quoted iden"]
"quoted "" iden"
Iden [QName "quoted \" iden"]
U&"quoted iden"
Iden [UQName "quoted iden"]
U&"quoted "" iden"
Iden [UQName "quoted \" iden"]

type names

cast('test' as binary)
Cast (StringLit "test") (TypeName [Name "binary"])
binary 'test'
TypedLit (TypeName [Name "binary"]) "test"
cast('test' as binary varying)
Cast (StringLit "test") (TypeName [Name "binary varying"])
binary varying 'test'
TypedLit (TypeName [Name "binary varying"]) "test"
cast('test' as character)
Cast (StringLit "test") (TypeName [Name "character"])
character 'test'
TypedLit (TypeName [Name "character"]) "test"
cast('test' as char)
Cast (StringLit "test") (TypeName [Name "char"])
char 'test'
TypedLit (TypeName [Name "char"]) "test"
cast('test' as character varying)
Cast (StringLit "test") (TypeName [Name "character varying"])
character varying 'test'
TypedLit (TypeName [Name "character varying"]) "test"
cast('test' as char varying)
Cast (StringLit "test") (TypeName [Name "char varying"])
char varying 'test'
TypedLit (TypeName [Name "char varying"]) "test"
cast('test' as varbinary)
Cast (StringLit "test") (TypeName [Name "varbinary"])
varbinary 'test'
TypedLit (TypeName [Name "varbinary"]) "test"
cast('test' as varchar)
Cast (StringLit "test") (TypeName [Name "varchar"])
varchar 'test'
TypedLit (TypeName [Name "varchar"]) "test"
cast('test' as character large object)
Cast (StringLit "test") (TypeName [Name "character large object"])
character large object 'test'
TypedLit (TypeName [Name "character large object"]) "test"
cast('test' as char large object)
Cast (StringLit "test") (TypeName [Name "char large object"])
char large object 'test'
TypedLit (TypeName [Name "char large object"]) "test"
cast('test' as clob)
Cast (StringLit "test") (TypeName [Name "clob"])
clob 'test'
TypedLit (TypeName [Name "clob"]) "test"
cast('test' as national character)
Cast (StringLit "test") (TypeName [Name "national character"])
national character 'test'
TypedLit (TypeName [Name "national character"]) "test"
cast('test' as national char)
Cast (StringLit "test") (TypeName [Name "national char"])
national char 'test'
TypedLit (TypeName [Name "national char"]) "test"
cast('test' as nchar)
Cast (StringLit "test") (TypeName [Name "nchar"])
nchar 'test'
TypedLit (TypeName [Name "nchar"]) "test"
cast('test' as national character varying)
Cast (StringLit "test")
  (TypeName [Name "national character varying"])
national character varying 'test'
TypedLit (TypeName [Name "national character varying"]) "test"
cast('test' as national char varying)
Cast (StringLit "test") (TypeName [Name "national char varying"])
national char varying 'test'
TypedLit (TypeName [Name "national char varying"]) "test"
cast('test' as nchar varying)
Cast (StringLit "test") (TypeName [Name "nchar varying"])
nchar varying 'test'
TypedLit (TypeName [Name "nchar varying"]) "test"
cast('test' as national character large object)
Cast (StringLit "test")
  (TypeName [Name "national character large object"])
national character large object 'test'
TypedLit (TypeName [Name "national character large object"]) "test"
cast('test' as nchar large object)
Cast (StringLit "test") (TypeName [Name "nchar large object"])
nchar large object 'test'
TypedLit (TypeName [Name "nchar large object"]) "test"
cast('test' as nclob)
Cast (StringLit "test") (TypeName [Name "nclob"])
nclob 'test'
TypedLit (TypeName [Name "nclob"]) "test"
cast('test' as binary large object)
Cast (StringLit "test") (TypeName [Name "binary large object"])
binary large object 'test'
TypedLit (TypeName [Name "binary large object"]) "test"
cast('test' as blob)
Cast (StringLit "test") (TypeName [Name "blob"])
blob 'test'
TypedLit (TypeName [Name "blob"]) "test"
cast('test' as numeric)
Cast (StringLit "test") (TypeName [Name "numeric"])
numeric 'test'
TypedLit (TypeName [Name "numeric"]) "test"
cast('test' as decimal)
Cast (StringLit "test") (TypeName [Name "decimal"])
decimal 'test'
TypedLit (TypeName [Name "decimal"]) "test"
cast('test' as dec)
Cast (StringLit "test") (TypeName [Name "dec"])
dec 'test'
TypedLit (TypeName [Name "dec"]) "test"
cast('test' as smallint)
Cast (StringLit "test") (TypeName [Name "smallint"])
smallint 'test'
TypedLit (TypeName [Name "smallint"]) "test"
cast('test' as integer)
Cast (StringLit "test") (TypeName [Name "integer"])
integer 'test'
TypedLit (TypeName [Name "integer"]) "test"
cast('test' as int)
Cast (StringLit "test") (TypeName [Name "int"])
int 'test'
TypedLit (TypeName [Name "int"]) "test"
cast('test' as bigint)
Cast (StringLit "test") (TypeName [Name "bigint"])
bigint 'test'
TypedLit (TypeName [Name "bigint"]) "test"
cast('test' as float)
Cast (StringLit "test") (TypeName [Name "float"])
float 'test'
TypedLit (TypeName [Name "float"]) "test"
cast('test' as real)
Cast (StringLit "test") (TypeName [Name "real"])
real 'test'
TypedLit (TypeName [Name "real"]) "test"
cast('test' as double precision)
Cast (StringLit "test") (TypeName [Name "double precision"])
double precision 'test'
TypedLit (TypeName [Name "double precision"]) "test"
cast('test' as boolean)
Cast (StringLit "test") (TypeName [Name "boolean"])
boolean 'test'
TypedLit (TypeName [Name "boolean"]) "test"
cast('test' as date)
Cast (StringLit "test") (TypeName [Name "date"])
date 'test'
TypedLit (TypeName [Name "date"]) "test"
cast('test' as time)
Cast (StringLit "test") (TypeName [Name "time"])
time 'test'
TypedLit (TypeName [Name "time"]) "test"
cast('test' as timestamp)
Cast (StringLit "test") (TypeName [Name "timestamp"])
timestamp 'test'
TypedLit (TypeName [Name "timestamp"]) "test"
cast('test' as char(5))
Cast (StringLit "test") (PrecTypeName [Name "char"] 5)
char(5) 'test'
TypedLit (PrecTypeName [Name "char"] 5) "test"
cast('test' as char varying(5))
Cast (StringLit "test") (PrecTypeName [Name "char varying"] 5)
char varying(5) 'test'
TypedLit (PrecTypeName [Name "char varying"] 5) "test"
cast('test' as decimal(15,2))
Cast (StringLit "test") (PrecScaleTypeName [Name "decimal"] 15 2)
decimal(15,2) 'test'
TypedLit (PrecScaleTypeName [Name "decimal"] 15 2) "test"
cast('test' as char(3 octets))
Cast (StringLit "test")
  (PrecLengthTypeName [Name "char"] 3 Nothing (Just PrecOctets))
char(3 octets) 'test'
TypedLit
  (PrecLengthTypeName [Name "char"] 3 Nothing (Just PrecOctets))
  "test"
cast('test' as varchar(50 characters))
Cast (StringLit "test")
  (PrecLengthTypeName [Name "varchar"] 50 Nothing
     (Just PrecCharacters))
varchar(50 characters) 'test'
TypedLit
  (PrecLengthTypeName [Name "varchar"] 50 Nothing
     (Just PrecCharacters))
  "test"
cast('test' as blob(3M))
Cast (StringLit "test")
  (PrecLengthTypeName [Name "blob"] 3 (Just PrecM) Nothing)
blob(3M) 'test'
TypedLit (PrecLengthTypeName [Name "blob"] 3 (Just PrecM) Nothing)
  "test"
cast('test' as blob(3T))
Cast (StringLit "test")
  (PrecLengthTypeName [Name "blob"] 3 (Just PrecT) Nothing)
blob(3T) 'test'
TypedLit (PrecLengthTypeName [Name "blob"] 3 (Just PrecT) Nothing)
  "test"
cast('test' as blob(3P))
Cast (StringLit "test")
  (PrecLengthTypeName [Name "blob"] 3 (Just PrecP) Nothing)
blob(3P) 'test'
TypedLit (PrecLengthTypeName [Name "blob"] 3 (Just PrecP) Nothing)
  "test"
cast('test' as blob(4M characters) )
Cast (StringLit "test")
  (PrecLengthTypeName [Name "blob"] 4 (Just PrecM)
     (Just PrecCharacters))
blob(4M characters)  'test'
TypedLit
  (PrecLengthTypeName [Name "blob"] 4 (Just PrecM)
     (Just PrecCharacters))
  "test"
cast('test' as blob(6G octets) )
Cast (StringLit "test")
  (PrecLengthTypeName [Name "blob"] 6 (Just PrecG) (Just PrecOctets))
blob(6G octets)  'test'
TypedLit
  (PrecLengthTypeName [Name "blob"] 6 (Just PrecG) (Just PrecOctets))
  "test"
cast('test' as national character large object(7K) )
Cast (StringLit "test")
  (PrecLengthTypeName [Name "national character large object"] 7
     (Just PrecK)
     Nothing)
national character large object(7K)  'test'
TypedLit
  (PrecLengthTypeName [Name "national character large object"] 7
     (Just PrecK)
     Nothing)
  "test"
cast('test' as time with time zone)
Cast (StringLit "test") (TimeTypeName [Name "time"] Nothing True)
time with time zone 'test'
TypedLit (TimeTypeName [Name "time"] Nothing True) "test"
cast('test' as datetime(3) without time zone)
Cast (StringLit "test")
  (TimeTypeName [Name "datetime"] (Just 3) False)
datetime(3) without time zone 'test'
TypedLit (TimeTypeName [Name "datetime"] (Just 3) False) "test"
cast('test' as char varying(5) character set something collate something_insensitive)
Cast (StringLit "test")
  (CharTypeName [Name "char varying"] (Just 5) [Name "something"]
     [Name "something_insensitive"])
char varying(5) character set something collate something_insensitive 'test'
TypedLit
  (CharTypeName [Name "char varying"] (Just 5) [Name "something"]
     [Name "something_insensitive"])
  "test"
cast('test' as char(5) character set something collate something_insensitive)
Cast (StringLit "test")
  (CharTypeName [Name "char"] (Just 5) [Name "something"]
     [Name "something_insensitive"])
char(5) character set something collate something_insensitive 'test'
TypedLit
  (CharTypeName [Name "char"] (Just 5) [Name "something"]
     [Name "something_insensitive"])
  "test"
cast('test' as char varying character set something collate something_insensitive)
Cast (StringLit "test")
  (CharTypeName [Name "char varying"] Nothing [Name "something"]
     [Name "something_insensitive"])
char varying character set something collate something_insensitive 'test'
TypedLit
  (CharTypeName [Name "char varying"] Nothing [Name "something"]
     [Name "something_insensitive"])
  "test"
cast('test' as char character set something collate something_insensitive)
Cast (StringLit "test")
  (CharTypeName [Name "char"] Nothing [Name "something"]
     [Name "something_insensitive"])
char character set something collate something_insensitive 'test'
TypedLit
  (CharTypeName [Name "char"] Nothing [Name "something"]
     [Name "something_insensitive"])
  "test"
cast('test' as char varying(5) collate something_insensitive)
Cast (StringLit "test")
  (CharTypeName [Name "char varying"] (Just 5) []
     [Name "something_insensitive"])
char varying(5) collate something_insensitive 'test'
TypedLit
  (CharTypeName [Name "char varying"] (Just 5) []
     [Name "something_insensitive"])
  "test"
cast('test' as char(5) collate something_insensitive)
Cast (StringLit "test")
  (CharTypeName [Name "char"] (Just 5) []
     [Name "something_insensitive"])
char(5) collate something_insensitive 'test'
TypedLit
  (CharTypeName [Name "char"] (Just 5) []
     [Name "something_insensitive"])
  "test"
cast('test' as char varying collate something_insensitive)
Cast (StringLit "test")
  (CharTypeName [Name "char varying"] Nothing []
     [Name "something_insensitive"])
char varying collate something_insensitive 'test'
TypedLit
  (CharTypeName [Name "char varying"] Nothing []
     [Name "something_insensitive"])
  "test"
cast('test' as char collate something_insensitive)
Cast (StringLit "test")
  (CharTypeName [Name "char"] Nothing []
     [Name "something_insensitive"])
char collate something_insensitive 'test'
TypedLit
  (CharTypeName [Name "char"] Nothing []
     [Name "something_insensitive"])
  "test"
cast('test' as char varying(5) character set something)
Cast (StringLit "test")
  (CharTypeName [Name "char varying"] (Just 5) [Name "something"] [])
char varying(5) character set something 'test'
TypedLit
  (CharTypeName [Name "char varying"] (Just 5) [Name "something"] [])
  "test"
cast('test' as char(5) character set something)
Cast (StringLit "test")
  (CharTypeName [Name "char"] (Just 5) [Name "something"] [])
char(5) character set something 'test'
TypedLit
  (CharTypeName [Name "char"] (Just 5) [Name "something"] [])
  "test"
cast('test' as char varying character set something)
Cast (StringLit "test")
  (CharTypeName [Name "char varying"] Nothing [Name "something"] [])
char varying character set something 'test'
TypedLit
  (CharTypeName [Name "char varying"] Nothing [Name "something"] [])
  "test"
cast('test' as char character set something)
Cast (StringLit "test")
  (CharTypeName [Name "char"] Nothing [Name "something"] [])
char character set something 'test'
TypedLit (CharTypeName [Name "char"] Nothing [Name "something"] [])
  "test"
cast('test' as char varying character set something)
Cast (StringLit "test")
  (CharTypeName [Name "char varying"] Nothing [Name "something"] [])
char varying character set something 'test'
TypedLit
  (CharTypeName [Name "char varying"] Nothing [Name "something"] [])
  "test"
cast('test' as row(a int))
Cast (StringLit "test")
  (RowTypeName [(Name "a", TypeName [Name "int"])])
row(a int) 'test'
TypedLit (RowTypeName [(Name "a", TypeName [Name "int"])]) "test"
cast('test' as row(a int,b char))
Cast (StringLit "test")
  (RowTypeName
     [(Name "a", TypeName [Name "int"]),
      (Name "b", TypeName [Name "char"])])
row(a int,b char) 'test'
TypedLit
  (RowTypeName
     [(Name "a", TypeName [Name "int"]),
      (Name "b", TypeName [Name "char"])])
  "test"
cast('test' as interval year)
Cast (StringLit "test")
  (IntervalTypeName (Itf "year" Nothing) Nothing)
interval year 'test'
TypedLit (IntervalTypeName (Itf "year" Nothing) Nothing) "test"
cast('test' as interval year(2))
Cast (StringLit "test")
  (IntervalTypeName (Itf "year" (Just (2, Nothing))) Nothing)
interval year(2) 'test'
TypedLit
  (IntervalTypeName (Itf "year" (Just (2, Nothing))) Nothing)
  "test"
cast('test' as interval second(2,5))
Cast (StringLit "test")
  (IntervalTypeName (Itf "second" (Just (2, Just 5))) Nothing)
interval second(2,5) 'test'
TypedLit
  (IntervalTypeName (Itf "second" (Just (2, Just 5))) Nothing)
  "test"
cast('test' as interval year to month)
Cast (StringLit "test")
  (IntervalTypeName (Itf "year" Nothing)
     (Just (Itf "month" Nothing)))
interval year to month 'test'
TypedLit
  (IntervalTypeName (Itf "year" Nothing)
     (Just (Itf "month" Nothing)))
  "test"
cast('test' as interval year(4) to second(2,3))
Cast (StringLit "test")
  (IntervalTypeName (Itf "year" (Just (4, Nothing)))
     (Just (Itf "second" (Just (2, Just 3)))))
interval year(4) to second(2,3) 'test'
TypedLit
  (IntervalTypeName (Itf "year" (Just (4, Nothing)))
     (Just (Itf "second" (Just (2, Just 3)))))
  "test"
cast('test' as binary array)
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "binary"]) Nothing)
binary array 'test'
TypedLit (ArrayTypeName (TypeName [Name "binary"]) Nothing) "test"
cast('test' as binary array[5])
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "binary"]) (Just 5))
binary array[5] 'test'
TypedLit (ArrayTypeName (TypeName [Name "binary"]) (Just 5)) "test"
cast('test' as binary varying array)
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "binary varying"]) Nothing)
binary varying array 'test'
TypedLit (ArrayTypeName (TypeName [Name "binary varying"]) Nothing)
  "test"
cast('test' as binary varying array[5])
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "binary varying"]) (Just 5))
binary varying array[5] 'test'
TypedLit
  (ArrayTypeName (TypeName [Name "binary varying"]) (Just 5))
  "test"
cast('test' as character array)
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "character"]) Nothing)
character array 'test'
TypedLit (ArrayTypeName (TypeName [Name "character"]) Nothing)
  "test"
cast('test' as character array[5])
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "character"]) (Just 5))
character array[5] 'test'
TypedLit (ArrayTypeName (TypeName [Name "character"]) (Just 5))
  "test"
cast('test' as char array)
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "char"]) Nothing)
char array 'test'
TypedLit (ArrayTypeName (TypeName [Name "char"]) Nothing) "test"
cast('test' as char array[5])
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "char"]) (Just 5))
char array[5] 'test'
TypedLit (ArrayTypeName (TypeName [Name "char"]) (Just 5)) "test"
cast('test' as character varying array)
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "character varying"]) Nothing)
character varying array 'test'
TypedLit
  (ArrayTypeName (TypeName [Name "character varying"]) Nothing)
  "test"
cast('test' as character varying array[5])
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "character varying"]) (Just 5))
character varying array[5] 'test'
TypedLit
  (ArrayTypeName (TypeName [Name "character varying"]) (Just 5))
  "test"
cast('test' as char varying array)
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "char varying"]) Nothing)
char varying array 'test'
TypedLit (ArrayTypeName (TypeName [Name "char varying"]) Nothing)
  "test"
cast('test' as char varying array[5])
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "char varying"]) (Just 5))
char varying array[5] 'test'
TypedLit (ArrayTypeName (TypeName [Name "char varying"]) (Just 5))
  "test"
cast('test' as varbinary array)
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "varbinary"]) Nothing)
varbinary array 'test'
TypedLit (ArrayTypeName (TypeName [Name "varbinary"]) Nothing)
  "test"
cast('test' as varbinary array[5])
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "varbinary"]) (Just 5))
varbinary array[5] 'test'
TypedLit (ArrayTypeName (TypeName [Name "varbinary"]) (Just 5))
  "test"
cast('test' as varchar array)
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "varchar"]) Nothing)
varchar array 'test'
TypedLit (ArrayTypeName (TypeName [Name "varchar"]) Nothing) "test"
cast('test' as varchar array[5])
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "varchar"]) (Just 5))
varchar array[5] 'test'
TypedLit (ArrayTypeName (TypeName [Name "varchar"]) (Just 5))
  "test"
cast('test' as character large object array)
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "character large object"]) Nothing)
character large object array 'test'
TypedLit
  (ArrayTypeName (TypeName [Name "character large object"]) Nothing)
  "test"
cast('test' as character large object array[5])
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "character large object"]) (Just 5))
character large object array[5] 'test'
TypedLit
  (ArrayTypeName (TypeName [Name "character large object"]) (Just 5))
  "test"
cast('test' as char large object array)
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "char large object"]) Nothing)
char large object array 'test'
TypedLit
  (ArrayTypeName (TypeName [Name "char large object"]) Nothing)
  "test"
cast('test' as char large object array[5])
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "char large object"]) (Just 5))
char large object array[5] 'test'
TypedLit
  (ArrayTypeName (TypeName [Name "char large object"]) (Just 5))
  "test"
cast('test' as clob array)
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "clob"]) Nothing)
clob array 'test'
TypedLit (ArrayTypeName (TypeName [Name "clob"]) Nothing) "test"
cast('test' as clob array[5])
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "clob"]) (Just 5))
clob array[5] 'test'
TypedLit (ArrayTypeName (TypeName [Name "clob"]) (Just 5)) "test"
cast('test' as national character array)
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "national character"]) Nothing)
national character array 'test'
TypedLit
  (ArrayTypeName (TypeName [Name "national character"]) Nothing)
  "test"
cast('test' as national character array[5])
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "national character"]) (Just 5))
national character array[5] 'test'
TypedLit
  (ArrayTypeName (TypeName [Name "national character"]) (Just 5))
  "test"
cast('test' as national char array)
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "national char"]) Nothing)
national char array 'test'
TypedLit (ArrayTypeName (TypeName [Name "national char"]) Nothing)
  "test"
cast('test' as national char array[5])
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "national char"]) (Just 5))
national char array[5] 'test'
TypedLit (ArrayTypeName (TypeName [Name "national char"]) (Just 5))
  "test"
cast('test' as nchar array)
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "nchar"]) Nothing)
nchar array 'test'
TypedLit (ArrayTypeName (TypeName [Name "nchar"]) Nothing) "test"
cast('test' as nchar array[5])
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "nchar"]) (Just 5))
nchar array[5] 'test'
TypedLit (ArrayTypeName (TypeName [Name "nchar"]) (Just 5)) "test"
cast('test' as national character varying array)
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "national character varying"])
     Nothing)
national character varying array 'test'
TypedLit
  (ArrayTypeName (TypeName [Name "national character varying"])
     Nothing)
  "test"
cast('test' as national character varying array[5])
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "national character varying"])
     (Just 5))
national character varying array[5] 'test'
TypedLit
  (ArrayTypeName (TypeName [Name "national character varying"])
     (Just 5))
  "test"
cast('test' as national char varying array)
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "national char varying"]) Nothing)
national char varying array 'test'
TypedLit
  (ArrayTypeName (TypeName [Name "national char varying"]) Nothing)
  "test"
cast('test' as national char varying array[5])
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "national char varying"]) (Just 5))
national char varying array[5] 'test'
TypedLit
  (ArrayTypeName (TypeName [Name "national char varying"]) (Just 5))
  "test"
cast('test' as nchar varying array)
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "nchar varying"]) Nothing)
nchar varying array 'test'
TypedLit (ArrayTypeName (TypeName [Name "nchar varying"]) Nothing)
  "test"
cast('test' as nchar varying array[5])
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "nchar varying"]) (Just 5))
nchar varying array[5] 'test'
TypedLit (ArrayTypeName (TypeName [Name "nchar varying"]) (Just 5))
  "test"
cast('test' as national character large object array)
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "national character large object"])
     Nothing)
national character large object array 'test'
TypedLit
  (ArrayTypeName (TypeName [Name "national character large object"])
     Nothing)
  "test"
cast('test' as national character large object array[5])
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "national character large object"])
     (Just 5))
national character large object array[5] 'test'
TypedLit
  (ArrayTypeName (TypeName [Name "national character large object"])
     (Just 5))
  "test"
cast('test' as nchar large object array)
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "nchar large object"]) Nothing)
nchar large object array 'test'
TypedLit
  (ArrayTypeName (TypeName [Name "nchar large object"]) Nothing)
  "test"
cast('test' as nchar large object array[5])
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "nchar large object"]) (Just 5))
nchar large object array[5] 'test'
TypedLit
  (ArrayTypeName (TypeName [Name "nchar large object"]) (Just 5))
  "test"
cast('test' as nclob array)
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "nclob"]) Nothing)
nclob array 'test'
TypedLit (ArrayTypeName (TypeName [Name "nclob"]) Nothing) "test"
cast('test' as nclob array[5])
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "nclob"]) (Just 5))
nclob array[5] 'test'
TypedLit (ArrayTypeName (TypeName [Name "nclob"]) (Just 5)) "test"
cast('test' as binary large object array)
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "binary large object"]) Nothing)
binary large object array 'test'
TypedLit
  (ArrayTypeName (TypeName [Name "binary large object"]) Nothing)
  "test"
cast('test' as binary large object array[5])
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "binary large object"]) (Just 5))
binary large object array[5] 'test'
TypedLit
  (ArrayTypeName (TypeName [Name "binary large object"]) (Just 5))
  "test"
cast('test' as blob array)
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "blob"]) Nothing)
blob array 'test'
TypedLit (ArrayTypeName (TypeName [Name "blob"]) Nothing) "test"
cast('test' as blob array[5])
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "blob"]) (Just 5))
blob array[5] 'test'
TypedLit (ArrayTypeName (TypeName [Name "blob"]) (Just 5)) "test"
cast('test' as numeric array)
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "numeric"]) Nothing)
numeric array 'test'
TypedLit (ArrayTypeName (TypeName [Name "numeric"]) Nothing) "test"
cast('test' as numeric array[5])
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "numeric"]) (Just 5))
numeric array[5] 'test'
TypedLit (ArrayTypeName (TypeName [Name "numeric"]) (Just 5))
  "test"
cast('test' as decimal array)
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "decimal"]) Nothing)
decimal array 'test'
TypedLit (ArrayTypeName (TypeName [Name "decimal"]) Nothing) "test"
cast('test' as decimal array[5])
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "decimal"]) (Just 5))
decimal array[5] 'test'
TypedLit (ArrayTypeName (TypeName [Name "decimal"]) (Just 5))
  "test"
cast('test' as dec array)
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "dec"]) Nothing)
dec array 'test'
TypedLit (ArrayTypeName (TypeName [Name "dec"]) Nothing) "test"
cast('test' as dec array[5])
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "dec"]) (Just 5))
dec array[5] 'test'
TypedLit (ArrayTypeName (TypeName [Name "dec"]) (Just 5)) "test"
cast('test' as smallint array)
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "smallint"]) Nothing)
smallint array 'test'
TypedLit (ArrayTypeName (TypeName [Name "smallint"]) Nothing)
  "test"
cast('test' as smallint array[5])
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "smallint"]) (Just 5))
smallint array[5] 'test'
TypedLit (ArrayTypeName (TypeName [Name "smallint"]) (Just 5))
  "test"
cast('test' as integer array)
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "integer"]) Nothing)
integer array 'test'
TypedLit (ArrayTypeName (TypeName [Name "integer"]) Nothing) "test"
cast('test' as integer array[5])
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "integer"]) (Just 5))
integer array[5] 'test'
TypedLit (ArrayTypeName (TypeName [Name "integer"]) (Just 5))
  "test"
cast('test' as int array)
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "int"]) Nothing)
int array 'test'
TypedLit (ArrayTypeName (TypeName [Name "int"]) Nothing) "test"
cast('test' as int array[5])
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "int"]) (Just 5))
int array[5] 'test'
TypedLit (ArrayTypeName (TypeName [Name "int"]) (Just 5)) "test"
cast('test' as bigint array)
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "bigint"]) Nothing)
bigint array 'test'
TypedLit (ArrayTypeName (TypeName [Name "bigint"]) Nothing) "test"
cast('test' as bigint array[5])
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "bigint"]) (Just 5))
bigint array[5] 'test'
TypedLit (ArrayTypeName (TypeName [Name "bigint"]) (Just 5)) "test"
cast('test' as float array)
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "float"]) Nothing)
float array 'test'
TypedLit (ArrayTypeName (TypeName [Name "float"]) Nothing) "test"
cast('test' as float array[5])
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "float"]) (Just 5))
float array[5] 'test'
TypedLit (ArrayTypeName (TypeName [Name "float"]) (Just 5)) "test"
cast('test' as real array)
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "real"]) Nothing)
real array 'test'
TypedLit (ArrayTypeName (TypeName [Name "real"]) Nothing) "test"
cast('test' as real array[5])
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "real"]) (Just 5))
real array[5] 'test'
TypedLit (ArrayTypeName (TypeName [Name "real"]) (Just 5)) "test"
cast('test' as double precision array)
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "double precision"]) Nothing)
double precision array 'test'
TypedLit
  (ArrayTypeName (TypeName [Name "double precision"]) Nothing)
  "test"
cast('test' as double precision array[5])
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "double precision"]) (Just 5))
double precision array[5] 'test'
TypedLit
  (ArrayTypeName (TypeName [Name "double precision"]) (Just 5))
  "test"
cast('test' as boolean array)
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "boolean"]) Nothing)
boolean array 'test'
TypedLit (ArrayTypeName (TypeName [Name "boolean"]) Nothing) "test"
cast('test' as boolean array[5])
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "boolean"]) (Just 5))
boolean array[5] 'test'
TypedLit (ArrayTypeName (TypeName [Name "boolean"]) (Just 5))
  "test"
cast('test' as date array)
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "date"]) Nothing)
date array 'test'
TypedLit (ArrayTypeName (TypeName [Name "date"]) Nothing) "test"
cast('test' as date array[5])
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "date"]) (Just 5))
date array[5] 'test'
TypedLit (ArrayTypeName (TypeName [Name "date"]) (Just 5)) "test"
cast('test' as time array)
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "time"]) Nothing)
time array 'test'
TypedLit (ArrayTypeName (TypeName [Name "time"]) Nothing) "test"
cast('test' as time array[5])
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "time"]) (Just 5))
time array[5] 'test'
TypedLit (ArrayTypeName (TypeName [Name "time"]) (Just 5)) "test"
cast('test' as timestamp array)
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "timestamp"]) Nothing)
timestamp array 'test'
TypedLit (ArrayTypeName (TypeName [Name "timestamp"]) Nothing)
  "test"
cast('test' as timestamp array[5])
Cast (StringLit "test")
  (ArrayTypeName (TypeName [Name "timestamp"]) (Just 5))
timestamp array[5] 'test'
TypedLit (ArrayTypeName (TypeName [Name "timestamp"]) (Just 5))
  "test"
cast('test' as char(5) array)
Cast (StringLit "test")
  (ArrayTypeName (PrecTypeName [Name "char"] 5) Nothing)
char(5) array 'test'
TypedLit (ArrayTypeName (PrecTypeName [Name "char"] 5) Nothing)
  "test"
cast('test' as char(5) array[5])
Cast (StringLit "test")
  (ArrayTypeName (PrecTypeName [Name "char"] 5) (Just 5))
char(5) array[5] 'test'
TypedLit (ArrayTypeName (PrecTypeName [Name "char"] 5) (Just 5))
  "test"
cast('test' as char varying(5) array)
Cast (StringLit "test")
  (ArrayTypeName (PrecTypeName [Name "char varying"] 5) Nothing)
char varying(5) array 'test'
TypedLit
  (ArrayTypeName (PrecTypeName [Name "char varying"] 5) Nothing)
  "test"
cast('test' as char varying(5) array[5])
Cast (StringLit "test")
  (ArrayTypeName (PrecTypeName [Name "char varying"] 5) (Just 5))
char varying(5) array[5] 'test'
TypedLit
  (ArrayTypeName (PrecTypeName [Name "char varying"] 5) (Just 5))
  "test"
cast('test' as decimal(15,2) array)
Cast (StringLit "test")
  (ArrayTypeName (PrecScaleTypeName [Name "decimal"] 15 2) Nothing)
decimal(15,2) array 'test'
TypedLit
  (ArrayTypeName (PrecScaleTypeName [Name "decimal"] 15 2) Nothing)
  "test"
cast('test' as decimal(15,2) array[5])
Cast (StringLit "test")
  (ArrayTypeName (PrecScaleTypeName [Name "decimal"] 15 2) (Just 5))
decimal(15,2) array[5] 'test'
TypedLit
  (ArrayTypeName (PrecScaleTypeName [Name "decimal"] 15 2) (Just 5))
  "test"
cast('test' as char(3 octets) array)
Cast (StringLit "test")
  (ArrayTypeName
     (PrecLengthTypeName [Name "char"] 3 Nothing (Just PrecOctets))
     Nothing)
char(3 octets) array 'test'
TypedLit
  (ArrayTypeName
     (PrecLengthTypeName [Name "char"] 3 Nothing (Just PrecOctets))
     Nothing)
  "test"
cast('test' as char(3 octets) array[5])
Cast (StringLit "test")
  (ArrayTypeName
     (PrecLengthTypeName [Name "char"] 3 Nothing (Just PrecOctets))
     (Just 5))
char(3 octets) array[5] 'test'
TypedLit
  (ArrayTypeName
     (PrecLengthTypeName [Name "char"] 3 Nothing (Just PrecOctets))
     (Just 5))
  "test"
cast('test' as varchar(50 characters) array)
Cast (StringLit "test")
  (ArrayTypeName
     (PrecLengthTypeName [Name "varchar"] 50 Nothing
        (Just PrecCharacters))
     Nothing)
varchar(50 characters) array 'test'
TypedLit
  (ArrayTypeName
     (PrecLengthTypeName [Name "varchar"] 50 Nothing
        (Just PrecCharacters))
     Nothing)
  "test"
cast('test' as varchar(50 characters) array[5])
Cast (StringLit "test")
  (ArrayTypeName
     (PrecLengthTypeName [Name "varchar"] 50 Nothing
        (Just PrecCharacters))
     (Just 5))
varchar(50 characters) array[5] 'test'
TypedLit
  (ArrayTypeName
     (PrecLengthTypeName [Name "varchar"] 50 Nothing
        (Just PrecCharacters))
     (Just 5))
  "test"
cast('test' as blob(3M) array)
Cast (StringLit "test")
  (ArrayTypeName
     (PrecLengthTypeName [Name "blob"] 3 (Just PrecM) Nothing)
     Nothing)
blob(3M) array 'test'
TypedLit
  (ArrayTypeName
     (PrecLengthTypeName [Name "blob"] 3 (Just PrecM) Nothing)
     Nothing)
  "test"
cast('test' as blob(3M) array[5])
Cast (StringLit "test")
  (ArrayTypeName
     (PrecLengthTypeName [Name "blob"] 3 (Just PrecM) Nothing)
     (Just 5))
blob(3M) array[5] 'test'
TypedLit
  (ArrayTypeName
     (PrecLengthTypeName [Name "blob"] 3 (Just PrecM) Nothing)
     (Just 5))
  "test"
cast('test' as blob(3T) array)
Cast (StringLit "test")
  (ArrayTypeName
     (PrecLengthTypeName [Name "blob"] 3 (Just PrecT) Nothing)
     Nothing)
blob(3T) array 'test'
TypedLit
  (ArrayTypeName
     (PrecLengthTypeName [Name "blob"] 3 (Just PrecT) Nothing)
     Nothing)
  "test"
cast('test' as blob(3T) array[5])
Cast (StringLit "test")
  (ArrayTypeName
     (PrecLengthTypeName [Name "blob"] 3 (Just PrecT) Nothing)
     (Just 5))
blob(3T) array[5] 'test'
TypedLit
  (ArrayTypeName
     (PrecLengthTypeName [Name "blob"] 3 (Just PrecT) Nothing)
     (Just 5))
  "test"
cast('test' as blob(3P) array)
Cast (StringLit "test")
  (ArrayTypeName
     (PrecLengthTypeName [Name "blob"] 3 (Just PrecP) Nothing)
     Nothing)
blob(3P) array 'test'
TypedLit
  (ArrayTypeName
     (PrecLengthTypeName [Name "blob"] 3 (Just PrecP) Nothing)
     Nothing)
  "test"
cast('test' as blob(3P) array[5])
Cast (StringLit "test")
  (ArrayTypeName
     (PrecLengthTypeName [Name "blob"] 3 (Just PrecP) Nothing)
     (Just 5))
blob(3P) array[5] 'test'
TypedLit
  (ArrayTypeName
     (PrecLengthTypeName [Name "blob"] 3 (Just PrecP) Nothing)
     (Just 5))
  "test"
cast('test' as blob(4M characters)  array)
Cast (StringLit "test")
  (ArrayTypeName
     (PrecLengthTypeName [Name "blob"] 4 (Just PrecM)
        (Just PrecCharacters))
     Nothing)
blob(4M characters)  array 'test'
TypedLit
  (ArrayTypeName
     (PrecLengthTypeName [Name "blob"] 4 (Just PrecM)
        (Just PrecCharacters))
     Nothing)
  "test"
cast('test' as blob(4M characters)  array[5])
Cast (StringLit "test")
  (ArrayTypeName
     (PrecLengthTypeName [Name "blob"] 4 (Just PrecM)
        (Just PrecCharacters))
     (Just 5))
blob(4M characters)  array[5] 'test'
TypedLit
  (ArrayTypeName
     (PrecLengthTypeName [Name "blob"] 4 (Just PrecM)
        (Just PrecCharacters))
     (Just 5))
  "test"
cast('test' as blob(6G octets)  array)
Cast (StringLit "test")
  (ArrayTypeName
     (PrecLengthTypeName [Name "blob"] 6 (Just PrecG) (Just PrecOctets))
     Nothing)
blob(6G octets)  array 'test'
TypedLit
  (ArrayTypeName
     (PrecLengthTypeName [Name "blob"] 6 (Just PrecG) (Just PrecOctets))
     Nothing)
  "test"
cast('test' as blob(6G octets)  array[5])
Cast (StringLit "test")
  (ArrayTypeName
     (PrecLengthTypeName [Name "blob"] 6 (Just PrecG) (Just PrecOctets))
     (Just 5))
blob(6G octets)  array[5] 'test'
TypedLit
  (ArrayTypeName
     (PrecLengthTypeName [Name "blob"] 6 (Just PrecG) (Just PrecOctets))
     (Just 5))
  "test"
cast('test' as national character large object(7K)  array)
Cast (StringLit "test")
  (ArrayTypeName
     (PrecLengthTypeName [Name "national character large object"] 7
        (Just PrecK)
        Nothing)
     Nothing)
national character large object(7K)  array 'test'
TypedLit
  (ArrayTypeName
     (PrecLengthTypeName [Name "national character large object"] 7
        (Just PrecK)
        Nothing)
     Nothing)
  "test"
cast('test' as national character large object(7K)  array[5])
Cast (StringLit "test")
  (ArrayTypeName
     (PrecLengthTypeName [Name "national character large object"] 7
        (Just PrecK)
        Nothing)
     (Just 5))
national character large object(7K)  array[5] 'test'
TypedLit
  (ArrayTypeName
     (PrecLengthTypeName [Name "national character large object"] 7
        (Just PrecK)
        Nothing)
     (Just 5))
  "test"
cast('test' as time with time zone array)
Cast (StringLit "test")
  (ArrayTypeName (TimeTypeName [Name "time"] Nothing True) Nothing)
time with time zone array 'test'
TypedLit
  (ArrayTypeName (TimeTypeName [Name "time"] Nothing True) Nothing)
  "test"
cast('test' as time with time zone array[5])
Cast (StringLit "test")
  (ArrayTypeName (TimeTypeName [Name "time"] Nothing True) (Just 5))
time with time zone array[5] 'test'
TypedLit
  (ArrayTypeName (TimeTypeName [Name "time"] Nothing True) (Just 5))
  "test"
cast('test' as datetime(3) without time zone array)
Cast (StringLit "test")
  (ArrayTypeName (TimeTypeName [Name "datetime"] (Just 3) False)
     Nothing)
datetime(3) without time zone array 'test'
TypedLit
  (ArrayTypeName (TimeTypeName [Name "datetime"] (Just 3) False)
     Nothing)
  "test"
cast('test' as datetime(3) without time zone array[5])
Cast (StringLit "test")
  (ArrayTypeName (TimeTypeName [Name "datetime"] (Just 3) False)
     (Just 5))
datetime(3) without time zone array[5] 'test'
TypedLit
  (ArrayTypeName (TimeTypeName [Name "datetime"] (Just 3) False)
     (Just 5))
  "test"
cast('test' as char varying(5) character set something collate something_insensitive array)
Cast (StringLit "test")
  (ArrayTypeName
     (CharTypeName [Name "char varying"] (Just 5) [Name "something"]
        [Name "something_insensitive"])
     Nothing)
char varying(5) character set something collate something_insensitive array 'test'
TypedLit
  (ArrayTypeName
     (CharTypeName [Name "char varying"] (Just 5) [Name "something"]
        [Name "something_insensitive"])
     Nothing)
  "test"
cast('test' as char varying(5) character set something collate something_insensitive array[5])
Cast (StringLit "test")
  (ArrayTypeName
     (CharTypeName [Name "char varying"] (Just 5) [Name "something"]
        [Name "something_insensitive"])
     (Just 5))
char varying(5) character set something collate something_insensitive array[5] 'test'
TypedLit
  (ArrayTypeName
     (CharTypeName [Name "char varying"] (Just 5) [Name "something"]
        [Name "something_insensitive"])
     (Just 5))
  "test"
cast('test' as char(5) character set something collate something_insensitive array)
Cast (StringLit "test")
  (ArrayTypeName
     (CharTypeName [Name "char"] (Just 5) [Name "something"]
        [Name "something_insensitive"])
     Nothing)
char(5) character set something collate something_insensitive array 'test'
TypedLit
  (ArrayTypeName
     (CharTypeName [Name "char"] (Just 5) [Name "something"]
        [Name "something_insensitive"])
     Nothing)
  "test"
cast('test' as char(5) character set something collate something_insensitive array[5])
Cast (StringLit "test")
  (ArrayTypeName
     (CharTypeName [Name "char"] (Just 5) [Name "something"]
        [Name "something_insensitive"])
     (Just 5))
char(5) character set something collate something_insensitive array[5] 'test'
TypedLit
  (ArrayTypeName
     (CharTypeName [Name "char"] (Just 5) [Name "something"]
        [Name "something_insensitive"])
     (Just 5))
  "test"
cast('test' as char varying character set something collate something_insensitive array)
Cast (StringLit "test")
  (ArrayTypeName
     (CharTypeName [Name "char varying"] Nothing [Name "something"]
        [Name "something_insensitive"])
     Nothing)
char varying character set something collate something_insensitive array 'test'
TypedLit
  (ArrayTypeName
     (CharTypeName [Name "char varying"] Nothing [Name "something"]
        [Name "something_insensitive"])
     Nothing)
  "test"
cast('test' as char varying character set something collate something_insensitive array[5])
Cast (StringLit "test")
  (ArrayTypeName
     (CharTypeName [Name "char varying"] Nothing [Name "something"]
        [Name "something_insensitive"])
     (Just 5))
char varying character set something collate something_insensitive array[5] 'test'
TypedLit
  (ArrayTypeName
     (CharTypeName [Name "char varying"] Nothing [Name "something"]
        [Name "something_insensitive"])
     (Just 5))
  "test"
cast('test' as char character set something collate something_insensitive array)
Cast (StringLit "test")
  (ArrayTypeName
     (CharTypeName [Name "char"] Nothing [Name "something"]
        [Name "something_insensitive"])
     Nothing)
char character set something collate something_insensitive array 'test'
TypedLit
  (ArrayTypeName
     (CharTypeName [Name "char"] Nothing [Name "something"]
        [Name "something_insensitive"])
     Nothing)
  "test"
cast('test' as char character set something collate something_insensitive array[5])
Cast (StringLit "test")
  (ArrayTypeName
     (CharTypeName [Name "char"] Nothing [Name "something"]
        [Name "something_insensitive"])
     (Just 5))
char character set something collate something_insensitive array[5] 'test'
TypedLit
  (ArrayTypeName
     (CharTypeName [Name "char"] Nothing [Name "something"]
        [Name "something_insensitive"])
     (Just 5))
  "test"
cast('test' as char varying(5) collate something_insensitive array)
Cast (StringLit "test")
  (ArrayTypeName
     (CharTypeName [Name "char varying"] (Just 5) []
        [Name "something_insensitive"])
     Nothing)
char varying(5) collate something_insensitive array 'test'
TypedLit
  (ArrayTypeName
     (CharTypeName [Name "char varying"] (Just 5) []
        [Name "something_insensitive"])
     Nothing)
  "test"
cast('test' as char varying(5) collate something_insensitive array[5])
Cast (StringLit "test")
  (ArrayTypeName
     (CharTypeName [Name "char varying"] (Just 5) []
        [Name "something_insensitive"])
     (Just 5))
char varying(5) collate something_insensitive array[5] 'test'
TypedLit
  (ArrayTypeName
     (CharTypeName [Name "char varying"] (Just 5) []
        [Name "something_insensitive"])
     (Just 5))
  "test"
cast('test' as char(5) collate something_insensitive array)
Cast (StringLit "test")
  (ArrayTypeName
     (CharTypeName [Name "char"] (Just 5) []
        [Name "something_insensitive"])
     Nothing)
char(5) collate something_insensitive array 'test'
TypedLit
  (ArrayTypeName
     (CharTypeName [Name "char"] (Just 5) []
        [Name "something_insensitive"])
     Nothing)
  "test"
cast('test' as char(5) collate something_insensitive array[5])
Cast (StringLit "test")
  (ArrayTypeName
     (CharTypeName [Name "char"] (Just 5) []
        [Name "something_insensitive"])
     (Just 5))
char(5) collate something_insensitive array[5] 'test'
TypedLit
  (ArrayTypeName
     (CharTypeName [Name "char"] (Just 5) []
        [Name "something_insensitive"])
     (Just 5))
  "test"
cast('test' as char varying collate something_insensitive array)
Cast (StringLit "test")
  (ArrayTypeName
     (CharTypeName [Name "char varying"] Nothing []
        [Name "something_insensitive"])
     Nothing)
char varying collate something_insensitive array 'test'
TypedLit
  (ArrayTypeName
     (CharTypeName [Name "char varying"] Nothing []
        [Name "something_insensitive"])
     Nothing)
  "test"
cast('test' as char varying collate something_insensitive array[5])
Cast (StringLit "test")
  (ArrayTypeName
     (CharTypeName [Name "char varying"] Nothing []
        [Name "something_insensitive"])
     (Just 5))
char varying collate something_insensitive array[5] 'test'
TypedLit
  (ArrayTypeName
     (CharTypeName [Name "char varying"] Nothing []
        [Name "something_insensitive"])
     (Just 5))
  "test"
cast('test' as char collate something_insensitive array)
Cast (StringLit "test")
  (ArrayTypeName
     (CharTypeName [Name "char"] Nothing []
        [Name "something_insensitive"])
     Nothing)
char collate something_insensitive array 'test'
TypedLit
  (ArrayTypeName
     (CharTypeName [Name "char"] Nothing []
        [Name "something_insensitive"])
     Nothing)
  "test"
cast('test' as char collate something_insensitive array[5])
Cast (StringLit "test")
  (ArrayTypeName
     (CharTypeName [Name "char"] Nothing []
        [Name "something_insensitive"])
     (Just 5))
char collate something_insensitive array[5] 'test'
TypedLit
  (ArrayTypeName
     (CharTypeName [Name "char"] Nothing []
        [Name "something_insensitive"])
     (Just 5))
  "test"
cast('test' as char varying(5) character set something array)
Cast (StringLit "test")
  (ArrayTypeName
     (CharTypeName [Name "char varying"] (Just 5) [Name "something"] [])
     Nothing)
char varying(5) character set something array 'test'
TypedLit
  (ArrayTypeName
     (CharTypeName [Name "char varying"] (Just 5) [Name "something"] [])
     Nothing)
  "test"
cast('test' as char varying(5) character set something array[5])
Cast (StringLit "test")
  (ArrayTypeName
     (CharTypeName [Name "char varying"] (Just 5) [Name "something"] [])
     (Just 5))
char varying(5) character set something array[5] 'test'
TypedLit
  (ArrayTypeName
     (CharTypeName [Name "char varying"] (Just 5) [Name "something"] [])
     (Just 5))
  "test"
cast('test' as char(5) character set something array)
Cast (StringLit "test")
  (ArrayTypeName
     (CharTypeName [Name "char"] (Just 5) [Name "something"] [])
     Nothing)
char(5) character set something array 'test'
TypedLit
  (ArrayTypeName
     (CharTypeName [Name "char"] (Just 5) [Name "something"] [])
     Nothing)
  "test"
cast('test' as char(5) character set something array[5])
Cast (StringLit "test")
  (ArrayTypeName
     (CharTypeName [Name "char"] (Just 5) [Name "something"] [])
     (Just 5))
char(5) character set something array[5] 'test'
TypedLit
  (ArrayTypeName
     (CharTypeName [Name "char"] (Just 5) [Name "something"] [])
     (Just 5))
  "test"
cast('test' as char varying character set something array)
Cast (StringLit "test")
  (ArrayTypeName
     (CharTypeName [Name "char varying"] Nothing [Name "something"] [])
     Nothing)
char varying character set something array 'test'
TypedLit
  (ArrayTypeName
     (CharTypeName [Name "char varying"] Nothing [Name "something"] [])
     Nothing)
  "test"
cast('test' as char varying character set something array[5])
Cast (StringLit "test")
  (ArrayTypeName
     (CharTypeName [Name "char varying"] Nothing [Name "something"] [])
     (Just 5))
char varying character set something array[5] 'test'
TypedLit
  (ArrayTypeName
     (CharTypeName [Name "char varying"] Nothing [Name "something"] [])
     (Just 5))
  "test"
cast('test' as char character set something array)
Cast (StringLit "test")
  (ArrayTypeName
     (CharTypeName [Name "char"] Nothing [Name "something"] [])
     Nothing)
char character set something array 'test'
TypedLit
  (ArrayTypeName
     (CharTypeName [Name "char"] Nothing [Name "something"] [])
     Nothing)
  "test"
cast('test' as char character set something array[5])
Cast (StringLit "test")
  (ArrayTypeName
     (CharTypeName [Name "char"] Nothing [Name "something"] [])
     (Just 5))
char character set something array[5] 'test'
TypedLit
  (ArrayTypeName
     (CharTypeName [Name "char"] Nothing [Name "something"] [])
     (Just 5))
  "test"
cast('test' as char varying character set something array)
Cast (StringLit "test")
  (ArrayTypeName
     (CharTypeName [Name "char varying"] Nothing [Name "something"] [])
     Nothing)
char varying character set something array 'test'
TypedLit
  (ArrayTypeName
     (CharTypeName [Name "char varying"] Nothing [Name "something"] [])
     Nothing)
  "test"
cast('test' as char varying character set something array[5])
Cast (StringLit "test")
  (ArrayTypeName
     (CharTypeName [Name "char varying"] Nothing [Name "something"] [])
     (Just 5))
char varying character set something array[5] 'test'
TypedLit
  (ArrayTypeName
     (CharTypeName [Name "char varying"] Nothing [Name "something"] [])
     (Just 5))
  "test"
cast('test' as row(a int) array)
Cast (StringLit "test")
  (ArrayTypeName (RowTypeName [(Name "a", TypeName [Name "int"])])
     Nothing)
row(a int) array 'test'
TypedLit
  (ArrayTypeName (RowTypeName [(Name "a", TypeName [Name "int"])])
     Nothing)
  "test"
cast('test' as row(a int) array[5])
Cast (StringLit "test")
  (ArrayTypeName (RowTypeName [(Name "a", TypeName [Name "int"])])
     (Just 5))
row(a int) array[5] 'test'
TypedLit
  (ArrayTypeName (RowTypeName [(Name "a", TypeName [Name "int"])])
     (Just 5))
  "test"
cast('test' as row(a int,b char) array)
Cast (StringLit "test")
  (ArrayTypeName
     (RowTypeName
        [(Name "a", TypeName [Name "int"]),
         (Name "b", TypeName [Name "char"])])
     Nothing)
row(a int,b char) array 'test'
TypedLit
  (ArrayTypeName
     (RowTypeName
        [(Name "a", TypeName [Name "int"]),
         (Name "b", TypeName [Name "char"])])
     Nothing)
  "test"
cast('test' as row(a int,b char) array[5])
Cast (StringLit "test")
  (ArrayTypeName
     (RowTypeName
        [(Name "a", TypeName [Name "int"]),
         (Name "b", TypeName [Name "char"])])
     (Just 5))
row(a int,b char) array[5] 'test'
TypedLit
  (ArrayTypeName
     (RowTypeName
        [(Name "a", TypeName [Name "int"]),
         (Name "b", TypeName [Name "char"])])
     (Just 5))
  "test"
cast('test' as interval year array)
Cast (StringLit "test")
  (ArrayTypeName (IntervalTypeName (Itf "year" Nothing) Nothing)
     Nothing)
interval year array 'test'
TypedLit
  (ArrayTypeName (IntervalTypeName (Itf "year" Nothing) Nothing)
     Nothing)
  "test"
cast('test' as interval year array[5])
Cast (StringLit "test")
  (ArrayTypeName (IntervalTypeName (Itf "year" Nothing) Nothing)
     (Just 5))
interval year array[5] 'test'
TypedLit
  (ArrayTypeName (IntervalTypeName (Itf "year" Nothing) Nothing)
     (Just 5))
  "test"
cast('test' as interval year(2) array)
Cast (StringLit "test")
  (ArrayTypeName
     (IntervalTypeName (Itf "year" (Just (2, Nothing))) Nothing)
     Nothing)
interval year(2) array 'test'
TypedLit
  (ArrayTypeName
     (IntervalTypeName (Itf "year" (Just (2, Nothing))) Nothing)
     Nothing)
  "test"
cast('test' as interval year(2) array[5])
Cast (StringLit "test")
  (ArrayTypeName
     (IntervalTypeName (Itf "year" (Just (2, Nothing))) Nothing)
     (Just 5))
interval year(2) array[5] 'test'
TypedLit
  (ArrayTypeName
     (IntervalTypeName (Itf "year" (Just (2, Nothing))) Nothing)
     (Just 5))
  "test"
cast('test' as interval second(2,5) array)
Cast (StringLit "test")
  (ArrayTypeName
     (IntervalTypeName (Itf "second" (Just (2, Just 5))) Nothing)
     Nothing)
interval second(2,5) array 'test'
TypedLit
  (ArrayTypeName
     (IntervalTypeName (Itf "second" (Just (2, Just 5))) Nothing)
     Nothing)
  "test"
cast('test' as interval second(2,5) array[5])
Cast (StringLit "test")
  (ArrayTypeName
     (IntervalTypeName (Itf "second" (Just (2, Just 5))) Nothing)
     (Just 5))
interval second(2,5) array[5] 'test'
TypedLit
  (ArrayTypeName
     (IntervalTypeName (Itf "second" (Just (2, Just 5))) Nothing)
     (Just 5))
  "test"
cast('test' as interval year to month array)
Cast (StringLit "test")
  (ArrayTypeName
     (IntervalTypeName (Itf "year" Nothing)
        (Just (Itf "month" Nothing)))
     Nothing)
interval year to month array 'test'
TypedLit
  (ArrayTypeName
     (IntervalTypeName (Itf "year" Nothing)
        (Just (Itf "month" Nothing)))
     Nothing)
  "test"
cast('test' as interval year to month array[5])
Cast (StringLit "test")
  (ArrayTypeName
     (IntervalTypeName (Itf "year" Nothing)
        (Just (Itf "month" Nothing)))
     (Just 5))
interval year to month array[5] 'test'
TypedLit
  (ArrayTypeName
     (IntervalTypeName (Itf "year" Nothing)
        (Just (Itf "month" Nothing)))
     (Just 5))
  "test"
cast('test' as interval year(4) to second(2,3) array)
Cast (StringLit "test")
  (ArrayTypeName
     (IntervalTypeName (Itf "year" (Just (4, Nothing)))
        (Just (Itf "second" (Just (2, Just 3)))))
     Nothing)
interval year(4) to second(2,3) array 'test'
TypedLit
  (ArrayTypeName
     (IntervalTypeName (Itf "year" (Just (4, Nothing)))
        (Just (Itf "second" (Just (2, Just 3)))))
     Nothing)
  "test"
cast('test' as interval year(4) to second(2,3) array[5])
Cast (StringLit "test")
  (ArrayTypeName
     (IntervalTypeName (Itf "year" (Just (4, Nothing)))
        (Just (Itf "second" (Just (2, Just 3)))))
     (Just 5))
interval year(4) to second(2,3) array[5] 'test'
TypedLit
  (ArrayTypeName
     (IntervalTypeName (Itf "year" (Just (4, Nothing)))
        (Just (Itf "second" (Just (2, Just 3)))))
     (Just 5))
  "test"
cast('test' as binary multiset)
Cast (StringLit "test")
  (MultisetTypeName (TypeName [Name "binary"]))
binary multiset 'test'
TypedLit (MultisetTypeName (TypeName [Name "binary"])) "test"
cast('test' as binary varying multiset)
Cast (StringLit "test")
  (MultisetTypeName (TypeName [Name "binary varying"]))
binary varying multiset 'test'
TypedLit (MultisetTypeName (TypeName [Name "binary varying"]))
  "test"
cast('test' as character multiset)
Cast (StringLit "test")
  (MultisetTypeName (TypeName [Name "character"]))
character multiset 'test'
TypedLit (MultisetTypeName (TypeName [Name "character"])) "test"
cast('test' as char multiset)
Cast (StringLit "test") (MultisetTypeName (TypeName [Name "char"]))
char multiset 'test'
TypedLit (MultisetTypeName (TypeName [Name "char"])) "test"
cast('test' as character varying multiset)
Cast (StringLit "test")
  (MultisetTypeName (TypeName [Name "character varying"]))
character varying multiset 'test'
TypedLit (MultisetTypeName (TypeName [Name "character varying"]))
  "test"
cast('test' as char varying multiset)
Cast (StringLit "test")
  (MultisetTypeName (TypeName [Name "char varying"]))
char varying multiset 'test'
TypedLit (MultisetTypeName (TypeName [Name "char varying"])) "test"
cast('test' as varbinary multiset)
Cast (StringLit "test")
  (MultisetTypeName (TypeName [Name "varbinary"]))
varbinary multiset 'test'
TypedLit (MultisetTypeName (TypeName [Name "varbinary"])) "test"
cast('test' as varchar multiset)
Cast (StringLit "test")
  (MultisetTypeName (TypeName [Name "varchar"]))
varchar multiset 'test'
TypedLit (MultisetTypeName (TypeName [Name "varchar"])) "test"
cast('test' as character large object multiset)
Cast (StringLit "test")
  (MultisetTypeName (TypeName [Name "character large object"]))
character large object multiset 'test'
TypedLit
  (MultisetTypeName (TypeName [Name "character large object"]))
  "test"
cast('test' as char large object multiset)
Cast (StringLit "test")
  (MultisetTypeName (TypeName [Name "char large object"]))
char large object multiset 'test'
TypedLit (MultisetTypeName (TypeName [Name "char large object"]))
  "test"
cast('test' as clob multiset)
Cast (StringLit "test") (MultisetTypeName (TypeName [Name "clob"]))
clob multiset 'test'
TypedLit (MultisetTypeName (TypeName [Name "clob"])) "test"
cast('test' as national character multiset)
Cast (StringLit "test")
  (MultisetTypeName (TypeName [Name "national character"]))
national character multiset 'test'
TypedLit (MultisetTypeName (TypeName [Name "national character"]))
  "test"
cast('test' as national char multiset)
Cast (StringLit "test")
  (MultisetTypeName (TypeName [Name "national char"]))
national char multiset 'test'
TypedLit (MultisetTypeName (TypeName [Name "national char"]))
  "test"
cast('test' as nchar multiset)
Cast (StringLit "test")
  (MultisetTypeName (TypeName [Name "nchar"]))
nchar multiset 'test'
TypedLit (MultisetTypeName (TypeName [Name "nchar"])) "test"
cast('test' as national character varying multiset)
Cast (StringLit "test")
  (MultisetTypeName (TypeName [Name "national character varying"]))
national character varying multiset 'test'
TypedLit
  (MultisetTypeName (TypeName [Name "national character varying"]))
  "test"
cast('test' as national char varying multiset)
Cast (StringLit "test")
  (MultisetTypeName (TypeName [Name "national char varying"]))
national char varying multiset 'test'
TypedLit
  (MultisetTypeName (TypeName [Name "national char varying"]))
  "test"
cast('test' as nchar varying multiset)
Cast (StringLit "test")
  (MultisetTypeName (TypeName [Name "nchar varying"]))
nchar varying multiset 'test'
TypedLit (MultisetTypeName (TypeName [Name "nchar varying"]))
  "test"
cast('test' as national character large object multiset)
Cast (StringLit "test")
  (MultisetTypeName
     (TypeName [Name "national character large object"]))
national character large object multiset 'test'
TypedLit
  (MultisetTypeName
     (TypeName [Name "national character large object"]))
  "test"
cast('test' as nchar large object multiset)
Cast (StringLit "test")
  (MultisetTypeName (TypeName [Name "nchar large object"]))
nchar large object multiset 'test'
TypedLit (MultisetTypeName (TypeName [Name "nchar large object"]))
  "test"
cast('test' as nclob multiset)
Cast (StringLit "test")
  (MultisetTypeName (TypeName [Name "nclob"]))
nclob multiset 'test'
TypedLit (MultisetTypeName (TypeName [Name "nclob"])) "test"
cast('test' as binary large object multiset)
Cast (StringLit "test")
  (MultisetTypeName (TypeName [Name "binary large object"]))
binary large object multiset 'test'
TypedLit (MultisetTypeName (TypeName [Name "binary large object"]))
  "test"
cast('test' as blob multiset)
Cast (StringLit "test") (MultisetTypeName (TypeName [Name "blob"]))
blob multiset 'test'
TypedLit (MultisetTypeName (TypeName [Name "blob"])) "test"
cast('test' as numeric multiset)
Cast (StringLit "test")
  (MultisetTypeName (TypeName [Name "numeric"]))
numeric multiset 'test'
TypedLit (MultisetTypeName (TypeName [Name "numeric"])) "test"
cast('test' as decimal multiset)
Cast (StringLit "test")
  (MultisetTypeName (TypeName [Name "decimal"]))
decimal multiset 'test'
TypedLit (MultisetTypeName (TypeName [Name "decimal"])) "test"
cast('test' as dec multiset)
Cast (StringLit "test") (MultisetTypeName (TypeName [Name "dec"]))
dec multiset 'test'
TypedLit (MultisetTypeName (TypeName [Name "dec"])) "test"
cast('test' as smallint multiset)
Cast (StringLit "test")
  (MultisetTypeName (TypeName [Name "smallint"]))
smallint multiset 'test'
TypedLit (MultisetTypeName (TypeName [Name "smallint"])) "test"
cast('test' as integer multiset)
Cast (StringLit "test")
  (MultisetTypeName (TypeName [Name "integer"]))
integer multiset 'test'
TypedLit (MultisetTypeName (TypeName [Name "integer"])) "test"
cast('test' as int multiset)
Cast (StringLit "test") (MultisetTypeName (TypeName [Name "int"]))
int multiset 'test'
TypedLit (MultisetTypeName (TypeName [Name "int"])) "test"
cast('test' as bigint multiset)
Cast (StringLit "test")
  (MultisetTypeName (TypeName [Name "bigint"]))
bigint multiset 'test'
TypedLit (MultisetTypeName (TypeName [Name "bigint"])) "test"
cast('test' as float multiset)
Cast (StringLit "test")
  (MultisetTypeName (TypeName [Name "float"]))
float multiset 'test'
TypedLit (MultisetTypeName (TypeName [Name "float"])) "test"
cast('test' as real multiset)
Cast (StringLit "test") (MultisetTypeName (TypeName [Name "real"]))
real multiset 'test'
TypedLit (MultisetTypeName (TypeName [Name "real"])) "test"
cast('test' as double precision multiset)
Cast (StringLit "test")
  (MultisetTypeName (TypeName [Name "double precision"]))
double precision multiset 'test'
TypedLit (MultisetTypeName (TypeName [Name "double precision"]))
  "test"
cast('test' as boolean multiset)
Cast (StringLit "test")
  (MultisetTypeName (TypeName [Name "boolean"]))
boolean multiset 'test'
TypedLit (MultisetTypeName (TypeName [Name "boolean"])) "test"
cast('test' as date multiset)
Cast (StringLit "test") (MultisetTypeName (TypeName [Name "date"]))
date multiset 'test'
TypedLit (MultisetTypeName (TypeName [Name "date"])) "test"
cast('test' as time multiset)
Cast (StringLit "test") (MultisetTypeName (TypeName [Name "time"]))
time multiset 'test'
TypedLit (MultisetTypeName (TypeName [Name "time"])) "test"
cast('test' as timestamp multiset)
Cast (StringLit "test")
  (MultisetTypeName (TypeName [Name "timestamp"]))
timestamp multiset 'test'
TypedLit (MultisetTypeName (TypeName [Name "timestamp"])) "test"
cast('test' as char(5) multiset)
Cast (StringLit "test")
  (MultisetTypeName (PrecTypeName [Name "char"] 5))
char(5) multiset 'test'
TypedLit (MultisetTypeName (PrecTypeName [Name "char"] 5)) "test"
cast('test' as char varying(5) multiset)
Cast (StringLit "test")
  (MultisetTypeName (PrecTypeName [Name "char varying"] 5))
char varying(5) multiset 'test'
TypedLit (MultisetTypeName (PrecTypeName [Name "char varying"] 5))
  "test"
cast('test' as decimal(15,2) multiset)
Cast (StringLit "test")
  (MultisetTypeName (PrecScaleTypeName [Name "decimal"] 15 2))
decimal(15,2) multiset 'test'
TypedLit
  (MultisetTypeName (PrecScaleTypeName [Name "decimal"] 15 2))
  "test"
cast('test' as char(3 octets) multiset)
Cast (StringLit "test")
  (MultisetTypeName
     (PrecLengthTypeName [Name "char"] 3 Nothing (Just PrecOctets)))
char(3 octets) multiset 'test'
TypedLit
  (MultisetTypeName
     (PrecLengthTypeName [Name "char"] 3 Nothing (Just PrecOctets)))
  "test"
cast('test' as varchar(50 characters) multiset)
Cast (StringLit "test")
  (MultisetTypeName
     (PrecLengthTypeName [Name "varchar"] 50 Nothing
        (Just PrecCharacters)))
varchar(50 characters) multiset 'test'
TypedLit
  (MultisetTypeName
     (PrecLengthTypeName [Name "varchar"] 50 Nothing
        (Just PrecCharacters)))
  "test"
cast('test' as blob(3M) multiset)
Cast (StringLit "test")
  (MultisetTypeName
     (PrecLengthTypeName [Name "blob"] 3 (Just PrecM) Nothing))
blob(3M) multiset 'test'
TypedLit
  (MultisetTypeName
     (PrecLengthTypeName [Name "blob"] 3 (Just PrecM) Nothing))
  "test"
cast('test' as blob(3T) multiset)
Cast (StringLit "test")
  (MultisetTypeName
     (PrecLengthTypeName [Name "blob"] 3 (Just PrecT) Nothing))
blob(3T) multiset 'test'
TypedLit
  (MultisetTypeName
     (PrecLengthTypeName [Name "blob"] 3 (Just PrecT) Nothing))
  "test"
cast('test' as blob(3P) multiset)
Cast (StringLit "test")
  (MultisetTypeName
     (PrecLengthTypeName [Name "blob"] 3 (Just PrecP) Nothing))
blob(3P) multiset 'test'
TypedLit
  (MultisetTypeName
     (PrecLengthTypeName [Name "blob"] 3 (Just PrecP) Nothing))
  "test"
cast('test' as blob(4M characters)  multiset)
Cast (StringLit "test")
  (MultisetTypeName
     (PrecLengthTypeName [Name "blob"] 4 (Just PrecM)
        (Just PrecCharacters)))
blob(4M characters)  multiset 'test'
TypedLit
  (MultisetTypeName
     (PrecLengthTypeName [Name "blob"] 4 (Just PrecM)
        (Just PrecCharacters)))
  "test"
cast('test' as blob(6G octets)  multiset)
Cast (StringLit "test")
  (MultisetTypeName
     (PrecLengthTypeName [Name "blob"] 6 (Just PrecG)
        (Just PrecOctets)))
blob(6G octets)  multiset 'test'
TypedLit
  (MultisetTypeName
     (PrecLengthTypeName [Name "blob"] 6 (Just PrecG)
        (Just PrecOctets)))
  "test"
cast('test' as national character large object(7K)  multiset)
Cast (StringLit "test")
  (MultisetTypeName
     (PrecLengthTypeName [Name "national character large object"] 7
        (Just PrecK)
        Nothing))
national character large object(7K)  multiset 'test'
TypedLit
  (MultisetTypeName
     (PrecLengthTypeName [Name "national character large object"] 7
        (Just PrecK)
        Nothing))
  "test"
cast('test'