1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-26 23:43:30 +03:00

Fixed this problem and added regression tests in domain.sql.

Also:
- Changed header file order (alphabetical)
- Changed to m = attnum - 1 in binary copy code for consistency

Rod Taylor
This commit is contained in:
Bruce Momjian
2002-09-20 03:52:50 +00:00
parent 24bebf0b72
commit 07a6fa9df1
3 changed files with 118 additions and 14 deletions

View File

@@ -37,12 +37,18 @@ 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
-- Test copy
COPY basictest (testvarchar) FROM stdin; -- fail
ERROR: copy: line 1, value too long for type character varying(5)
lost synchronization with server, resetting connection
COPY basictest (testvarchar) FROM stdin;
select * from basictest;
testint4 | testtext | testvarchar | testnumeric
----------+----------+-------------+-------------
88 | haha | short | 123.12
88 | haha | short | 123.12
(2 rows)
| | short |
(3 rows)
-- check that domains inherit operations from base types
select testtext || testvarchar as concat, testnumeric + 42 as sum
@@ -51,7 +57,8 @@ from basictest;
-----------+--------
hahashort | 165.12
hahashort | 165.12
(2 rows)
|
(3 rows)
drop table basictest;
drop domain domainvarchar restrict;
@@ -111,12 +118,18 @@ ERROR: Domain dnotnull does not allow NULL values
INSERT INTO nulltest values ('a', 'b', NULL, 'd');
ERROR: ExecInsert: Fail to add null value in not null attribute col3
INSERT INTO nulltest values ('a', 'b', 'c', NULL); -- Good
-- Test copy
COPY nulltest FROM stdin; --fail
ERROR: copy: line 1, CopyFrom: Fail to add null value in not null attribute col3
lost synchronization with server, resetting connection
COPY nulltest FROM stdin;
select * from nulltest;
col1 | col2 | col3 | col4
------+------+------+------
a | b | c | d
a | b | c |
(2 rows)
a | b | c |
(3 rows)
-- Test out coerced (casted) constraints
SELECT cast('1' as dnotnull);
@@ -156,13 +169,16 @@ NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index 'defaulttest_pkey
insert into defaulttest default values;
insert into defaulttest default values;
insert into defaulttest default values;
-- Test defaults with copy
COPY defaulttest(col5) FROM stdin;
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)
3 | 12 | 5 | 4 | 42 | 88 | 8000 | 12.12
(4 rows)
drop sequence ddef4_seq;
drop table defaulttest;

View File

@@ -35,6 +35,16 @@ create table basictest
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
-- Test copy
COPY basictest (testvarchar) FROM stdin; -- fail
notsoshorttext
\.
COPY basictest (testvarchar) FROM stdin;
short
\.
select * from basictest;
-- check that domains inherit operations from base types
@@ -84,6 +94,16 @@ 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
-- Test copy
COPY nulltest FROM stdin; --fail
a b \N d
\.
COPY nulltest FROM stdin;
a b c \N
\.
select * from nulltest;
-- Test out coerced (casted) constraints
@@ -119,6 +139,12 @@ create table defaulttest
insert into defaulttest default values;
insert into defaulttest default values;
insert into defaulttest default values;
-- Test defaults with copy
COPY defaulttest(col5) FROM stdin;
42
\.
select * from defaulttest;
drop sequence ddef4_seq;