summaryrefslogtreecommitdiff
path: root/src/test/regress
diff options
context:
space:
mode:
authorBruce Momjian2002-03-19 02:18:25 +0000
committerBruce Momjian2002-03-19 02:18:25 +0000
commitd3788c330517af301576a14bdd71f26da3b0e1c0 (patch)
treeaccb7af74b71d962496a250d1eb6cbec71bffd48 /src/test/regress
parent525b19399c629455bdcd63c9879f7c75f7ae3d25 (diff)
Add DOMAIN support. Includes manual pages and regression tests, from
Rod Taylor.
Diffstat (limited to 'src/test/regress')
-rw-r--r--src/test/regress/expected/domain.out114
-rw-r--r--src/test/regress/parallel_schedule2
-rw-r--r--src/test/regress/serial_schedule4
-rw-r--r--src/test/regress/sql/domain.sql111
4 files changed, 229 insertions, 2 deletions
diff --git a/src/test/regress/expected/domain.out b/src/test/regress/expected/domain.out
new file mode 100644
index 00000000000..4d8d13ec2d7
--- /dev/null
+++ b/src/test/regress/expected/domain.out
@@ -0,0 +1,114 @@
+-- Test Comment / Drop
+create domain domaindroptest int4;
+comment on domain domaindroptest is 'About to drop this..';
+create domain basetypetest domaindroptest;
+ERROR: DefineDomain: domaindroptest is not a basetype
+drop domain domaindroptest;
+ERROR: parser: parse error at or near ";"
+drop domain domaindroptest restrict;
+-- TEST Domains.
+create domain domainvarchar varchar(5);
+create domain domainnumeric numeric(8,2);
+create domain domainint4 int4;
+create domain domaintext text;
+-- Test tables using domains
+create table basictest
+ ( testint4 domainint4
+ , testtext domaintext
+ , testvarchar domainvarchar
+ , testnumeric domainnumeric
+ );
+INSERT INTO basictest values ('88', 'haha', 'short', '123.12'); -- Good
+INSERT INTO basictest values ('88', 'haha', 'short text', '123.12'); -- Bad varchar
+ERROR: value too long for type character varying(5)
+INSERT INTO basictest values ('88', 'haha', 'short', '123.1212'); -- Truncate numeric
+select * from basictest;
+ testint4 | testtext | testvarchar | testnumeric
+----------+----------+-------------+-------------
+ 88 | haha | short | 123.12
+ 88 | haha | short | 123.12
+(2 rows)
+
+drop table basictest;
+drop domain domainvarchar restrict;
+drop domain domainnumeric restrict;
+drop domain domainint4 restrict;
+drop domain domaintext restrict;
+-- Array Test
+create domain domainint4arr int4[1];
+create domain domaintextarr text[2][3];
+create table domarrtest
+ ( testint4arr domainint4arr
+ , testtextarr domaintextarr
+ );
+INSERT INTO domarrtest values ('{2,2}', '{{"a","b"}{"c","d"}}');
+INSERT INTO domarrtest values ('{{2,2}{2,2}}', '{{"a","b"}}');
+INSERT INTO domarrtest values ('{2,2}', '{{"a","b"}{"c","d"}{"e"}}');
+INSERT INTO domarrtest values ('{2,2}', '{{"a"}{"c"}}');
+INSERT INTO domarrtest values (NULL, '{{"a","b"}{"c","d","e"}}');
+drop table domarrtest;
+drop domain domainint4arr restrict;
+drop domain domaintextarr restrict;
+create domain dnotnull varchar(15) NOT NULL;
+create domain dnull varchar(15) NULL;
+create table nulltest
+ ( col1 dnotnull
+ , col2 dnotnull NULL -- NOT NULL in the domain cannot be overridden
+ , col3 dnull NOT NULL
+ , col4 dnull
+ );
+INSERT INTO nulltest DEFAULT VALUES;
+ERROR: ExecAppend: Fail to add null value in not null attribute col1
+INSERT INTO nulltest values ('a', 'b', 'c', 'd'); -- Good
+INSERT INTO nulltest values (NULL, 'b', 'c', 'd');
+ERROR: ExecAppend: Fail to add null value in not null attribute col1
+INSERT INTO nulltest values ('a', NULL, 'c', 'd');
+ERROR: ExecAppend: Fail to add null value in not null attribute col2
+INSERT INTO nulltest values ('a', 'b', NULL, 'd');
+ERROR: ExecAppend: Fail to add null value in not null attribute col3
+INSERT INTO nulltest values ('a', 'b', 'c', NULL); -- Good
+select * from nulltest;
+ col1 | col2 | col3 | col4
+------+------+------+------
+ a | b | c | d
+ a | b | c |
+(2 rows)
+
+drop table nulltest;
+drop domain dnotnull restrict;
+drop domain dnull restrict;
+create domain ddef1 int4 DEFAULT 3;
+create domain ddef2 oid DEFAULT '12';
+-- Type mixing, function returns int8
+create domain ddef3 text DEFAULT 5;
+create sequence ddef4_seq;
+create domain ddef4 int4 DEFAULT nextval(cast('ddef4_seq' as text));
+create domain ddef5 numeric(8,2) NOT NULL DEFAULT '12.12';
+create table defaulttest
+ ( col1 ddef1
+ , col2 ddef2
+ , col3 ddef3
+ , col4 ddef4
+ , col5 ddef1 NOT NULL DEFAULT NULL
+ , col6 ddef2 DEFAULT '88'
+ , col7 ddef4 DEFAULT 8000
+ , col8 ddef5
+ );
+insert into defaulttest default values;
+insert into defaulttest default values;
+insert into defaulttest default values;
+select * from defaulttest;
+ col1 | col2 | col3 | col4 | col5 | col6 | col7 | col8
+------+------+------+------+------+------+------+-------
+ 3 | 12 | 5 | 1 | 3 | 88 | 8000 | 12.12
+ 3 | 12 | 5 | 2 | 3 | 88 | 8000 | 12.12
+ 3 | 12 | 5 | 3 | 3 | 88 | 8000 | 12.12
+(3 rows)
+
+drop sequence ddef4_seq;
+drop table defaulttest;
+drop domain ddef1 restrict;
+drop domain ddef2 restrict;
+drop domain ddef3 restrict;
+drop domain ddef4 restrict;
+drop domain ddef5 restrict;
diff --git a/src/test/regress/parallel_schedule b/src/test/regress/parallel_schedule
index 877a70f902b..cd9d2d5260a 100644
--- a/src/test/regress/parallel_schedule
+++ b/src/test/regress/parallel_schedule
@@ -73,4 +73,4 @@ test: select_views alter_table portals_p2 rules foreign_key
# The sixth group of parallel test
# ----------
# "plpgsql" cannot run concurrently with "rules"
-test: limit plpgsql temp
+test: limit plpgsql temp domain
diff --git a/src/test/regress/serial_schedule b/src/test/regress/serial_schedule
index 61a5d39b649..c56b3561c2f 100644
--- a/src/test/regress/serial_schedule
+++ b/src/test/regress/serial_schedule
@@ -1,4 +1,4 @@
-# $Header: /cvsroot/pgsql/src/test/regress/serial_schedule,v 1.7 2001/09/28 07:59:38 thomas Exp $
+# $Header: /cvsroot/pgsql/src/test/regress/serial_schedule,v 1.8 2002/03/19 02:18:24 momjian Exp $
# This should probably be in an order similar to parallel_schedule.
test: boolean
test: char
@@ -80,3 +80,5 @@ test: foreign_key
test: limit
test: plpgsql
test: temp
+test: domain
+
diff --git a/src/test/regress/sql/domain.sql b/src/test/regress/sql/domain.sql
new file mode 100644
index 00000000000..1417fe31896
--- /dev/null
+++ b/src/test/regress/sql/domain.sql
@@ -0,0 +1,111 @@
+
+
+-- Test Comment / Drop
+create domain domaindroptest int4;
+comment on domain domaindroptest is 'About to drop this..';
+
+create domain basetypetest domaindroptest;
+
+drop domain domaindroptest;
+drop domain domaindroptest restrict;
+
+
+-- TEST Domains.
+
+create domain domainvarchar varchar(5);
+create domain domainnumeric numeric(8,2);
+create domain domainint4 int4;
+create domain domaintext text;
+
+
+-- Test tables using domains
+create table basictest
+ ( testint4 domainint4
+ , testtext domaintext
+ , testvarchar domainvarchar
+ , testnumeric domainnumeric
+ );
+
+INSERT INTO basictest values ('88', 'haha', 'short', '123.12'); -- Good
+INSERT INTO basictest values ('88', 'haha', 'short text', '123.12'); -- Bad varchar
+INSERT INTO basictest values ('88', 'haha', 'short', '123.1212'); -- Truncate numeric
+select * from basictest;
+
+drop table basictest;
+drop domain domainvarchar restrict;
+drop domain domainnumeric restrict;
+drop domain domainint4 restrict;
+drop domain domaintext restrict;
+
+
+-- Array Test
+create domain domainint4arr int4[1];
+create domain domaintextarr text[2][3];
+
+create table domarrtest
+ ( testint4arr domainint4arr
+ , testtextarr domaintextarr
+ );
+INSERT INTO domarrtest values ('{2,2}', '{{"a","b"}{"c","d"}}');
+INSERT INTO domarrtest values ('{{2,2}{2,2}}', '{{"a","b"}}');
+INSERT INTO domarrtest values ('{2,2}', '{{"a","b"}{"c","d"}{"e"}}');
+INSERT INTO domarrtest values ('{2,2}', '{{"a"}{"c"}}');
+INSERT INTO domarrtest values (NULL, '{{"a","b"}{"c","d","e"}}');
+
+drop table domarrtest;
+drop domain domainint4arr restrict;
+drop domain domaintextarr restrict;
+
+
+create domain dnotnull varchar(15) NOT NULL;
+create domain dnull varchar(15) NULL;
+
+create table nulltest
+ ( col1 dnotnull
+ , col2 dnotnull NULL -- NOT NULL in the domain cannot be overridden
+ , col3 dnull NOT NULL
+ , col4 dnull
+ );
+INSERT INTO nulltest DEFAULT VALUES;
+INSERT INTO nulltest values ('a', 'b', 'c', 'd'); -- Good
+INSERT INTO nulltest values (NULL, 'b', 'c', 'd');
+INSERT INTO nulltest values ('a', NULL, 'c', 'd');
+INSERT INTO nulltest values ('a', 'b', NULL, 'd');
+INSERT INTO nulltest values ('a', 'b', 'c', NULL); -- Good
+select * from nulltest;
+
+drop table nulltest;
+drop domain dnotnull restrict;
+drop domain dnull restrict;
+
+
+create domain ddef1 int4 DEFAULT 3;
+create domain ddef2 oid DEFAULT '12';
+-- Type mixing, function returns int8
+create domain ddef3 text DEFAULT 5;
+create sequence ddef4_seq;
+create domain ddef4 int4 DEFAULT nextval(cast('ddef4_seq' as text));
+create domain ddef5 numeric(8,2) NOT NULL DEFAULT '12.12';
+
+create table defaulttest
+ ( col1 ddef1
+ , col2 ddef2
+ , col3 ddef3
+ , col4 ddef4
+ , col5 ddef1 NOT NULL DEFAULT NULL
+ , col6 ddef2 DEFAULT '88'
+ , col7 ddef4 DEFAULT 8000
+ , col8 ddef5
+ );
+insert into defaulttest default values;
+insert into defaulttest default values;
+insert into defaulttest default values;
+select * from defaulttest;
+
+drop sequence ddef4_seq;
+drop table defaulttest;
+drop domain ddef1 restrict;
+drop domain ddef2 restrict;
+drop domain ddef3 restrict;
+drop domain ddef4 restrict;
+drop domain ddef5 restrict;