~vcs-imports/mammoth-replicator/trunk

« back to all changes in this revision

Viewing changes to src/test/regress/sql/rowtypes.sql

  • Committer: alvherre
  • Date: 2005-12-16 21:24:52 UTC
  • Revision ID: svn-v4:db760fc0-0f08-0410-9d63-cc6633f64896:trunk:1
Initial import of the REL8_0_3 sources from the Pgsql CVS repository.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
--
 
2
-- ROWTYPES
 
3
--
 
4
 
 
5
-- Make both a standalone composite type and a table rowtype
 
6
 
 
7
create type complex as (r float8, i float8);
 
8
 
 
9
create temp table fullname (first text, last text);
 
10
 
 
11
-- Nested composite
 
12
 
 
13
create type quad as (c1 complex, c2 complex);
 
14
 
 
15
-- Some simple tests of I/O conversions and row construction
 
16
 
 
17
select (1.1,2.2)::complex, row((3.3,4.4),(5.5,null))::quad;
 
18
 
 
19
select row('Joe', 'Blow')::fullname, '(Joe,Blow)'::fullname;
 
20
 
 
21
select '(Joe,von Blow)'::fullname, '(Joe,d''Blow)'::fullname;
 
22
 
 
23
select '(Joe,"von""Blow")'::fullname, '(Joe,d\\\\Blow)'::fullname;
 
24
 
 
25
select '(Joe,"Blow,Jr")'::fullname;
 
26
 
 
27
select '(Joe,)'::fullname;      -- ok, null 2nd column
 
28
select '(Joe)'::fullname;       -- bad
 
29
select '(Joe,,)'::fullname;     -- bad
 
30
 
 
31
create temp table quadtable(f1 int, q quad);
 
32
 
 
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)));
 
35
 
 
36
select * from quadtable;
 
37
 
 
38
select f1, q.c1 from quadtable;         -- fails, q is a table reference
 
39
 
 
40
select f1, (q).c1, (qq.q).c1.i from quadtable qq;
 
41
 
 
42
create temp table people (fn fullname, bd date);
 
43
 
 
44
insert into people values ('(Joe,Blow)', '1984-01-10');
 
45
 
 
46
select * from people;
 
47
 
 
48
-- at the moment this will not work due to ALTER TABLE inadequacy:
 
49
alter table fullname add column suffix text default '';
 
50
 
 
51
-- but this should work:
 
52
alter table fullname add column suffix text default null;
 
53
 
 
54
select * from people;
 
55
 
 
56
-- test insertion/updating of subfields
 
57
update people set fn.suffix = 'Jr';
 
58
 
 
59
select * from people;
 
60
 
 
61
insert into quadtable (f1, q.c1.r, q.c2.i) values(44,55,66);
 
62
 
 
63
select * from quadtable;
 
64
 
 
65
-- The object here is to ensure that toasted references inside
 
66
-- composite values don't cause problems.  The large f1 value will
 
67
-- be toasted inside pp, it must still work after being copied to people.
 
68
 
 
69
create temp table pp (f1 text);
 
70
insert into pp values (repeat('abcdefghijkl', 100000));
 
71
 
 
72
insert into people select ('Jim', f1, null)::fullname, current_date from pp;
 
73
 
 
74
select (fn).first, substr((fn).last, 1, 20), length((fn).last) from people;