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:
|
FunCall Ann (Name Ann [Nmc "+"])
[NumberLit Ann "1", Identifier Ann (Nmc "tst1")]
|
|
FunCall Ann (Name Ann [Nmc "+"])
[Identifier Ann (Nmc "tst1"), NumberLit Ann "1"]
|
|
FunCall Ann (Name Ann [Nmc "+"])
[Identifier Ann (Nmc "tst"), Identifier Ann (Nmc "tst1")]
|
|
FunCall Ann (Name Ann [Nmc "||"])
[StringLit Ann "a", StringLit Ann "b"]
|
|
Cast Ann (StringLit Ann "stuff") (SimpleTypeName Ann "text")
|
|
Cast Ann (NumberLit Ann "245") (PrecTypeName Ann "float" 24)
|
|
Cast Ann (NumberLit Ann "245.1") (Prec2TypeName Ann "numeric" 5 3)
|
|
Cast Ann (NumberLit Ann "245")
(SimpleTypeName Ann "double precision")
|
|
TypedStringLit Ann (SimpleTypeName Ann "date") "1998-12-01"
|
|
Interval Ann "63" IntervalDay Nothing
|
|
Interval Ann "63" IntervalDay (Just 3)
|
|
Extract Ann ExtractYear (Identifier Ann (Nmc "a"))
|
|
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 Ann (Identifier Ann (Nmc "a")) (SimpleTypeName Ann "text")
|
|
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"]]
|
|
FunCall Ann (Name Ann [Nmc "substring"])
[Identifier Ann (Nmc "a"), Identifier Ann (Nmc "b"),
Identifier Ann (Nmc "c")]
|
|
FunCall Ann (Name Ann [Nmc "!like"])
[Identifier Ann (Nmc "a"), Identifier Ann (Nmc "b")]
|
|
FunCall Ann (Name Ann [Nmc "!notlike"])
[Identifier Ann (Nmc "a"), Identifier Ann (Nmc "b")]
|
|
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")]
|
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)))]
|
|
[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)]
|
|
[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)]
|
|
[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)]
|
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]
|
|
[Assignment Ann (Name Ann [Nmc "success"]) (BooleanLit Ann True)]
|
|
[Assignment Ann (Name Ann [Nmc "success"]) (BooleanLit Ann True)]
|
|
[Return Ann (Just (BooleanLit Ann True))]
|
|
|
|
[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 Ann (FunCall Ann (Name Ann [Nmc "test"]) [])]
|
|
[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 Ann (Identifier Ann (Nmc "s"))]
|
|
[Into Ann False [Name Ann [Nmc "r"]]
(Execute Ann (Identifier Ann (Nmc "s")))]
|
|
[ContinueStatement Ann Nothing]
|