Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb8312c5

Browse files
committed
Add some regression tests for composite-type operations.
1 parentbb3da43 commitb8312c5

File tree

4 files changed

+191
-2
lines changed

4 files changed

+191
-2
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
--
2+
-- ROWTYPES
3+
--
4+
-- Make both a standalone composite type and a table rowtype
5+
create type complex as (r float8, i float8);
6+
create temp table fullname (first text, last text);
7+
-- Nested composite
8+
create type quad as (c1 complex, c2 complex);
9+
-- Some simple tests of I/O conversions and row construction
10+
select (1.1,2.2)::complex, row((3.3,4.4),(5.5,null))::quad;
11+
row | row
12+
-----------+------------------------
13+
(1.1,2.2) | ("(3.3,4.4)","(5.5,)")
14+
(1 row)
15+
16+
select row('Joe', 'Blow')::fullname, '(Joe,Blow)'::fullname;
17+
row | fullname
18+
------------+------------
19+
(Joe,Blow) | (Joe,Blow)
20+
(1 row)
21+
22+
select '(Joe,von Blow)'::fullname, '(Joe,d''Blow)'::fullname;
23+
fullname | fullname
24+
------------------+--------------
25+
(Joe,"von Blow") | (Joe,d'Blow)
26+
(1 row)
27+
28+
select '(Joe,"von""Blow")'::fullname, '(Joe,d\\\\Blow)'::fullname;
29+
fullname | fullname
30+
-------------------+-----------------
31+
(Joe,"von""Blow") | (Joe,"d\\Blow")
32+
(1 row)
33+
34+
select '(Joe,"Blow,Jr")'::fullname;
35+
fullname
36+
-----------------
37+
(Joe,"Blow,Jr")
38+
(1 row)
39+
40+
select '(Joe,)'::fullname;-- ok, null 2nd column
41+
fullname
42+
----------
43+
(Joe,)
44+
(1 row)
45+
46+
select '(Joe)'::fullname;-- bad
47+
ERROR: malformed record literal: "(Joe)"
48+
DETAIL: Too few columns.
49+
select '(Joe,,)'::fullname;-- bad
50+
ERROR: malformed record literal: "(Joe,,)"
51+
DETAIL: Too many columns.
52+
create temp table quadtable(f1 int, q quad);
53+
insert into quadtable values (1, ((3.3,4.4),(5.5,6.6)));
54+
insert into quadtable values (2, ((null,4.4),(5.5,6.6)));
55+
select * from quadtable;
56+
f1 | q
57+
----+---------------------------
58+
1 | ("(3.3,4.4)","(5.5,6.6)")
59+
2 | ("(,4.4)","(5.5,6.6)")
60+
(2 rows)
61+
62+
select f1, q.c1 from quadtable;-- fails, q is a table reference
63+
ERROR: relation "q" does not exist
64+
select f1, (q).c1, (qq.q).c1.i from quadtable qq;
65+
f1 | c1 | i
66+
----+-----------+-----
67+
1 | (3.3,4.4) | 4.4
68+
2 | (,4.4) | 4.4
69+
(2 rows)
70+
71+
create temp table people (fn fullname, bd date);
72+
insert into people values ('(Joe,Blow)', '1984-01-10');
73+
select * from people;
74+
fn | bd
75+
------------+------------
76+
(Joe,Blow) | 01-10-1984
77+
(1 row)
78+
79+
-- at the moment this will not work due to ALTER TABLE inadequacy:
80+
alter table fullname add column suffix text default '';
81+
ERROR: cannot alter table "fullname" because column "people"."fn" uses its rowtype
82+
-- but this should work:
83+
alter table fullname add column suffix text default null;
84+
select * from people;
85+
fn | bd
86+
-------------+------------
87+
(Joe,Blow,) | 01-10-1984
88+
(1 row)
89+
90+
-- This fails at the moment, would like it to work though:
91+
update people set fn.suffix = 'Jr';
92+
ERROR: syntax error at or near "." at character 21
93+
LINE 1: update people set fn.suffix = 'Jr';
94+
^
95+
-- ugly workaround:
96+
update people set fn = ((fn).first, (fn).last, 'III');
97+
select * from people;
98+
fn | bd
99+
----------------+------------
100+
(Joe,Blow,III) | 01-10-1984
101+
(1 row)
102+
103+
-- The object here is to ensure that toasted references inside
104+
-- composite values don't cause problems. The large f1 value will
105+
-- be toasted inside pp, it must still work after being copied to people.
106+
create temp table pp (f1 text);
107+
insert into pp values (repeat('abcdefghijkl', 100000));
108+
insert into people select ('Jim', f1, null)::fullname, current_date from pp;
109+
select (fn).first, substr((fn).last, 1, 20), length((fn).last) from people;
110+
first | substr | length
111+
-------+----------------------+---------
112+
Joe | Blow | 4
113+
Jim | abcdefghijklabcdefgh | 1200000
114+
(2 rows)
115+

‎src/test/regress/parallel_schedule

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ test: select_views portals_p2 rules foreign_key cluster
7474
# The sixth group of parallel test
7575
# ----------
7676
# "plpgsql" cannot run concurrently with "rules"
77-
test: limit plpgsql copy2 temp domain rangefuncs prepare without_oid conversion truncate alter_table sequence polymorphism
77+
test: limit plpgsql copy2 temp domain rangefuncs prepare without_oid conversion truncate alter_table sequence polymorphism rowtypes
7878

7979
# run stats by itself because its delay may be insufficient under heavy load
8080
test: stats

‎src/test/regress/serial_schedule

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $PostgreSQL: pgsql/src/test/regress/serial_schedule,v 1.24 2004/01/11 04:58:17 neilc Exp $
1+
# $PostgreSQL: pgsql/src/test/regress/serial_schedule,v 1.25 2004/06/06 21:20:46 tgl Exp $
22
# This should probably be in an order similar to parallel_schedule.
33
test: boolean
44
test: char
@@ -94,4 +94,5 @@ test: truncate
9494
test: alter_table
9595
test: sequence
9696
test: polymorphism
97+
test: rowtypes
9798
test: stats

‎src/test/regress/sql/rowtypes.sql

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
--
2+
-- ROWTYPES
3+
--
4+
5+
-- Make both a standalone composite type and a table rowtype
6+
7+
createtypecomplexas (r float8, i float8);
8+
9+
create temp table fullname (firsttext, lasttext);
10+
11+
-- Nested composite
12+
13+
createtypequadas (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(f1int, q quad);
32+
33+
insert into quadtablevalues (1, ((3.3,4.4),(5.5,6.6)));
34+
insert into quadtablevalues (2, ((null,4.4),(5.5,6.6)));
35+
36+
select*from quadtable;
37+
38+
select f1,q.c1from quadtable;-- fails, q is a table reference
39+
40+
select f1, (q).c1, (qq.q).c1.ifrom quadtable qq;
41+
42+
create temp table people (fn fullname, bddate);
43+
44+
insert into peoplevalues ('(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+
altertable fullname add column suffixtext default'';
50+
51+
-- but this should work:
52+
altertable fullname add column suffixtext defaultnull;
53+
54+
select*from people;
55+
56+
-- This fails at the moment, would like it to work though:
57+
update peoplesetfn.suffix='Jr';
58+
59+
-- ugly workaround:
60+
update peopleset fn= ((fn).first, (fn).last,'III');
61+
62+
select*from people;
63+
64+
-- The object here is to ensure that toasted references inside
65+
-- composite values don't cause problems. The large f1 value will
66+
-- be toasted inside pp, it must still work after being copied to people.
67+
68+
create temp table pp (f1text);
69+
insert into ppvalues (repeat('abcdefghijkl',100000));
70+
71+
insert into peopleselect ('Jim', f1,null)::fullname,current_datefrom pp;
72+
73+
select (fn).first, substr((fn).last,1,20), length((fn).last)from people;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp