Fix pg_dump bug in the database-level collation patch. "datcollate" and
[PostgreSQL.git] / src / test / regress / sql / rowtypes.sql
blob7e5c554d3b79b75cb7c3b890196766b478ea850a
1 --
2 -- ROWTYPES
3 --
5 -- Make both a standalone composite type and a table rowtype
7 create type complex as (r float8, i float8);
9 create temp table fullname (first text, last text);
11 -- Nested composite
13 create type quad as (c1 complex, c2 complex);
15 -- Some simple tests of I/O conversions and row construction
17 select (1.1,2.2)::complex, row((3.3,4.4),(5.5,null))::quad;
19 select row('Joe', 'Blow')::fullname, '(Joe,Blow)'::fullname;
21 select '(Joe,von Blow)'::fullname, '(Joe,d''Blow)'::fullname;
23 select '(Joe,"von""Blow")'::fullname, E'(Joe,d\\\\Blow)'::fullname;
25 select '(Joe,"Blow,Jr")'::fullname;
27 select '(Joe,)'::fullname;      -- ok, null 2nd column
28 select '(Joe)'::fullname;       -- bad
29 select '(Joe,,)'::fullname;     -- bad
31 create temp table quadtable(f1 int, q quad);
33 insert into quadtable values (1, ((3.3,4.4),(5.5,6.6)));
34 insert into quadtable values (2, ((null,4.4),(5.5,6.6)));
36 select * from quadtable;
38 begin;
39 set local add_missing_from = false;
40 select f1, q.c1 from quadtable;         -- fails, q is a table reference
41 rollback;
43 select f1, (q).c1, (qq.q).c1.i from quadtable qq;
45 create temp table people (fn fullname, bd date);
47 insert into people values ('(Joe,Blow)', '1984-01-10');
49 select * from people;
51 -- at the moment this will not work due to ALTER TABLE inadequacy:
52 alter table fullname add column suffix text default '';
54 -- but this should work:
55 alter table fullname add column suffix text default null;
57 select * from people;
59 -- test insertion/updating of subfields
60 update people set fn.suffix = 'Jr';
62 select * from people;
64 insert into quadtable (f1, q.c1.r, q.c2.i) values(44,55,66);
66 select * from quadtable;
68 -- The object here is to ensure that toasted references inside
69 -- composite values don't cause problems.  The large f1 value will
70 -- be toasted inside pp, it must still work after being copied to people.
72 create temp table pp (f1 text);
73 insert into pp values (repeat('abcdefghijkl', 100000));
75 insert into people select ('Jim', f1, null)::fullname, current_date from pp;
77 select (fn).first, substr((fn).last, 1, 20), length((fn).last) from people;
79 -- Test row comparison semantics.  Prior to PG 8.2 we did this in a totally
80 -- non-spec-compliant way.
82 select ROW(1,2) < ROW(1,3) as true;
83 select ROW(1,2) < ROW(1,1) as false;
84 select ROW(1,2) < ROW(1,NULL) as null;
85 select ROW(1,2,3) < ROW(1,3,NULL) as true; -- the NULL is not examined
86 select ROW(11,'ABC') < ROW(11,'DEF') as true;
87 select ROW(11,'ABC') > ROW(11,'DEF') as false;
88 select ROW(12,'ABC') > ROW(11,'DEF') as true;
90 -- = and <> have different NULL-behavior than < etc
91 select ROW(1,2,3) < ROW(1,NULL,4) as null;
92 select ROW(1,2,3) = ROW(1,NULL,4) as false;
93 select ROW(1,2,3) <> ROW(1,NULL,4) as true;
95 -- We allow operators beyond the six standard ones, if they have btree
96 -- operator classes.
97 select ROW('ABC','DEF') ~<=~ ROW('DEF','ABC') as true;
98 select ROW('ABC','DEF') ~>=~ ROW('DEF','ABC') as false;
99 select ROW('ABC','DEF') ~~ ROW('DEF','ABC') as fail;
101 -- Check row comparison with a subselect
102 select unique1, unique2 from tenk1
103 where (unique1, unique2) < any (select ten, ten from tenk1 where hundred < 3)
104       and unique1 <= 20
105 order by 1;
107 -- Also check row comparison with an indexable condition
108 select thousand, tenthous from tenk1
109 where (thousand, tenthous) >= (997, 5000)
110 order by thousand, tenthous;
112 -- Check some corner cases involving empty rowtypes
113 select ROW();
114 select ROW() IS NULL;
115 select ROW() = ROW();