HsSqlPpp-0.4.0



The parser examples have the sql source on the left, and the ast that the parser produces the right, the annotations have been replaced with a placeholder 'Ann' to make the output a bit more readable.

The source this file is generated from is here: ParserTests.lhs

parserTests

parse expressions

numbers

42
NumberLit Ann "42"
3.5
NumberLit Ann "3.5"
4.
NumberLit Ann "4."
.001
NumberLit Ann ".001"
5e2
NumberLit Ann "5e2"
1.925e-3
NumberLit Ann "1.925e-3"

basic expressions

1
NumberLit Ann "1"
-1
FunCall Ann (Name Ann [Nmc "u-"]) [NumberLit Ann "1"]
1.1
NumberLit Ann "1.1"
-1.1
FunCall Ann (Name Ann [Nmc "u-"]) [NumberLit Ann "1.1"]
1 + 1
FunCall Ann (Name Ann [Nmc "+"])
  [NumberLit Ann "1", NumberLit Ann "1"]
1+1+1
FunCall Ann (Name Ann [Nmc "+"])
  [FunCall Ann (Name Ann [Nmc "+"])
     [NumberLit Ann "1", NumberLit Ann "1"],
   NumberLit Ann "1"]

parens

(1)
NumberLit Ann "1"
row ()
FunCall Ann (Name Ann [Nmc "!rowctor"]) []
row (1)
FunCall Ann (Name Ann [Nmc "!rowctor"]) [NumberLit Ann "1"]
row (1,2)
FunCall Ann (Name Ann [Nmc "!rowctor"])
  [NumberLit Ann "1", NumberLit Ann "2"]
(1,2)
FunCall Ann (Name Ann [Nmc "!rowctor"])
  [NumberLit Ann "1", NumberLit Ann "2"]

more basic expressions

'test'
StringLit Ann "test"
''
StringLit Ann ""
hello
Identifier Ann (Nmc "hello")
helloTest
Identifier Ann (Nmc "helloTest")
hello_test
Identifier Ann (Nmc "hello_test")
"this is an identifier"
Identifier Ann (QNmc "this is an identifier")
hello1234
Identifier Ann (Nmc "hello1234")
true
BooleanLit Ann True
false
BooleanLit Ann False
null
NullLit Ann

array ctor and selector

array[1,2]
FunCall Ann (Name Ann [Nmc "!arrayctor"])
  [NumberLit Ann "1", NumberLit Ann "2"]
a[1]
FunCall Ann (Name Ann [Nmc "!arraysub"])
  [Identifier Ann (Nmc "a"), NumberLit Ann "1"]

simple operators

1 + tst1
FunCall Ann (Name Ann [Nmc "+"])
  [NumberLit Ann "1", Identifier Ann (Nmc "tst1")]
tst1 + 1
FunCall Ann (Name Ann [Nmc "+"])
  [Identifier Ann (Nmc "tst1"), NumberLit Ann "1"]
tst + tst1
FunCall Ann (Name Ann [Nmc "+"])
  [Identifier Ann (Nmc "tst"), Identifier Ann (Nmc "tst1")]
'a' || 'b'
FunCall Ann (Name Ann [Nmc "||"])
  [StringLit Ann "a", StringLit Ann "b"]
'stuff'::text
Cast Ann (StringLit Ann "stuff") (SimpleTypeName Ann "text")
245::float(24)
Cast Ann (NumberLit Ann "245") (PrecTypeName Ann "float" 24)
245.1::numeric(5,3)
Cast Ann (NumberLit Ann "245.1") (Prec2TypeName Ann "numeric" 5 3)
245::double precision
Cast Ann (NumberLit Ann "245")
  (SimpleTypeName Ann "double precision")
date '1998-12-01'
TypedStringLit Ann (SimpleTypeName Ann "date") "1998-12-01"
interval '63' day
Interval Ann "63" IntervalDay Nothing
interval '63' day (3)
Interval Ann "63" IntervalDay (Just 3)
extract(year from a)
Extract Ann ExtractYear (Identifier Ann (Nmc "a"))
a between 1 and 3
FunCall Ann (Name Ann [Nmc "!between"])
  [Identifier Ann (Nmc "a"), NumberLit Ann "1", NumberLit Ann "3"]
a between 7 - 1 and 7 + 1
FunCall Ann (Name Ann [Nmc "!between"])
  [Identifier Ann (Nmc "a"),
   FunCall Ann (Name Ann [Nmc "-"])
     [NumberLit Ann "7", NumberLit Ann "1"],
   FunCall Ann (Name Ann [Nmc "+"])
     [NumberLit Ann "7", NumberLit Ann "1"]]
cast(a as text)
Cast Ann (Identifier Ann (Nmc "a")) (SimpleTypeName Ann "text")
@ a
FunCall Ann (Name Ann [Nmc "@"]) [Identifier Ann (Nmc "a")]
substring(a from 0 for 3)
FunCall Ann (Name Ann [Nmc "!substring"])
  [Identifier Ann (Nmc "a"), NumberLit Ann "0", NumberLit Ann "3"]
substring(a from 0 for (5 - 3))
FunCall Ann (Name Ann [Nmc "!substring"])
  [Identifier Ann (Nmc "a"), NumberLit Ann "0",
   FunCall Ann (Name Ann [Nmc "-"])
     [NumberLit Ann "5", NumberLit Ann "3"]]
substring(a,b,c)
FunCall Ann (Name Ann [Nmc "substring"])
  [Identifier Ann (Nmc "a"), Identifier Ann (Nmc "b"),
   Identifier Ann (Nmc "c")]
a like b
FunCall Ann (Name Ann [Nmc "!like"])
  [Identifier Ann (Nmc "a"), Identifier Ann (Nmc "b")]
a not like b
FunCall Ann (Name Ann [Nmc "!notlike"])
  [Identifier Ann (Nmc "a"), Identifier Ann (Nmc "b")]
a and b and c and d
FunCall Ann (Name Ann [Nmc "!and"])
  [FunCall Ann (Name Ann [Nmc "!and"])
     [FunCall Ann (Name Ann [Nmc "!and"])
        [Identifier Ann (Nmc "a"), Identifier Ann (Nmc "b")],
      Identifier Ann (Nmc "c")],
   Identifier Ann (Nmc "d")]

function calls

fn()
FunCall Ann (Name Ann [Nmc "fn"]) []
fn(1)
FunCall Ann (Name Ann [Nmc "fn"]) [NumberLit Ann "1"]
fn('test')
FunCall Ann (Name Ann [Nmc "fn"]) [StringLit Ann "test"]
fn(1,'test')
FunCall Ann (Name Ann [Nmc "fn"])
  [NumberLit Ann "1", StringLit Ann "test"]
fn('test')
FunCall Ann (Name Ann [Nmc "fn"]) [StringLit Ann "test"]

simple whitespace sanity checks

fn (1)
FunCall Ann (Name Ann [Nmc "fn"]) [NumberLit Ann "1"]
fn( 1)
FunCall Ann (Name Ann [Nmc "fn"]) [NumberLit Ann "1"]
fn(1 )
FunCall Ann (Name Ann [Nmc "fn"]) [NumberLit Ann "1"]
fn(1)
FunCall Ann (Name Ann [Nmc "fn"]) [NumberLit Ann "1"]

null stuff

not null
FunCall Ann (Name Ann [Nmc "!not"]) [NullLit Ann]
a is null
FunCall Ann (Name Ann [Nmc "!isnull"]) [Identifier Ann (Nmc "a")]
a is not null
FunCall Ann (Name Ann [Nmc "!isnotnull"])
  [Identifier Ann (Nmc "a")]
not not true
FunCall Ann (Name Ann [Nmc "!not"])
  [FunCall Ann (Name Ann [Nmc "!not"]) [BooleanLit Ann True]]

case expressions

case when a,b then 3
                when c then 4
                else 5
           end
Case Ann
  [([Identifier Ann (Nmc "a"), Identifier Ann (Nmc "b")],
    NumberLit Ann "3"),
   ([Identifier Ann (Nmc "c")], NumberLit Ann "4")]
  (Just (NumberLit Ann "5"))
case 1 when 2 then 3 else 4 end
CaseSimple Ann (NumberLit Ann "1")
  [([NumberLit Ann "2"], NumberLit Ann "3")]
  (Just (NumberLit Ann "4"))

positional args

$1
PositionalArg Ann 1
?
Placeholder Ann
a = ?
FunCall Ann (Name Ann [Nmc "="])
  [Identifier Ann (Nmc "a"), Placeholder Ann]

exists

exists (select 1 from a)
Exists Ann
  (Select Ann Dupes (SelectList Ann [SelExp Ann (NumberLit Ann "1")])
     [Tref Ann (Name Ann [Nmc "a"]) (NoAlias Ann)]
     Nothing
     []
     Nothing
     []
     Nothing
     Nothing)

in variants

t in (1,2)
InPredicate Ann (Identifier Ann (Nmc "t")) True
  (InList Ann [NumberLit Ann "1", NumberLit Ann "2"])
t not in (1,2)
InPredicate Ann (Identifier Ann (Nmc "t")) False
  (InList Ann [NumberLit Ann "1", NumberLit Ann "2"])
(t,u) in (1,2)
InPredicate Ann
  (FunCall Ann (Name Ann [Nmc "!rowctor"])
     [Identifier Ann (Nmc "t"), Identifier Ann (Nmc "u")])
  True
  (InList Ann [NumberLit Ann "1", NumberLit Ann "2"])
3 = any (array[1,2])
LiftOperator Ann "=" LiftAny
  [NumberLit Ann "3",
   FunCall Ann (Name Ann [Nmc "!arrayctor"])
     [NumberLit Ann "1", NumberLit Ann "2"]]
3 = all (array[1,2,4])
LiftOperator Ann "=" LiftAll
  [NumberLit Ann "3",
   FunCall Ann (Name Ann [Nmc "!arrayctor"])
     [NumberLit Ann "1", NumberLit Ann "2", NumberLit Ann "4"]]

comparison operators

a < b
FunCall Ann (Name Ann [Nmc "<"])
  [Identifier Ann (Nmc "a"), Identifier Ann (Nmc "b")]
a <> b
FunCall Ann (Name Ann [Nmc "<>"])
  [Identifier Ann (Nmc "a"), Identifier Ann (Nmc "b")]
a != b
FunCall Ann (Name Ann [Nmc "<>"])
  [Identifier Ann (Nmc "a"), Identifier Ann (Nmc "b")]

string parsing

''
StringLit Ann ""
''''
StringLit Ann "'"
'test'''
StringLit Ann "test'"
'''test'
StringLit Ann "'test"
'te''st'
StringLit Ann "te'st"
$$test$$
StringLit Ann "test"
$$te'st$$
StringLit Ann "te'st"
$st$test$st$
StringLit Ann "test"
$outer$te$$yup$$st$outer$
StringLit Ann "te$$yup$$st"
'spl$$it'
StringLit Ann "spl$$it"

bracketed things

(p).x
QIdentifier Ann [Nmc "p", Nmc "x"]
(select f(((a).x, y)::z))
ScalarSubQuery Ann
  (Select Ann Dupes
     (SelectList Ann
        [SelExp Ann
           (FunCall Ann (Name Ann [Nmc "f"])
              [Cast Ann
                 (FunCall Ann (Name Ann [Nmc "!rowctor"])
                    [QIdentifier Ann [Nmc "a", Nmc "x"], Identifier Ann (Nmc "y")])
                 (SimpleTypeName Ann "z")])])
     []
     Nothing
     []
     Nothing
     []
     Nothing
     Nothing)

parse selects

simple select statements

select no table

select 1;
[QueryStatement Ann
   (Select Ann Dupes (SelectList Ann [SelExp Ann (NumberLit Ann "1")])
      []
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]

select from table

select * from tbl;
[QueryStatement Ann
   (Select Ann Dupes (SelectList Ann [SelExp Ann (Star Ann)])
      [Tref Ann (Name Ann [Nmc "tbl"]) (NoAlias Ann)]
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]
select a,b from tbl;
[QueryStatement Ann
   (Select Ann Dupes
      (SelectList Ann
         [SelExp Ann (Identifier Ann (Nmc "a")),
          SelExp Ann (Identifier Ann (Nmc "b"))])
      [Tref Ann (Name Ann [Nmc "tbl"]) (NoAlias Ann)]
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]
select a,b from inf.tbl;
[QueryStatement Ann
   (Select Ann Dupes
      (SelectList Ann
         [SelExp Ann (Identifier Ann (Nmc "a")),
          SelExp Ann (Identifier Ann (Nmc "b"))])
      [Tref Ann (Name Ann [Nmc "inf", Nmc "tbl"]) (NoAlias Ann)]
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]
select distinct * from tbl;
[QueryStatement Ann
   (Select Ann Distinct (SelectList Ann [SelExp Ann (Star Ann)])
      [Tref Ann (Name Ann [Nmc "tbl"]) (NoAlias Ann)]
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]
select a from tbl where b=2;
[QueryStatement Ann
   (Select Ann Dupes
      (SelectList Ann [SelExp Ann (Identifier Ann (Nmc "a"))])
      [Tref Ann (Name Ann [Nmc "tbl"]) (NoAlias Ann)]
      (Just
         (FunCall Ann (Name Ann [Nmc "="])
            [Identifier Ann (Nmc "b"), NumberLit Ann "2"]))
      []
      Nothing
      []
      Nothing
      Nothing)]
select a from tbl where b=2 and c=3;
[QueryStatement Ann
   (Select Ann Dupes
      (SelectList Ann [SelExp Ann (Identifier Ann (Nmc "a"))])
      [Tref Ann (Name Ann [Nmc "tbl"]) (NoAlias Ann)]
      (Just
         (FunCall Ann (Name Ann [Nmc "!and"])
            [FunCall Ann (Name Ann [Nmc "="])
               [Identifier Ann (Nmc "b"), NumberLit Ann "2"],
             FunCall Ann (Name Ann [Nmc "="])
               [Identifier Ann (Nmc "c"), NumberLit Ann "3"]]))
      []
      Nothing
      []
      Nothing
      Nothing)]
SELECT T.A::INT FROM TABLE AS T;
[QueryStatement Ann
   (Select Ann Dupes
      (SelectList Ann
         [SelExp Ann
            (Cast Ann (QIdentifier Ann [Nmc "T", Nmc "A"])
               (SimpleTypeName Ann "int"))])
      [Tref Ann (Name Ann [Nmc "TABLE"]) (TableAlias Ann (Nmc "T"))]
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]

more select statements

select a from tbl
except
select a from tbl1;
[QueryStatement Ann
   (CombineQueryExpr Ann Except
      (Select Ann Dupes
         (SelectList Ann [SelExp Ann (Identifier Ann (Nmc "a"))])
         [Tref Ann (Name Ann [Nmc "tbl"]) (NoAlias Ann)]
         Nothing
         []
         Nothing
         []
         Nothing
         Nothing)
      (Select Ann Dupes
         (SelectList Ann [SelExp Ann (Identifier Ann (Nmc "a"))])
         [Tref Ann (Name Ann [Nmc "tbl1"]) (NoAlias Ann)]
         Nothing
         []
         Nothing
         []
         Nothing
         Nothing))]
select a from tbl where true
except
select a from tbl1 where true;
[QueryStatement Ann
   (CombineQueryExpr Ann Except
      (Select Ann Dupes
         (SelectList Ann [SelExp Ann (Identifier Ann (Nmc "a"))])
         [Tref Ann (Name Ann [Nmc "tbl"]) (NoAlias Ann)]
         (Just (BooleanLit Ann True))
         []
         Nothing
         []
         Nothing
         Nothing)
      (Select Ann Dupes
         (SelectList Ann [SelExp Ann (Identifier Ann (Nmc "a"))])
         [Tref Ann (Name Ann [Nmc "tbl1"]) (NoAlias Ann)]
         (Just (BooleanLit Ann True))
         []
         Nothing
         []
         Nothing
         Nothing))]
select a from tbl
union
select a from tbl1;
[QueryStatement Ann
   (CombineQueryExpr Ann Union
      (Select Ann Dupes
         (SelectList Ann [SelExp Ann (Identifier Ann (Nmc "a"))])
         [Tref Ann (Name Ann [Nmc "tbl"]) (NoAlias Ann)]
         Nothing
         []
         Nothing
         []
         Nothing
         Nothing)
      (Select Ann Dupes
         (SelectList Ann [SelExp Ann (Identifier Ann (Nmc "a"))])
         [Tref Ann (Name Ann [Nmc "tbl1"]) (NoAlias Ann)]
         Nothing
         []
         Nothing
         []
         Nothing
         Nothing))]
select a from tbl
union all
select a from tbl1;
[QueryStatement Ann
   (CombineQueryExpr Ann UnionAll
      (Select Ann Dupes
         (SelectList Ann [SelExp Ann (Identifier Ann (Nmc "a"))])
         [Tref Ann (Name Ann [Nmc "tbl"]) (NoAlias Ann)]
         Nothing
         []
         Nothing
         []
         Nothing
         Nothing)
      (Select Ann Dupes
         (SelectList Ann [SelExp Ann (Identifier Ann (Nmc "a"))])
         [Tref Ann (Name Ann [Nmc "tbl1"]) (NoAlias Ann)]
         Nothing
         []
         Nothing
         []
         Nothing
         Nothing))]
(select 1 union select 2) union select 3;
[QueryStatement Ann
   (CombineQueryExpr Ann Union
      (CombineQueryExpr Ann Union
         (Select Ann Dupes (SelectList Ann [SelExp Ann (NumberLit Ann "1")])
            []
            Nothing
            []
            Nothing
            []
            Nothing
            Nothing)
         (Select Ann Dupes (SelectList Ann [SelExp Ann (NumberLit Ann "2")])
            []
            Nothing
            []
            Nothing
            []
            Nothing
            Nothing))
      (Select Ann Dupes (SelectList Ann [SelExp Ann (NumberLit Ann "3")])
         []
         Nothing
         []
         Nothing
         []
         Nothing
         Nothing))]
select 1 union (select 2 union select 3);
[QueryStatement Ann
   (CombineQueryExpr Ann Union
      (Select Ann Dupes (SelectList Ann [SelExp Ann (NumberLit Ann "1")])
         []
         Nothing
         []
         Nothing
         []
         Nothing
         Nothing)
      (CombineQueryExpr Ann Union
         (Select Ann Dupes (SelectList Ann [SelExp Ann (NumberLit Ann "2")])
            []
            Nothing
            []
            Nothing
            []
            Nothing
            Nothing)
         (Select Ann Dupes (SelectList Ann [SelExp Ann (NumberLit Ann "3")])
            []
            Nothing
            []
            Nothing
            []
            Nothing
            Nothing)))]
with a as (select 1 as a1),
                b as (select * from a)
                select * from b;
[QueryStatement Ann
   (WithQueryExpr Ann
      [WithQuery Ann (Nmc "a") Nothing
         (Select Ann Dupes
            (SelectList Ann [SelectItem Ann (NumberLit Ann "1") (Nmc "a1")])
            []
            Nothing
            []
            Nothing
            []
            Nothing
            Nothing),
       WithQuery Ann (Nmc "b") Nothing
         (Select Ann Dupes (SelectList Ann [SelExp Ann (Star Ann)])
            [Tref Ann (Name Ann [Nmc "a"]) (NoAlias Ann)]
            Nothing
            []
            Nothing
            []
            Nothing
            Nothing)]
      (Select Ann Dupes (SelectList Ann [SelExp Ann (Star Ann)])
         [Tref Ann (Name Ann [Nmc "b"]) (NoAlias Ann)]
         Nothing
         []
         Nothing
         []
         Nothing
         Nothing))]
with a as (select 1 as a1),
                b as (select * from a)
                select * from a
                union select * from b;
[QueryStatement Ann
   (WithQueryExpr Ann
      [WithQuery Ann (Nmc "a") Nothing
         (Select Ann Dupes
            (SelectList Ann [SelectItem Ann (NumberLit Ann "1") (Nmc "a1")])
            []
            Nothing
            []
            Nothing
            []
            Nothing
            Nothing),
       WithQuery Ann (Nmc "b") Nothing
         (Select Ann Dupes (SelectList Ann [SelExp Ann (Star Ann)])
            [Tref Ann (Name Ann [Nmc "a"]) (NoAlias Ann)]
            Nothing
            []
            Nothing
            []
            Nothing
            Nothing)]
      (CombineQueryExpr Ann Union
         (Select Ann Dupes (SelectList Ann [SelExp Ann (Star Ann)])
            [Tref Ann (Name Ann [Nmc "a"]) (NoAlias Ann)]
            Nothing
            []
            Nothing
            []
            Nothing
            Nothing)
         (Select Ann Dupes (SelectList Ann [SelExp Ann (Star Ann)])
            [Tref Ann (Name Ann [Nmc "b"]) (NoAlias Ann)]
            Nothing
            []
            Nothing
            []
            Nothing
            Nothing)))]
select a as b from tbl;
[QueryStatement Ann
   (Select Ann Dupes
      (SelectList Ann
         [SelectItem Ann (Identifier Ann (Nmc "a")) (Nmc "b")])
      [Tref Ann (Name Ann [Nmc "tbl"]) (NoAlias Ann)]
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]
select a + b as b from tbl;
[QueryStatement Ann
   (Select Ann Dupes
      (SelectList Ann
         [SelectItem Ann
            (FunCall Ann (Name Ann [Nmc "+"])
               [Identifier Ann (Nmc "a"), Identifier Ann (Nmc "b")])
            (Nmc "b")])
      [Tref Ann (Name Ann [Nmc "tbl"]) (NoAlias Ann)]
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]
select a.* from tbl a;
[QueryStatement Ann
   (Select Ann Dupes
      (SelectList Ann [SelExp Ann (QStar Ann (Nmc "a"))])
      [Tref Ann (Name Ann [Nmc "tbl"]) (TableAlias Ann (Nmc "a"))]
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]
select a.* from tbl a(b,c);
[QueryStatement Ann
   (Select Ann Dupes
      (SelectList Ann [SelExp Ann (QStar Ann (Nmc "a"))])
      [Tref Ann (Name Ann [Nmc "tbl"])
         (FullAlias Ann (Nmc "a") [Nmc "b", Nmc "c"])]
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]
select * from t1 a, t2 b;
[QueryStatement Ann
   (Select Ann Dupes (SelectList Ann [SelExp Ann (Star Ann)])
      [Tref Ann (Name Ann [Nmc "t1"]) (TableAlias Ann (Nmc "a")),
       Tref Ann (Name Ann [Nmc "t2"]) (TableAlias Ann (Nmc "b"))]
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]
select a from b inner join c on b.a=c.a;
[QueryStatement Ann
   (Select Ann Dupes
      (SelectList Ann [SelExp Ann (Identifier Ann (Nmc "a"))])
      [JoinTref Ann (Tref Ann (Name Ann [Nmc "b"]) (NoAlias Ann))
         Unnatural
         Inner
         (Tref Ann (Name Ann [Nmc "c"]) (NoAlias Ann))
         (Just
            (JoinOn Ann
               (FunCall Ann (Name Ann [Nmc "="])
                  [QIdentifier Ann [Nmc "b", Nmc "a"],
                   QIdentifier Ann [Nmc "c", Nmc "a"]])))
         (NoAlias Ann)]
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]
select a from b inner join c as d on b.a=d.a;
[QueryStatement Ann
   (Select Ann Dupes
      (SelectList Ann [SelExp Ann (Identifier Ann (Nmc "a"))])
      [JoinTref Ann (Tref Ann (Name Ann [Nmc "b"]) (NoAlias Ann))
         Unnatural
         Inner
         (Tref Ann (Name Ann [Nmc "c"]) (TableAlias Ann (Nmc "d")))
         (Just
            (JoinOn Ann
               (FunCall Ann (Name Ann [Nmc "="])
                  [QIdentifier Ann [Nmc "b", Nmc "a"],
                   QIdentifier Ann [Nmc "d", Nmc "a"]])))
         (NoAlias Ann)]
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]
select a from b inner join c using(d,e);
[QueryStatement Ann
   (Select Ann Dupes
      (SelectList Ann [SelExp Ann (Identifier Ann (Nmc "a"))])
      [JoinTref Ann (Tref Ann (Name Ann [Nmc "b"]) (NoAlias Ann))
         Unnatural
         Inner
         (Tref Ann (Name Ann [Nmc "c"]) (NoAlias Ann))
         (Just (JoinUsing Ann [Nmc "d", Nmc "e"]))
         (NoAlias Ann)]
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]
select a from b natural inner join c;
[QueryStatement Ann
   (Select Ann Dupes
      (SelectList Ann [SelExp Ann (Identifier Ann (Nmc "a"))])
      [JoinTref Ann (Tref Ann (Name Ann [Nmc "b"]) (NoAlias Ann)) Natural
         Inner
         (Tref Ann (Name Ann [Nmc "c"]) (NoAlias Ann))
         Nothing
         (NoAlias Ann)]
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]
select a from b left outer join c;
[QueryStatement Ann
   (Select Ann Dupes
      (SelectList Ann [SelExp Ann (Identifier Ann (Nmc "a"))])
      [JoinTref Ann (Tref Ann (Name Ann [Nmc "b"]) (NoAlias Ann))
         Unnatural
         LeftOuter
         (Tref Ann (Name Ann [Nmc "c"]) (NoAlias Ann))
         Nothing
         (NoAlias Ann)]
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]
select a from b full outer join c;
[QueryStatement Ann
   (Select Ann Dupes
      (SelectList Ann [SelExp Ann (Identifier Ann (Nmc "a"))])
      [JoinTref Ann (Tref Ann (Name Ann [Nmc "b"]) (NoAlias Ann))
         Unnatural
         FullOuter
         (Tref Ann (Name Ann [Nmc "c"]) (NoAlias Ann))
         Nothing
         (NoAlias Ann)]
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]
select a from b right outer join c;
[QueryStatement Ann
   (Select Ann Dupes
      (SelectList Ann [SelExp Ann (Identifier Ann (Nmc "a"))])
      [JoinTref Ann (Tref Ann (Name Ann [Nmc "b"]) (NoAlias Ann))
         Unnatural
         RightOuter
         (Tref Ann (Name Ann [Nmc "c"]) (NoAlias Ann))
         Nothing
         (NoAlias Ann)]
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]
select a from b cross join c;
[QueryStatement Ann
   (Select Ann Dupes
      (SelectList Ann [SelExp Ann (Identifier Ann (Nmc "a"))])
      [JoinTref Ann (Tref Ann (Name Ann [Nmc "b"]) (NoAlias Ann))
         Unnatural
         Cross
         (Tref Ann (Name Ann [Nmc "c"]) (NoAlias Ann))
         Nothing
         (NoAlias Ann)]
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]
select a from (b natural join c);
[QueryStatement Ann
   (Select Ann Dupes
      (SelectList Ann [SelExp Ann (Identifier Ann (Nmc "a"))])
      [JoinTref Ann (Tref Ann (Name Ann [Nmc "b"]) (NoAlias Ann)) Natural
         Inner
         (Tref Ann (Name Ann [Nmc "c"]) (NoAlias Ann))
         Nothing
         (NoAlias Ann)]
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]
select x from a cross join b cross join c;
[QueryStatement Ann
   (Select Ann Dupes
      (SelectList Ann [SelExp Ann (Identifier Ann (Nmc "x"))])
      [JoinTref Ann
         (JoinTref Ann (Tref Ann (Name Ann [Nmc "a"]) (NoAlias Ann))
            Unnatural
            Cross
            (Tref Ann (Name Ann [Nmc "b"]) (NoAlias Ann))
            Nothing
            (NoAlias Ann))
         Unnatural
         Cross
         (Tref Ann (Name Ann [Nmc "c"]) (NoAlias Ann))
         Nothing
         (NoAlias Ann)]
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]
select x from ((a cross join b) cross join c);
[QueryStatement Ann
   (Select Ann Dupes
      (SelectList Ann [SelExp Ann (Identifier Ann (Nmc "x"))])
      [JoinTref Ann
         (JoinTref Ann (Tref Ann (Name Ann [Nmc "a"]) (NoAlias Ann))
            Unnatural
            Cross
            (Tref Ann (Name Ann [Nmc "b"]) (NoAlias Ann))
            Nothing
            (NoAlias Ann))
         Unnatural
         Cross
         (Tref Ann (Name Ann [Nmc "c"]) (NoAlias Ann))
         Nothing
         (NoAlias Ann)]
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]
select x from (a cross join (b cross join c));
[QueryStatement Ann
   (Select Ann Dupes
      (SelectList Ann [SelExp Ann (Identifier Ann (Nmc "x"))])
      [JoinTref Ann (Tref Ann (Name Ann [Nmc "a"]) (NoAlias Ann))
         Unnatural
         Cross
         (JoinTref Ann (Tref Ann (Name Ann [Nmc "b"]) (NoAlias Ann))
            Unnatural
            Cross
            (Tref Ann (Name Ann [Nmc "c"]) (NoAlias Ann))
            Nothing
            (NoAlias Ann))
         Nothing
         (NoAlias Ann)]
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]
select x from ((a cross join b) cross join c);
[QueryStatement Ann
   (Select Ann Dupes
      (SelectList Ann [SelExp Ann (Identifier Ann (Nmc "x"))])
      [JoinTref Ann
         (JoinTref Ann (Tref Ann (Name Ann [Nmc "a"]) (NoAlias Ann))
            Unnatural
            Cross
            (Tref Ann (Name Ann [Nmc "b"]) (NoAlias Ann))
            Nothing
            (NoAlias Ann))
         Unnatural
         Cross
         (Tref Ann (Name Ann [Nmc "c"]) (NoAlias Ann))
         Nothing
         (NoAlias Ann)]
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]
select x from (a cross join b) cross join c;
[QueryStatement Ann
   (Select Ann Dupes
      (SelectList Ann [SelExp Ann (Identifier Ann (Nmc "x"))])
      [JoinTref Ann
         (JoinTref Ann (Tref Ann (Name Ann [Nmc "a"]) (NoAlias Ann))
            Unnatural
            Cross
            (Tref Ann (Name Ann [Nmc "b"]) (NoAlias Ann))
            Nothing
            (NoAlias Ann))
         Unnatural
         Cross
         (Tref Ann (Name Ann [Nmc "c"]) (NoAlias Ann))
         Nothing
         (NoAlias Ann)]
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]
select x from ((a cross join b) cross join c) cross join d;
[QueryStatement Ann
   (Select Ann Dupes
      (SelectList Ann [SelExp Ann (Identifier Ann (Nmc "x"))])
      [JoinTref Ann
         (JoinTref Ann
            (JoinTref Ann (Tref Ann (Name Ann [Nmc "a"]) (NoAlias Ann))
               Unnatural
               Cross
               (Tref Ann (Name Ann [Nmc "b"]) (NoAlias Ann))
               Nothing
               (NoAlias Ann))
            Unnatural
            Cross
            (Tref Ann (Name Ann [Nmc "c"]) (NoAlias Ann))
            Nothing
            (NoAlias Ann))
         Unnatural
         Cross
         (Tref Ann (Name Ann [Nmc "d"]) (NoAlias Ann))
         Nothing
         (NoAlias Ann)]
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]
select a from b
    inner join c
      on true
    inner join d
      on 1=1;
[QueryStatement Ann
   (Select Ann Dupes
      (SelectList Ann [SelExp Ann (Identifier Ann (Nmc "a"))])
      [JoinTref Ann
         (JoinTref Ann (Tref Ann (Name Ann [Nmc "b"]) (NoAlias Ann))
            Unnatural
            Inner
            (Tref Ann (Name Ann [Nmc "c"]) (NoAlias Ann))
            (Just (JoinOn Ann (BooleanLit Ann True)))
            (NoAlias Ann))
         Unnatural
         Inner
         (Tref Ann (Name Ann [Nmc "d"]) (NoAlias Ann))
         (Just
            (JoinOn Ann
               (FunCall Ann (Name Ann [Nmc "="])
                  [NumberLit Ann "1", NumberLit Ann "1"])))
         (NoAlias Ann)]
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]
select row_number() over(order by a) as place from tbl;
[QueryStatement Ann
   (Select Ann Dupes
      (SelectList Ann
         [SelectItem Ann
            (WindowFn Ann (FunCall Ann (Name Ann [Nmc "row_number"]) []) []
               [(Identifier Ann (Nmc "a"), Asc)]
               FrameUnboundedPreceding)
            (Nmc "place")])
      [Tref Ann (Name Ann [Nmc "tbl"]) (NoAlias Ann)]
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]
select row_number() over(order by a asc) as place from tbl;
[QueryStatement Ann
   (Select Ann Dupes
      (SelectList Ann
         [SelectItem Ann
            (WindowFn Ann (FunCall Ann (Name Ann [Nmc "row_number"]) []) []
               [(Identifier Ann (Nmc "a"), Asc)]
               FrameUnboundedPreceding)
            (Nmc "place")])
      [Tref Ann (Name Ann [Nmc "tbl"]) (NoAlias Ann)]
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]
select row_number() over(order by a desc) as place from tbl;
[QueryStatement Ann
   (Select Ann Dupes
      (SelectList Ann
         [SelectItem Ann
            (WindowFn Ann (FunCall Ann (Name Ann [Nmc "row_number"]) []) []
               [(Identifier Ann (Nmc "a"), Desc)]
               FrameUnboundedPreceding)
            (Nmc "place")])
      [Tref Ann (Name Ann [Nmc "tbl"]) (NoAlias Ann)]
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]
select row_number()
over(partition by (a,b) order by c) as place
from tbl;
[QueryStatement Ann
   (Select Ann Dupes
      (SelectList Ann
         [SelectItem Ann
            (WindowFn Ann (FunCall Ann (Name Ann [Nmc "row_number"]) [])
               [FunCall Ann (Name Ann [Nmc "!rowctor"])
                  [Identifier Ann (Nmc "a"), Identifier Ann (Nmc "b")]]
               [(Identifier Ann (Nmc "c"), Asc)]
               FrameUnboundedPreceding)
            (Nmc "place")])
      [Tref Ann (Name Ann [Nmc "tbl"]) (NoAlias Ann)]
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]
select * from a natural inner join (select * from b) as a;
[QueryStatement Ann
   (Select Ann Dupes (SelectList Ann [SelExp Ann (Star Ann)])
      [JoinTref Ann (Tref Ann (Name Ann [Nmc "a"]) (NoAlias Ann)) Natural
         Inner
         (SubTref Ann
            (Select Ann Dupes (SelectList Ann [SelExp Ann (Star Ann)])
               [Tref Ann (Name Ann [Nmc "b"]) (NoAlias Ann)]
               Nothing
               []
               Nothing
               []
               Nothing
               Nothing)
            (TableAlias Ann (Nmc "a")))
         Nothing
         (NoAlias Ann)]
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]
select * from a order by c;
[QueryStatement Ann
   (Select Ann Dupes (SelectList Ann [SelExp Ann (Star Ann)])
      [Tref Ann (Name Ann [Nmc "a"]) (NoAlias Ann)]
      Nothing
      []
      Nothing
      [(Identifier Ann (Nmc "c"), Asc)]
      Nothing
      Nothing)]
select *
from Adventure
order by Clicks desc, AdventureID;
[QueryStatement Ann
   (Select Ann Dupes (SelectList Ann [SelExp Ann (Star Ann)])
      [Tref Ann (Name Ann [Nmc "Adventure"]) (NoAlias Ann)]
      Nothing
      []
      Nothing
      [(Identifier Ann (Nmc "Clicks"), Desc),
       (Identifier Ann (Nmc "AdventureID"), Asc)]
      Nothing
      Nothing)]
select * from a order by c,d asc;
[QueryStatement Ann
   (Select Ann Dupes (SelectList Ann [SelExp Ann (Star Ann)])
      [Tref Ann (Name Ann [Nmc "a"]) (NoAlias Ann)]
      Nothing
      []
      Nothing
      [(Identifier Ann (Nmc "c"), Asc), (Identifier Ann (Nmc "d"), Asc)]
      Nothing
      Nothing)]
select * from a order by c,d desc;
[QueryStatement Ann
   (Select Ann Dupes (SelectList Ann [SelExp Ann (Star Ann)])
      [Tref Ann (Name Ann [Nmc "a"]) (NoAlias Ann)]
      Nothing
      []
      Nothing
      [(Identifier Ann (Nmc "c"), Asc), (Identifier Ann (Nmc "d"), Desc)]
      Nothing
      Nothing)]
select * from a order by c limit 1;
[QueryStatement Ann
   (Select Ann Dupes (SelectList Ann [SelExp Ann (Star Ann)])
      [Tref Ann (Name Ann [Nmc "a"]) (NoAlias Ann)]
      Nothing
      []
      Nothing
      [(Identifier Ann (Nmc "c"), Asc)]
      (Just (NumberLit Ann "1"))
      Nothing)]
select top 3 * from a order by c;
[QueryStatement Ann
   (Select Ann Dupes (SelectList Ann [SelExp Ann (Star Ann)])
      [Tref Ann (Name Ann [Nmc "a"]) (NoAlias Ann)]
      Nothing
      []
      Nothing
      [(Identifier Ann (Nmc "c"), Asc)]
      (Just (NumberLit Ann "3"))
      Nothing)]
select * from a order by c offset 3;
[QueryStatement Ann
   (Select Ann Dupes (SelectList Ann [SelExp Ann (Star Ann)])
      [Tref Ann (Name Ann [Nmc "a"]) (NoAlias Ann)]
      Nothing
      []
      Nothing
      [(Identifier Ann (Nmc "c"), Asc)]
      Nothing
      (Just (NumberLit Ann "3")))]
select a from (select b from c) as d;
[QueryStatement Ann
   (Select Ann Dupes
      (SelectList Ann [SelExp Ann (Identifier Ann (Nmc "a"))])
      [SubTref Ann
         (Select Ann Dupes
            (SelectList Ann [SelExp Ann (Identifier Ann (Nmc "b"))])
            [Tref Ann (Name Ann [Nmc "c"]) (NoAlias Ann)]
            Nothing
            []
            Nothing
            []
            Nothing
            Nothing)
         (TableAlias Ann (Nmc "d"))]
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]
select * from gen();
[QueryStatement Ann
   (Select Ann Dupes (SelectList Ann [SelExp Ann (Star Ann)])
      [FunTref Ann (FunCall Ann (Name Ann [Nmc "gen"]) []) (NoAlias Ann)]
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]
select * from gen() as t;
[QueryStatement Ann
   (Select Ann Dupes (SelectList Ann [SelExp Ann (Star Ann)])
      [FunTref Ann (FunCall Ann (Name Ann [Nmc "gen"]) [])
         (TableAlias Ann (Nmc "t"))]
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]
select count(distinct b) from c;
[QueryStatement Ann
   (Select Ann Dupes
      (SelectList Ann
         [SelExp Ann
            (AggregateFn Ann Distinct
               (FunCall Ann (Name Ann [Nmc "count"]) [Identifier Ann (Nmc "b")])
               [])])
      [Tref Ann (Name Ann [Nmc "c"]) (NoAlias Ann)]
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]
select count(all b) from c;
[QueryStatement Ann
   (Select Ann Dupes
      (SelectList Ann
         [SelExp Ann
            (AggregateFn Ann Dupes
               (FunCall Ann (Name Ann [Nmc "count"]) [Identifier Ann (Nmc "b")])
               [])])
      [Tref Ann (Name Ann [Nmc "c"]) (NoAlias Ann)]
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]
select string_agg(distinct relname,',' order by relname1) from pg_class;
[QueryStatement Ann
   (Select Ann Dupes
      (SelectList Ann
         [SelExp Ann
            (AggregateFn Ann Distinct
               (FunCall Ann (Name Ann [Nmc "string_agg"])
                  [Identifier Ann (Nmc "relname"), StringLit Ann ","])
               [(Identifier Ann (Nmc "relname1"), Asc)])])
      [Tref Ann (Name Ann [Nmc "pg_class"]) (NoAlias Ann)]
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]
select a, count(b) from c group by a;
[QueryStatement Ann
   (Select Ann Dupes
      (SelectList Ann
         [SelExp Ann (Identifier Ann (Nmc "a")),
          SelExp Ann
            (FunCall Ann (Name Ann [Nmc "count"]) [Identifier Ann (Nmc "b")])])
      [Tref Ann (Name Ann [Nmc "c"]) (NoAlias Ann)]
      Nothing
      [Identifier Ann (Nmc "a")]
      Nothing
      []
      Nothing
      Nothing)]
select a, count(b) as cnt from c group by a having cnt > 4;
[QueryStatement Ann
   (Select Ann Dupes
      (SelectList Ann
         [SelExp Ann (Identifier Ann (Nmc "a")),
          SelectItem Ann
            (FunCall Ann (Name Ann [Nmc "count"]) [Identifier Ann (Nmc "b")])
            (Nmc "cnt")])
      [Tref Ann (Name Ann [Nmc "c"]) (NoAlias Ann)]
      Nothing
      [Identifier Ann (Nmc "a")]
      (Just
         (FunCall Ann (Name Ann [Nmc ">"])
            [Identifier Ann (Nmc "cnt"), NumberLit Ann "4"]))
      []
      Nothing
      Nothing)]
select a from (select 1 as a, 2 as b) x;
[QueryStatement Ann
   (Select Ann Dupes
      (SelectList Ann [SelExp Ann (Identifier Ann (Nmc "a"))])
      [SubTref Ann
         (Select Ann Dupes
            (SelectList Ann
               [SelectItem Ann (NumberLit Ann "1") (Nmc "a"),
                SelectItem Ann (NumberLit Ann "2") (Nmc "b")])
            []
            Nothing
            []
            Nothing
            []
            Nothing
            Nothing)
         (TableAlias Ann (Nmc "x"))]
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]

some misc stuff

select (p).x, (p).y from pos;
[QueryStatement Ann
   (Select Ann Dupes
      (SelectList Ann
         [SelExp Ann (QIdentifier Ann [Nmc "p", Nmc "x"]),
          SelExp Ann (QIdentifier Ann [Nmc "p", Nmc "y"])])
      [Tref Ann (Name Ann [Nmc "pos"]) (NoAlias Ann)]
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]
select ($1).x, ($1).y from pos;
[QueryStatement Ann
   (Select Ann Dupes
      (SelectList Ann
         [SelExp Ann
            (FunCall Ann (Name Ann [Nmc "."])
               [PositionalArg Ann 1, Identifier Ann (Nmc "x")]),
          SelExp Ann
            (FunCall Ann (Name Ann [Nmc "."])
               [PositionalArg Ann 1, Identifier Ann (Nmc "y")])])
      [Tref Ann (Name Ann [Nmc "pos"]) (NoAlias Ann)]
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]
select row_number() over(), x from tb;
[QueryStatement Ann
   (Select Ann Dupes
      (SelectList Ann
         [SelExp Ann
            (WindowFn Ann (FunCall Ann (Name Ann [Nmc "row_number"]) []) [] []
               FrameUnboundedPreceding),
          SelExp Ann (Identifier Ann (Nmc "x"))])
      [Tref Ann (Name Ann [Nmc "tb"]) (NoAlias Ann)]
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]

dml

insert

insert into testtable
(columna,columnb)
values (1,2);
[Insert Ann (Name Ann [Nmc "testtable"])
   [Nmc "columna", Nmc "columnb"]
   (Values Ann [[NumberLit Ann "1", NumberLit Ann "2"]])
   Nothing]
values (1,2), (3,4);
[QueryStatement Ann
   (Values Ann
      [[NumberLit Ann "1", NumberLit Ann "2"],
       [NumberLit Ann "3", NumberLit Ann "4"]])]
insert into testtable
(columna,columnb)
values (1,2), (3,4);
[Insert Ann (Name Ann [Nmc "testtable"])
   [Nmc "columna", Nmc "columnb"]
   (Values Ann
      [[NumberLit Ann "1", NumberLit Ann "2"],
       [NumberLit Ann "3", NumberLit Ann "4"]])
   Nothing]
insert into a
    select b from c;
[Insert Ann (Name Ann [Nmc "a"]) []
   (Select Ann Dupes
      (SelectList Ann [SelExp Ann (Identifier Ann (Nmc "b"))])
      [Tref Ann (Name Ann [Nmc "c"]) (NoAlias Ann)]
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)
   Nothing]
insert into testtable
(columna,columnb)
values (1,2) returning id;
[Insert Ann (Name Ann [Nmc "testtable"])
   [Nmc "columna", Nmc "columnb"]
   (Values Ann [[NumberLit Ann "1", NumberLit Ann "2"]])
   (Just (SelectList Ann [SelExp Ann (Identifier Ann (Nmc "id"))]))]

update

update tb
  set x = 1, y = 2;
[Update Ann (Name Ann [Nmc "tb"])
   [SetClause Ann (Nmc "x") (NumberLit Ann "1"),
    SetClause Ann (Nmc "y") (NumberLit Ann "2")]
   []
   Nothing
   Nothing]
update tb
  set x = 1, y = 2 where z = true;
[Update Ann (Name Ann [Nmc "tb"])
   [SetClause Ann (Nmc "x") (NumberLit Ann "1"),
    SetClause Ann (Nmc "y") (NumberLit Ann "2")]
   []
   (Just
      (FunCall Ann (Name Ann [Nmc "="])
         [Identifier Ann (Nmc "z"), BooleanLit Ann True]))
   Nothing]
update tb
  set x = 1, y = 2 returning id;
[Update Ann (Name Ann [Nmc "tb"])
   [SetClause Ann (Nmc "x") (NumberLit Ann "1"),
    SetClause Ann (Nmc "y") (NumberLit Ann "2")]
   []
   Nothing
   (Just (SelectList Ann [SelExp Ann (Identifier Ann (Nmc "id"))]))]
update tb
  set (x,y) = (1,2);
[Update Ann (Name Ann [Nmc "tb"])
   [MultiSetClause Ann [Nmc "x", Nmc "y"]
      (FunCall Ann (Name Ann [Nmc "!rowctor"])
         [NumberLit Ann "1", NumberLit Ann "2"])]
   []
   Nothing
   Nothing]

delete

delete from tbl1 where x = true;
[Delete Ann (Name Ann [Nmc "tbl1"]) []
   (Just
      (FunCall Ann (Name Ann [Nmc "="])
         [Identifier Ann (Nmc "x"), BooleanLit Ann True]))
   Nothing]
delete from tbl1 where x = true returning id;
[Delete Ann (Name Ann [Nmc "tbl1"]) []
   (Just
      (FunCall Ann (Name Ann [Nmc "="])
         [Identifier Ann (Nmc "x"), BooleanLit Ann True]))
   (Just (SelectList Ann [SelExp Ann (Identifier Ann (Nmc "id"))]))]

truncate

truncate test;
[Truncate Ann [Name Ann [Nmc "test"]] ContinueIdentity Restrict]
truncate table test, test2 restart identity cascade;
[Truncate Ann [Name Ann [Nmc "test"], Name Ann [Nmc "test2"]]
   RestartIdentity
   Cascade]

copy

copy tbl(a,b) from stdin;
bat	t
bear	f
\.
[Copy Ann (Name Ann [Nmc "tbl"]) [Nmc "a", Nmc "b"] Stdin,
 CopyData Ann "bat\tt\nbear\tf\n"]

ddl

create table

simple tables

create table test (
  fielda text,
  fieldb int
);
[CreateTable Ann (Name Ann [Nmc "test"])
   [AttributeDef Ann (Nmc "fielda") (SimpleTypeName Ann "text")
      Nothing
      [],
    AttributeDef Ann (Nmc "fieldb") (SimpleTypeName Ann "int") Nothing
      []]
   []]
create table tbl (
  fld boolean default false);
[CreateTable Ann (Name Ann [Nmc "tbl"])
   [AttributeDef Ann (Nmc "fld") (SimpleTypeName Ann "boolean")
      (Just (BooleanLit Ann False))
      []]
   []]
create table tbl as select 1;
[CreateTableAs Ann (Name Ann [Nmc "tbl"])
   (Select Ann Dupes (SelectList Ann [SelExp Ann (NumberLit Ann "1")])
      []
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]
alter table a alter column b set default 1;
[AlterTable Ann (Name Ann [Nmc "a"])
   [AlterColumnDefault Ann (Nmc "b") (NumberLit Ann "1")]]
alter table a add constraint unique(b);
[AlterTable Ann (Name Ann [Nmc "a"])
   [AddConstraint Ann (UniqueConstraint Ann "" [Nmc "b"])]]

constraints

nulls

create table t1 (
 a text null
);
[CreateTable Ann (Name Ann [Nmc "t1"])
   [AttributeDef Ann (Nmc "a") (SimpleTypeName Ann "text") Nothing
      [NullConstraint Ann ""]]
   []]
create table t1 (
 a text not null
);
[CreateTable Ann (Name Ann [Nmc "t1"])
   [AttributeDef Ann (Nmc "a") (SimpleTypeName Ann "text") Nothing
      [NotNullConstraint Ann ""]]
   []]

unique

create table t1 (
 x int,
 y int,
 unique (x,y)
);
[CreateTable Ann (Name Ann [Nmc "t1"])
   [AttributeDef Ann (Nmc "x") (SimpleTypeName Ann "int") Nothing [],
    AttributeDef Ann (Nmc "y") (SimpleTypeName Ann "int") Nothing []]
   [UniqueConstraint Ann "" [Nmc "x", Nmc "y"]]]
create table t1 (
 x int,
 unique (x),
 y int
);
[CreateTable Ann (Name Ann [Nmc "t1"])
   [AttributeDef Ann (Nmc "x") (SimpleTypeName Ann "int") Nothing [],
    AttributeDef Ann (Nmc "y") (SimpleTypeName Ann "int") Nothing []]
   [UniqueConstraint Ann "" [Nmc "x"]]]
create table t1 (
 x int unique
);
[CreateTable Ann (Name Ann [Nmc "t1"])
   [AttributeDef Ann (Nmc "x") (SimpleTypeName Ann "int") Nothing
      [RowUniqueConstraint Ann ""]]
   []]
create table t1 (
 x int unique not null
);
[CreateTable Ann (Name Ann [Nmc "t1"])
   [AttributeDef Ann (Nmc "x") (SimpleTypeName Ann "int") Nothing
      [RowUniqueConstraint Ann "", NotNullConstraint Ann ""]]
   []]
create table t1 (
 x int not null unique
);
[CreateTable Ann (Name Ann [Nmc "t1"])
   [AttributeDef Ann (Nmc "x") (SimpleTypeName Ann "int") Nothing
      [NotNullConstraint Ann "", RowUniqueConstraint Ann ""]]
   []]

primary key

create table t1 (
 x int primary key
);
[CreateTable Ann (Name Ann [Nmc "t1"])
   [AttributeDef Ann (Nmc "x") (SimpleTypeName Ann "int") Nothing
      [RowPrimaryKeyConstraint Ann ""]]
   []]
create table t1 (
 x int,
 y int,
 primary key (x,y)
);
[CreateTable Ann (Name Ann [Nmc "t1"])
   [AttributeDef Ann (Nmc "x") (SimpleTypeName Ann "int") Nothing [],
    AttributeDef Ann (Nmc "y") (SimpleTypeName Ann "int") Nothing []]
   [PrimaryKeyConstraint Ann "" [Nmc "x", Nmc "y"]]]

check

create table t (
f text check (f in('a', 'b'))
);
[CreateTable Ann (Name Ann [Nmc "t"])
   [AttributeDef Ann (Nmc "f") (SimpleTypeName Ann "text") Nothing
      [RowCheckConstraint Ann ""
         (InPredicate Ann (Identifier Ann (Nmc "f")) True
            (InList Ann [StringLit Ann "a", StringLit Ann "b"]))]]
   []]
create table t1 (
 x int,
 y int,
 check (x>y)
);
[CreateTable Ann (Name Ann [Nmc "t1"])
   [AttributeDef Ann (Nmc "x") (SimpleTypeName Ann "int") Nothing [],
    AttributeDef Ann (Nmc "y") (SimpleTypeName Ann "int") Nothing []]
   [CheckConstraint Ann ""
      (FunCall Ann (Name Ann [Nmc ">"])
         [Identifier Ann (Nmc "x"), Identifier Ann (Nmc "y")])]]

misc

create table t (
f text not null unique check (f in('a', 'b'))
);
[CreateTable Ann (Name Ann [Nmc "t"])
   [AttributeDef Ann (Nmc "f") (SimpleTypeName Ann "text") Nothing
      [NotNullConstraint Ann "", RowUniqueConstraint Ann "",
       RowCheckConstraint Ann ""
         (InPredicate Ann (Identifier Ann (Nmc "f")) True
            (InList Ann [StringLit Ann "a", StringLit Ann "b"]))]]
   []]

references

create table t1 (
 x int references t2
);
[CreateTable Ann (Name Ann [Nmc "t1"])
   [AttributeDef Ann (Nmc "x") (SimpleTypeName Ann "int") Nothing
      [RowReferenceConstraint Ann "" (Name Ann [Nmc "t2"]) Nothing
         Restrict
         Restrict]]
   []]
create table t1 (
 x int references t2(y)
);
[CreateTable Ann (Name Ann [Nmc "t1"])
   [AttributeDef Ann (Nmc "x") (SimpleTypeName Ann "int") Nothing
      [RowReferenceConstraint Ann "" (Name Ann [Nmc "t2"])
         (Just (Nmc "y"))
         Restrict
         Restrict]]
   []]
create table t1 (
 x int,
 y int,
 foreign key (x,y) references t2
);
[CreateTable Ann (Name Ann [Nmc "t1"])
   [AttributeDef Ann (Nmc "x") (SimpleTypeName Ann "int") Nothing [],
    AttributeDef Ann (Nmc "y") (SimpleTypeName Ann "int") Nothing []]
   [ReferenceConstraint Ann "" [Nmc "x", Nmc "y"]
      (Name Ann [Nmc "t2"])
      []
      Restrict
      Restrict]]
create table t1 (
 x int,
 y int,
 foreign key (x,y) references t2(z,w)
);
[CreateTable Ann (Name Ann [Nmc "t1"])
   [AttributeDef Ann (Nmc "x") (SimpleTypeName Ann "int") Nothing [],
    AttributeDef Ann (Nmc "y") (SimpleTypeName Ann "int") Nothing []]
   [ReferenceConstraint Ann "" [Nmc "x", Nmc "y"]
      (Name Ann [Nmc "t2"])
      [Nmc "z", Nmc "w"]
      Restrict
      Restrict]]
create table t1 (
 x int references t2 on delete cascade
);
[CreateTable Ann (Name Ann [Nmc "t1"])
   [AttributeDef Ann (Nmc "x") (SimpleTypeName Ann "int") Nothing
      [RowReferenceConstraint Ann "" (Name Ann [Nmc "t2"]) Nothing
         Cascade
         Restrict]]
   []]
create table t1 (
 x int references t2 on update cascade
);
[CreateTable Ann (Name Ann [Nmc "t1"])
   [AttributeDef Ann (Nmc "x") (SimpleTypeName Ann "int") Nothing
      [RowReferenceConstraint Ann "" (Name Ann [Nmc "t2"]) Nothing
         Restrict
         Cascade]]
   []]
create table t1 (
 x int references t2 on delete cascade on update cascade
);
[CreateTable Ann (Name Ann [Nmc "t1"])
   [AttributeDef Ann (Nmc "x") (SimpleTypeName Ann "int") Nothing
      [RowReferenceConstraint Ann "" (Name Ann [Nmc "t2"]) Nothing
         Cascade
         Cascade]]
   []]
create table t1 (
 x int,
 y int,
 foreign key (x,y) references t2 on update cascade on delete cascade
);
[CreateTable Ann (Name Ann [Nmc "t1"])
   [AttributeDef Ann (Nmc "x") (SimpleTypeName Ann "int") Nothing [],
    AttributeDef Ann (Nmc "y") (SimpleTypeName Ann "int") Nothing []]
   [ReferenceConstraint Ann "" [Nmc "x", Nmc "y"]
      (Name Ann [Nmc "t2"])
      []
      Cascade
      Cascade]]

misc ddl

misc create

create view v1 as
select a,b from t;
[CreateView Ann (Name Ann [Nmc "v1"]) Nothing
   (Select Ann Dupes
      (SelectList Ann
         [SelExp Ann (Identifier Ann (Nmc "a")),
          SelExp Ann (Identifier Ann (Nmc "b"))])
      [Tref Ann (Name Ann [Nmc "t"]) (NoAlias Ann)]
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]
create view v1(c,d) as
select a,b from t;
[CreateView Ann (Name Ann [Nmc "v1"]) (Just [Nmc "c", Nmc "d"])
   (Select Ann Dupes
      (SelectList Ann
         [SelExp Ann (Identifier Ann (Nmc "a")),
          SelExp Ann (Identifier Ann (Nmc "b"))])
      [Tref Ann (Name Ann [Nmc "t"]) (NoAlias Ann)]
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]
create domain td as text check (value in ('t1', 't2'));
[CreateDomain Ann (Name Ann [Nmc "td"]) (SimpleTypeName Ann "text")
   ""
   (Just
      (InPredicate Ann (Identifier Ann (Nmc "value")) True
         (InList Ann [StringLit Ann "t1", StringLit Ann "t2"])))]
create type tp1 as (
  f1 text,
  f2 text
);
[CreateType Ann (Name Ann [Nmc "tp1"])
   [TypeAttDef Ann (Nmc "f1") (SimpleTypeName Ann "text"),
    TypeAttDef Ann (Nmc "f2") (SimpleTypeName Ann "text")]]
create sequence s start with 5 increment by 4 no maxvalue no minvalue cache 1;
[CreateSequence Ann (Name Ann [Nmc "s"]) 4 1 9223372036854775807 5
   1]
alter sequence s owned by a.b;
[AlterSequence Ann (Name Ann [Nmc "s"])
   (Name Ann [Nmc "a", Nmc "b"])]
create trigger tr
after insert or delete on tb
for each statement
execute procedure fb();
[CreateTrigger Ann (Nmc "tr") TriggerAfter [TInsert, TDelete]
   (Name Ann [Nmc "tb"])
   EachStatement
   (Name Ann [Nmc "fb"])
   []]

drops

drop domain t;
[DropSomething Ann Domain Require [Name Ann [Nmc "t"]] Restrict]
drop domain if exists t,u cascade;
[DropSomething Ann Domain IfExists
   [Name Ann [Nmc "t"], Name Ann [Nmc "u"]]
   Cascade]
drop domain t restrict;
[DropSomething Ann Domain Require [Name Ann [Nmc "t"]] Restrict]
drop type t;
[DropSomething Ann Type Require [Name Ann [Nmc "t"]] Restrict]
drop table t;
[DropSomething Ann Table Require [Name Ann [Nmc "t"]] Restrict]
drop view t;
[DropSomething Ann View Require [Name Ann [Nmc "t"]] Restrict]

functionsddl

basics

create function t1(text) returns text as $$
select a from t1 where b = $1;
$$ language sql stable;
[CreateFunction Ann (Name Ann [Nmc "t1"])
   [ParamDefTp Ann (SimpleTypeName Ann "text")]
   (SimpleTypeName Ann "text")
   NoReplace
   Sql
   (SqlFnBody Ann
      [QueryStatement Ann
         (Select Ann Dupes
            (SelectList Ann [SelExp Ann (Identifier Ann (Nmc "a"))])
            [Tref Ann (Name Ann [Nmc "t1"]) (NoAlias Ann)]
            (Just
               (FunCall Ann (Name Ann [Nmc "="])
                  [Identifier Ann (Nmc "b"), PositionalArg Ann 1]))
            []
            Nothing
            []
            Nothing
            Nothing)])
   Stable]
create function fn() returns void as $$
declare
  a int;
  b text;
begin
  null;
end;
$$ language plpgsql volatile;
[CreateFunction Ann (Name Ann [Nmc "fn"]) []
   (SimpleTypeName Ann "void")
   NoReplace
   Plpgsql
   (PlpgsqlFnBody Ann
      (Block Ann Nothing
         [VarDef Ann (Nmc "a") (SimpleTypeName Ann "int") Nothing,
          VarDef Ann (Nmc "b") (SimpleTypeName Ann "text") Nothing]
         [NullStatement Ann]))
   Volatile]
create function fn() returns void as $$
declare
  a int;
  b text;
begin
  null;
end;
$$ language plpgsql volatile;
[CreateFunction Ann (Name Ann [Nmc "fn"]) []
   (SimpleTypeName Ann "void")
   NoReplace
   Plpgsql
   (PlpgsqlFnBody Ann
      (Block Ann Nothing
         [VarDef Ann (Nmc "a") (SimpleTypeName Ann "int") Nothing,
          VarDef Ann (Nmc "b") (SimpleTypeName Ann "text") Nothing]
         [NullStatement Ann]))
   Volatile]
create function fn(a text[]) returns int[] as $$
declare
  b xtype[] := '{}';
begin
  null;
end;
$$ language plpgsql immutable;
[CreateFunction Ann (Name Ann [Nmc "fn"])
   [ParamDef Ann (Nmc "a")
      (ArrayTypeName Ann (SimpleTypeName Ann "text"))]
   (ArrayTypeName Ann (SimpleTypeName Ann "int"))
   NoReplace
   Plpgsql
   (PlpgsqlFnBody Ann
      (Block Ann Nothing
         [VarDef Ann (Nmc "b")
            (ArrayTypeName Ann (SimpleTypeName Ann "xtype"))
            (Just (StringLit Ann "{}"))]
         [NullStatement Ann]))
   Immutable]
create function fn() returns void as '
declare
  a int := 3;
begin
  null;
end;
' language plpgsql stable;
[CreateFunction Ann (Name Ann [Nmc "fn"]) []
   (SimpleTypeName Ann "void")
   NoReplace
   Plpgsql
   (PlpgsqlFnBody Ann
      (Block Ann Nothing
         [VarDef Ann (Nmc "a") (SimpleTypeName Ann "int")
            (Just (NumberLit Ann "3"))]
         [NullStatement Ann]))
   Stable]
create function fn(int) returns void as '
declare
  a alias for $1;
begin
  null;
end;
' language plpgsql stable;
[CreateFunction Ann (Name Ann [Nmc "fn"])
   [ParamDefTp Ann (SimpleTypeName Ann "int")]
   (SimpleTypeName Ann "void")
   NoReplace
   Plpgsql
   (PlpgsqlFnBody Ann
      (Block Ann Nothing [ParamAlias Ann (Nmc "a") 1]
         [NullStatement Ann]))
   Stable]
create function fn(b int) returns void as '
declare
  a alias for b;
begin
  null;
end;
' language plpgsql stable;
[CreateFunction Ann (Name Ann [Nmc "fn"])
   [ParamDef Ann (Nmc "b") (SimpleTypeName Ann "int")]
   (SimpleTypeName Ann "void")
   NoReplace
   Plpgsql
   (PlpgsqlFnBody Ann
      (Block Ann Nothing [VarAlias Ann (Nmc "a") (Name Ann [Nmc "b"])]
         [NullStatement Ann]))
   Stable]
create function fn() returns setof int as $$
begin
  null;
end;
$$ language plpgsql stable;
[CreateFunction Ann (Name Ann [Nmc "fn"]) []
   (SetOfTypeName Ann (SimpleTypeName Ann "int"))
   NoReplace
   Plpgsql
   (PlpgsqlFnBody Ann (Block Ann Nothing [] [NullStatement Ann]))
   Stable]
create function fn() returns void as $$
begin
  null;
end
$$ language plpgsql stable;
[CreateFunction Ann (Name Ann [Nmc "fn"]) []
   (SimpleTypeName Ann "void")
   NoReplace
   Plpgsql
   (PlpgsqlFnBody Ann (Block Ann Nothing [] [NullStatement Ann]))
   Stable]
create or replace function fn() returns void as $$
begin
  null;
end
$$ language plpgsql stable;
[CreateFunction Ann (Name Ann [Nmc "fn"]) []
   (SimpleTypeName Ann "void")
   Replace
   Plpgsql
   (PlpgsqlFnBody Ann (Block Ann Nothing [] [NullStatement Ann]))
   Stable]
drop function test(text);
[DropFunction Ann Require
   [(Name Ann [Nmc "test"], [SimpleTypeName Ann "text"])]
   Restrict]
drop function test(int,int);
[DropFunction Ann Require
   [(Name Ann [Nmc "test"],
     [SimpleTypeName Ann "int", SimpleTypeName Ann "int"])]
   Restrict]
drop function if exists a(),test(text) cascade;
[DropFunction Ann IfExists
   [(Name Ann [Nmc "a"], []),
    (Name Ann [Nmc "test"], [SimpleTypeName Ann "text"])]
   Cascade]

plpgsql

simple plpgsql statements

success := true;
[Assignment Ann (Name Ann [Nmc "success"]) (BooleanLit Ann True)]
success = true;
[Assignment Ann (Name Ann [Nmc "success"]) (BooleanLit Ann True)]
return true;
[Return Ann (Just (BooleanLit Ann True))]
return;
[Return Ann Nothing]
return next 1;
[ReturnNext Ann (NumberLit Ann "1")]
return query select a from b;
[ReturnQuery Ann
   (Select Ann Dupes
      (SelectList Ann [SelExp Ann (Identifier Ann (Nmc "a"))])
      [Tref Ann (Name Ann [Nmc "b"]) (NoAlias Ann)]
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]
raise notice 'stuff %', 1;
[Raise Ann RNotice "stuff %" [NumberLit Ann "1"]]
perform test();
[Perform Ann (FunCall Ann (Name Ann [Nmc "test"]) [])]
perform test(a,b);
[Perform Ann
   (FunCall Ann (Name Ann [Nmc "test"])
      [Identifier Ann (Nmc "a"), Identifier Ann (Nmc "b")])]
perform test(r.relvar_name || '_and_stuff');
[Perform Ann
   (FunCall Ann (Name Ann [Nmc "test"])
      [FunCall Ann (Name Ann [Nmc "||"])
         [QIdentifier Ann [Nmc "r", Nmc "relvar_name"],
          StringLit Ann "_and_stuff"]])]
select into a,b c,d from e;
[Into Ann False [Name Ann [Nmc "a"], Name Ann [Nmc "b"]]
   (QueryStatement Ann
      (Select Ann Dupes
         (SelectList Ann
            [SelExp Ann (Identifier Ann (Nmc "c")),
             SelExp Ann (Identifier Ann (Nmc "d"))])
         [Tref Ann (Name Ann [Nmc "e"]) (NoAlias Ann)]
         Nothing
         []
         Nothing
         []
         Nothing
         Nothing))]
select c,d into a,b from e;
[Into Ann False [Name Ann [Nmc "a"], Name Ann [Nmc "b"]]
   (QueryStatement Ann
      (Select Ann Dupes
         (SelectList Ann
            [SelExp Ann (Identifier Ann (Nmc "c")),
             SelExp Ann (Identifier Ann (Nmc "d"))])
         [Tref Ann (Name Ann [Nmc "e"]) (NoAlias Ann)]
         Nothing
         []
         Nothing
         []
         Nothing
         Nothing))]
delete from pieces where x = 1 and y = 1 returning tag into r.tag;
[Into Ann False [Name Ann [Nmc "r", Nmc "tag"]]
   (Delete Ann (Name Ann [Nmc "pieces"]) []
      (Just
         (FunCall Ann (Name Ann [Nmc "!and"])
            [FunCall Ann (Name Ann [Nmc "="])
               [Identifier Ann (Nmc "x"), NumberLit Ann "1"],
             FunCall Ann (Name Ann [Nmc "="])
               [Identifier Ann (Nmc "y"), NumberLit Ann "1"]]))
      (Just (SelectList Ann [SelExp Ann (Identifier Ann (Nmc "tag"))])))]
update pieces
set a=b returning tag into r.tag;
[Into Ann False [Name Ann [Nmc "r", Nmc "tag"]]
   (Update Ann (Name Ann [Nmc "pieces"])
      [SetClause Ann (Nmc "a") (Identifier Ann (Nmc "b"))]
      []
      Nothing
      (Just (SelectList Ann [SelExp Ann (Identifier Ann (Nmc "tag"))])))]
insert into t(a) values (1) returning id into x;
[Into Ann False [Name Ann [Nmc "x"]]
   (Insert Ann (Name Ann [Nmc "t"]) [Nmc "a"]
      (Values Ann [[NumberLit Ann "1"]])
      (Just (SelectList Ann [SelExp Ann (Identifier Ann (Nmc "id"))])))]
update t
  set x = 1 returning id into z;
[Into Ann False [Name Ann [Nmc "z"]]
   (Update Ann (Name Ann [Nmc "t"])
      [SetClause Ann (Nmc "x") (NumberLit Ann "1")]
      []
      Nothing
      (Just (SelectList Ann [SelExp Ann (Identifier Ann (Nmc "id"))])))]
execute s;
[Execute Ann (Identifier Ann (Nmc "s"))]
execute s into r;
[Into Ann False [Name Ann [Nmc "r"]]
   (Execute Ann (Identifier Ann (Nmc "s")))]
continue;
[ContinueStatement Ann Nothing]

other plpgsql statements

for r in select a from tbl loop
null;
end loop;
[ForQueryStatement Ann Nothing (Nmc "r")
   (Select Ann Dupes
      (SelectList Ann [SelExp Ann (Identifier Ann (Nmc "a"))])
      [Tref Ann (Name Ann [Nmc "tbl"]) (NoAlias Ann)]
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)
   [NullStatement Ann]]
for r in select a from tbl where true loop
null;
end loop;
[ForQueryStatement Ann Nothing (Nmc "r")
   (Select Ann Dupes
      (SelectList Ann [SelExp Ann (Identifier Ann (Nmc "a"))])
      [Tref Ann (Name Ann [Nmc "tbl"]) (NoAlias Ann)]
      (Just (BooleanLit Ann True))
      []
      Nothing
      []
      Nothing
      Nothing)
   [NullStatement Ann]]
for r in 1 .. 10 loop
null;
end loop;
[ForIntegerStatement Ann Nothing (Nmc "r") (NumberLit Ann "1")
   (NumberLit Ann "10")
   [NullStatement Ann]]
for r in 1..10 loop
null;
end loop;
[ForIntegerStatement Ann Nothing (Nmc "r") (NumberLit Ann "1")
   (NumberLit Ann "10")
   [NullStatement Ann]]
if a=b then
  update c set d = e;
end if;
[If Ann
   [(FunCall Ann (Name Ann [Nmc "="])
       [Identifier Ann (Nmc "a"), Identifier Ann (Nmc "b")],
     [Update Ann (Name Ann [Nmc "c"])
        [SetClause Ann (Nmc "d") (Identifier Ann (Nmc "e"))]
        []
        Nothing
        Nothing])]
   []]
if true then
  null;
else
  null;
end if;
[If Ann [(BooleanLit Ann True, [NullStatement Ann])]
   [NullStatement Ann]]
if true then
  null;
elseif false then
  return;
end if;
[If Ann
   [(BooleanLit Ann True, [NullStatement Ann]),
    (BooleanLit Ann False, [Return Ann Nothing])]
   []]
if true then
  null;
elseif false then
  return;
elsif false then
  return;
else
  return;
end if;
[If Ann
   [(BooleanLit Ann True, [NullStatement Ann]),
    (BooleanLit Ann False, [Return Ann Nothing]),
    (BooleanLit Ann False, [Return Ann Nothing])]
   [Return Ann Nothing]]
case a
  when b then null;
  when c,d then null;
  else null;
end case;
[CaseStatementSimple Ann (Identifier Ann (Nmc "a"))
   [([Identifier Ann (Nmc "b")], [NullStatement Ann]),
    ([Identifier Ann (Nmc "c"), Identifier Ann (Nmc "d")],
     [NullStatement Ann])]
   [NullStatement Ann]]

miscParserTests

multiple statements

select 1;
select 2;
[QueryStatement Ann
   (Select Ann Dupes (SelectList Ann [SelExp Ann (NumberLit Ann "1")])
      []
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing),
 QueryStatement Ann
   (Select Ann Dupes (SelectList Ann [SelExp Ann (NumberLit Ann "2")])
      []
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]

comments

[]
-- this is a test
[]
/* this is
a test*/
[]
select 1;
-- this is a test
select -- this is a test
2;
[QueryStatement Ann
   (Select Ann Dupes (SelectList Ann [SelExp Ann (NumberLit Ann "1")])
      []
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing),
 QueryStatement Ann
   (Select Ann Dupes (SelectList Ann [SelExp Ann (NumberLit Ann "2")])
      []
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]
select 1;
/* this is
a test*/
select /* this is a test*/2;
[QueryStatement Ann
   (Select Ann Dupes (SelectList Ann [SelExp Ann (NumberLit Ann "1")])
      []
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing),
 QueryStatement Ann
   (Select Ann Dupes (SelectList Ann [SelExp Ann (NumberLit Ann "2")])
      []
      Nothing
      []
      Nothing
      []
      Nothing
      Nothing)]

misc

SET search_path TO my_schema, public;
[Set Ann "search_path" [SetId Ann "my_schema", SetId Ann "public"]]
SET t1 = 3;
[Set Ann "t1" [SetNum Ann 3.0]]
SET t1 = 'stuff';
[Set Ann "t1" [SetStr Ann "stuff"]]
create language plpgsql;
[CreateLanguage Ann "plpgsql"]