The type checking examples have the sql on the left and the result of type checking on the right. Different sections are using different tests:
It's a bit rough at the moment, the clarity will be improved.
The source this file is generated from is here:
|
Right (ScalarType "int4")
|
|
Right (ScalarType "numeric")
|
|
|
|
Right (ScalarType "bool")
|
|
Right (ArrayType (ScalarType "int4"))
|
|
Right (ArrayType UnknownType)
|
|
Right (ArrayType (ScalarType "text"))
|
|
Right (ArrayType (ScalarType "text"))
|
|
Right (ArrayType (ScalarType "int4"))
|
|
Left
[NoMatchingOperator "!arrayctor"
[ScalarType "int4", ScalarType "bool"]]
|
|
Right (ScalarType "bool")
|
|
Left
[NoMatchingOperator "=" [ScalarType "int4", ScalarType "bool"]]
|
substring('aqbc' from 2 for 2)
|
Right (ScalarType "text")
|
substring(3 from 2 for 2)
|
Left
[NoMatchingOperator "!substring"
[ScalarType "int4", ScalarType "int4", ScalarType "int4"]]
|
substring('aqbc' from 2 for true)
|
Left
[NoMatchingOperator "!substring"
[UnknownType, ScalarType "int4", ScalarType "bool"]]
|
|
Right (ScalarType "bool")
|
|
Left
[IncompatibleTypeSet
[ScalarType "int4", ScalarType "bool", ScalarType "int4"]]
|
|
Right (ScalarType "int4")
|
|
|
|
Right (ScalarType "text")
|
|
Right (ScalarType "bool")
|
|
Left [NoMatchingOperator "!not" [ScalarType "int4"]]
|
|
Right (ScalarType "int4")
|
|
Left [NoMatchingOperator "@" [ScalarType "bool"]]
|
|
Right (ScalarType "int4")
|
|
Left [NoMatchingOperator "-" [UnknownType]]
|
|
Right (ScalarType "int4")
|
|
Right (ScalarType "bool")
|
|
Right (ScalarType "bool")
|
|
Right (ScalarType "int4")
|
|
Right (ScalarType "int4")
|
|
Right (ScalarType "int4")
|
|
Right (ScalarType "int4")
|
|
Right (ScalarType "float8")
|
|
Right (ScalarType "int4")
|
|
Left
[NoMatchingOperator "!and" [ScalarType "int4", ScalarType "int4"]]
|
|
Right (ScalarType "bool")
|
|
Right (ScalarType "bool")
|
|
Right (ScalarType "text")
|
|
Left [NoMatchingOperator "lower" [ScalarType "int4"]]
|
|
Right (ScalarType "int4")
|
|
Right (ScalarType "int4")
|
coalesce('3',1,true,null)
|
Left
[NoMatchingOperator "coalesce"
[UnknownType, ScalarType "int4", ScalarType "bool", UnknownType]]
|
|
|
nullif('hello'::text,'hello')
|
Right (ScalarType "text")
|
|
Right (ScalarType "int4")
|
|
Left
[NoMatchingOperator "nullif"
[ScalarType "bool", ScalarType "int4"]]
|
|
Right (ScalarType "int4")
|
|
Right (ScalarType "int4")
|
|
Left
[NoMatchingOperator "least" [ScalarType "int4", ScalarType "bool"]]
|
|
Right (AnonymousRecordType [ScalarType "int4"])
|
|
Right (AnonymousRecordType [ScalarType "int4", ScalarType "int4"])
|
|
Right (AnonymousRecordType [UnknownType, UnknownType])
|
|
Right
(AnonymousRecordType
[ScalarType "bool", ScalarType "int4", UnknownType])
|
|
Right
(AnonymousRecordType
[ScalarType "bool", ScalarType "int4", UnknownType,
ScalarType "numeric"])
|
|
Right (ScalarType "bool")
|
|
Right (ScalarType "bool")
|
|
Right (ScalarType "bool")
|
|
Left
[NoMatchingOperator "="
[AnonymousRecordType
[ScalarType "int4", ScalarType "int4", ScalarType "int4"],
AnonymousRecordType [ScalarType "int4", ScalarType "int4"]]]
|
|
Right (ScalarType "bool")
|
|
Left
[NoMatchingOperator "="
[AnonymousRecordType [ScalarType "int4", ScalarType "bool"],
AnonymousRecordType [ScalarType "int4", ScalarType "int4"]]]
|
|
Right (ScalarType "bool")
|
|
Right (ScalarType "bool")
|
|
Right (ScalarType "bool")
|
|
Right (ScalarType "bool")
|
|
Right (ScalarType "bool")
|
case
when true then 1
end
|
Right (ScalarType "int4")
|
case
when 1=2 then 'stuff'
when 2=3 then 'blah'
else 'test'
end
|
|
case
when 1=2 then 'stuff'
when 2=3 then 'blah'
else 'test'::text
end
|
Right (ScalarType "text")
|
case
when 1=2 then 'stuff'
when true=3 then 'blah'
else 'test'
end
|
Left
[NoMatchingOperator "=" [ScalarType "bool", ScalarType "int4"]]
|
case
when 1=2 then true
when 2=3 then false
else 1
end
|
Left
[IncompatibleTypeSet
[ScalarType "bool", ScalarType "bool", ScalarType "int4"]]
|
case
when 1=2 then false
when 2=3 then 1
else true
end
|
Left
[IncompatibleTypeSet
[ScalarType "bool", ScalarType "int4", ScalarType "bool"]]
|
case 1 when 2 then 3 else 4 end
|
Right (ScalarType "int4")
|
case 1 when true then 3 else 4 end
|
Left [IncompatibleTypeSet [ScalarType "int4", ScalarType "bool"]]
|
case 1 when 2 then true else false end
|
Right (ScalarType "bool")
|
case 1 when 2 then 3 else false end
|
Left [IncompatibleTypeSet [ScalarType "int4", ScalarType "bool"]]
|
array_append(ARRAY[1,2], 3)
|
Right (ArrayType (ScalarType "int4"))
|
array_append(ARRAY['a','b'], 'c')
|
Right (ArrayType UnknownType)
|
array_append(ARRAY['a','b'], 'c'::text)
|
Right (ArrayType (ScalarType "text"))
|
array_append(ARRAY['a','b'::text], 'c')
|
Right (ArrayType (ScalarType "text"))
|
array_append(ARRAY['a'::int,'b'], 'c')
|
Right (ArrayType (ScalarType "int4"))
|
|
Right [Just ([], [("?column?", ScalarType "int4")])]
|
|
Right [Just ([], [("a", ScalarType "int4")])]
|
|
Right
[Just
([],
[("?column?", ScalarType "int4"),
("?column?", ScalarType "int4")])]
|
|
Right
[Just ([], [("a", ScalarType "int4"), ("b", ScalarType "int4")])]
|
select 1+2 as a, 'a' || 'b';
|
Right
[Just
([], [("a", ScalarType "int4"), ("?column?", ScalarType "text")])]
|
|
Right
[Just
([],
[("column1", ScalarType "int4"), ("column2", ScalarType "int4")])]
|
|
Right
[Just
([],
[("column1", ScalarType "int4"), ("column2", ScalarType "int4")])]
|
values (1,2),('a', true);
|
Left [IncompatibleTypeSet [ScalarType "int4", ScalarType "bool"]]
|
|
Right
[Just
([],
[("column1", ScalarType "int4"), ("column2", ScalarType "int4")])]
|
values ('a', true),(1,2);
|
Left [IncompatibleTypeSet [ScalarType "bool", ScalarType "int4"]]
|
values ('a'::text, '2'::int2),('1','2');
|
Right
[Just
([],
[("column1", ScalarType "text"), ("column2", ScalarType "int2")])]
|
|
Left [ValuesListsMustBeSameLength]
|
select 1,2 union select '3', '4';
|
Right
[Just
([],
[("?column?", ScalarType "int4"),
("?column?", ScalarType "int4")])]
|
select 1,2 intersect select 'a', true;
|
Left [IncompatibleTypeSet [ScalarType "int4", ScalarType "bool"]]
|
select '3', '4' except select 1,2;
|
Right
[Just
([],
[("?column?", ScalarType "int4"),
("?column?", ScalarType "int4")])]
|
select 'a', true union select 1,2;
|
Left [IncompatibleTypeSet [ScalarType "bool", ScalarType "int4"]]
|
select 'a'::text, '2'::int2 intersect select '1','2';
|
Right
[Just
([], [("text", ScalarType "text"), ("int2", ScalarType "int2")])]
|
select 1,2,3 except select 1,2;
|
Left [ValuesListsMustBeSameLength]
|
select '3' as a, '4' as b except select 1,2;
|
Right
[Just ([], [("a", ScalarType "int4"), ("b", ScalarType "int4")])]
|
select a from (select 1 as a, 2 as b) x;
|
Right [Just ([], [("a", ScalarType "int4")])]
|
select b from (select 1 as a, 2 as b) x;
|
Right [Just ([], [("b", ScalarType "int4")])]
|
select c from (select 1 as a, 2 as b) x;
|
Left [UnrecognisedIdentifier "c"]
|
select typlen from pg_type;
|
Right [Just ([], [("typlen", ScalarType "int2")])]
|
|
Right [Just ([], [("oid", ScalarType "oid")])]
|
select p.oid from pg_type p;
|
Right [Just ([], [("oid", ScalarType "oid")])]
|
|
Left [UnrecognisedRelation "nope"]
|
select generate_series from generate_series(1,7);
|
Right [Just ([], [("generate_series", ScalarType "int4")])]
|
select generate_series.generate_series from generate_series(1,7);
|
Right [Just ([], [("generate_series", ScalarType "int4")])]
|
select g from generate_series(1,7) g;
|
Right [Just ([], [("g", ScalarType "int4")])]
|
select g.g from generate_series(1,7) g;
|
Right [Just ([], [("g", ScalarType "int4")])]
|
select generate_series.g from generate_series(1,7) g;
|
Left [UnrecognisedCorrelationName "generate_series"]
|
select g.generate_series from generate_series(1,7) g;
|
Left [UnrecognisedIdentifier "generate_series"]
|
select * from pg_attrdef;
|
Right
[Just
([],
[("adrelid", ScalarType "oid"), ("adnum", ScalarType "int2"),
("adbin", ScalarType "pg_node_tree"),
("adsrc", ScalarType "text")])]
|
|
Right [Just ([], [("abs", ScalarType "int4")])]
|
select * from (select 1 as a, 2 as b) a
cross join (select true as c, 4.5 as d) b;
|
Right
[Just
([],
[("a", ScalarType "int4"), ("b", ScalarType "int4"),
("c", ScalarType "bool"), ("d", ScalarType "numeric")])]
|
select * from (select 1 as a, 2 as b) a
inner join (select true as c, 4.5 as d) b on true;
|
Right
[Just
([],
[("a", ScalarType "int4"), ("b", ScalarType "int4"),
("c", ScalarType "bool"), ("d", ScalarType "numeric")])]
|
select * from (select 1 as a, 2 as b) a
inner join (select 1 as a, 4.5 as d) b using(a);
|
Right
[Just
([],
[("a", ScalarType "int4"), ("b", ScalarType "int4"),
("d", ScalarType "numeric")])]
|
select * from (select 1 as a, 2 as b) a
natural inner join (select 1 as a, 4.5 as d) b;
|
Right
[Just
([],
[("a", ScalarType "int4"), ("b", ScalarType "int4"),
("d", ScalarType "numeric")])]
|
select * from (select 2 as b, 1 as a) a
natural inner join (select 4.5 as d, 1 as a) b;
|
Right
[Just
([],
[("a", ScalarType "int4"), ("b", ScalarType "int4"),
("d", ScalarType "numeric")])]
|
select * from (select 1 as a1) a, (select 2 as a2) b;
|
Right
[Just ([], [("a1", ScalarType "int4"), ("a2", ScalarType "int4")])]
|
select * from (select 1 as a1) a, (select 2 as a1) b;
|
Right
[Just ([], [("a1", ScalarType "int4"), ("a1", ScalarType "int4")])]
|
select a.* from
(select 1 as a, 2 as b) a
cross join (select 3 as c, 4 as d) b;
|
Right
[Just ([], [("a", ScalarType "int4"), ("b", ScalarType "int4")])]
|
select a.b,b.c from
(select 1 as a, 2 as b) a
natural inner join (select 3 as a, 4 as c) b;
|
Right
[Just ([], [("b", ScalarType "int4"), ("c", ScalarType "int4")])]
|
select a.a,b.a from
(select 1 as a, 2 as b) a
natural inner join (select 3 as a, 4 as c) b;
|
Right
[Just ([], [("a", ScalarType "int4"), ("a", ScalarType "int4")])]
|
select pg_attrdef.adsrc from pg_attrdef;
|
Right [Just ([], [("adsrc", ScalarType "text")])]
|
select a.adsrc from pg_attrdef a;
|
Right [Just ([], [("adsrc", ScalarType "text")])]
|
select pg_attrdef.adsrc from pg_attrdef a;
|
Left [UnrecognisedCorrelationName "pg_attrdef"]
|
select a from (select 2 as b, 1 as a) a
natural inner join (select 4.5 as d, 1 as a) b;
|
Right [Just ([], [("a", ScalarType "int4")])]
|
select 1 from pg_type where true;
|
Right [Just ([], [("?column?", ScalarType "int4")])]
|
select 1 from pg_type where 1;
|
Left [ExpressionMustBeBool]
|
select typname from pg_type where typbyval;
|
Right [Just ([], [("typname", ScalarType "name")])]
|
select typname from pg_type where typtype = 'b';
|
Right [Just ([], [("typname", ScalarType "name")])]
|
select typname from pg_type where what = 'b';
|
Left [UnrecognisedIdentifier "what"]
|
select relname as relvar_name
from pg_class
where ((relnamespace =
(select oid
from pg_namespace
where (nspname = 'public'))) and (relkind = 'r'));
|
Right [Just ([], [("relvar_name", ScalarType "name")])]
|
select relname from pg_class where relkind in ('r', 'v');
|
Right [Just ([], [("relname", ScalarType "name")])]
|
select * from generate_series(1,7) g
where g not in (select * from generate_series(3,5));
|
Right [Just ([], [("g", ScalarType "int4")])]
|
select * from generate_series(3,5);
|
Right [Just ([], [("generate_series", ScalarType "int4")])]
|
select * from generate_series(1,7) g
where g not in (1,2);
|
Right [Just ([], [("g", ScalarType "int4")])]
|
select 3 = any(array[1,2,3]);
|
Right [Just ([], [("?column?", ScalarType "bool")])]
|
[CatCreateTable "a" [("t", ScalarType "int4")] [],
CatCreateTable "b"
[("t", ScalarType "int4"), ("u", ScalarType "numeric")]
[]]
select b.t,b.u from a,b where a.t = b.t
and b.u = (select min(b.u) from b where a.t = b.t);
|
Right
[Just
([], [("t", ScalarType "int4"), ("u", ScalarType "numeric")])]
|
insert into nope (a,b) values (c,d);
|
Left
[UnrecognisedRelation "nope", UnrecognisedIdentifier "c",
UnrecognisedIdentifier "d"]
|
insert into pg_attrdef (adrelid,adnum,adbin,adsrc)
values (1,2, 'a', 'b');
|
|
insert into pg_attrdef
values (1,2, 'a', 'c');
|
|
insert into pg_attrdef (hello,adnum,adbin,adsrc)
values (1,2, 'a', 'b');
|
Left [UnrecognisedIdentifier "hello"]
|
insert into pg_attrdef (adrelid,adnum,adbin,adsrc)
values (1,true, 'a', 'b');
|
Left [IncompatibleTypes (ScalarType "int2") (ScalarType "bool")]
|
insert into pg_attrdef (adrelid,adnum,adbin,adsrc)
values (1,true, 'a', 'b','c');
|
Left [WrongNumberOfColumns]
|
|
Left [UnrecognisedRelation "nope"]
|
update pg_attrdef set adsrc = '' where 1;
|
Left [ExpressionMustBeBool]
|
update pg_attrdef set (adbin,adsrc) = ('a','b','c');
|
Left
[IncompatibleTypes
(AnonymousRecordType
[ScalarType "pg_node_tree", ScalarType "text"])
(AnonymousRecordType [UnknownType, UnknownType, UnknownType])]
|
update pg_attrdef set (adrelid,adsrc) = (true,'b');
|
Left
[IncompatibleTypes
(AnonymousRecordType [ScalarType "oid", ScalarType "text"])
(AnonymousRecordType [ScalarType "bool", UnknownType])]
|
update pg_attrdef set (shmadrelid,adsrc) = ('a','b');
|
Left [UnrecognisedIdentifier "shmadrelid"]
|
update pg_attrdef set adsrc='';
|
|
update pg_attrdef set adsrc='' where 1=2;
|
|
update pg_attrdef set adsrc='' where adsrc='';
|
|
update pg_attrdef set adnum = adnum + 1;
|
|
create table t1 (
a int,
b text
);
|
[CatCreateTable "t1"
[("a", ScalarType "int4"), ("b", ScalarType "text")]
[("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
("xmin", ScalarType "xid"), ("ctid", ScalarType "tid")]]
|
create type t1 as (
a int,
b text
);
|
[CatCreateComposite "t1"
[("a", ScalarType "int4"), ("b", ScalarType "text")]]
|
create domain t1 as text;
|
[CatCreateDomain (DomainType "t1") (ScalarType "text")]
|
create view v1 as select * from pg_attrdef;
|
[CatCreateView "v1"
[("adrelid", ScalarType "oid"), ("adnum", ScalarType "int2"),
("adbin", ScalarType "pg_node_tree"),
("adsrc", ScalarType "text")]]
|
create function t1(text) returns text as $$
null;
$$ language sql stable;
|
[CatCreateFunction FunName "t1" [ScalarType "text"]
(ScalarType "text")
False]
|
|
[CatCreateFunction FunName "plpgsql_call_handler" []
(Pseudo LanguageHandler)
False,
CatCreateFunction FunName "plpgsql_validator" [ScalarType "oid"]
(Pseudo Void)
False]
|