Commit a4e1304e authored by Tom Lane's avatar Tom Lane

Add check that inherited constraints and defaults work.

parent 47a895fe
...@@ -84,9 +84,10 @@ SELECT '' AS two, * from CHECK2_TBL; ...@@ -84,9 +84,10 @@ SELECT '' AS two, * from CHECK2_TBL;
CREATE SEQUENCE INSERT_SEQ; CREATE SEQUENCE INSERT_SEQ;
CREATE TABLE INSERT_TBL (x INT DEFAULT nextval('insert_seq'), CREATE TABLE INSERT_TBL (x INT DEFAULT nextval('insert_seq'),
y TEXT DEFAULT '-NULL-', z INT DEFAULT -1 * currval('insert_seq'), y TEXT DEFAULT '-NULL-',
CONSTRAINT INSERT_CON CHECK (x >= 3 AND y <> 'check failed' AND x < 8), z INT DEFAULT -1 * currval('insert_seq'),
CHECK (x + z = 0)); CONSTRAINT INSERT_CON CHECK (x >= 3 AND y <> 'check failed' AND x < 8),
CHECK (x + z = 0));
INSERT INTO INSERT_TBL VALUES (null, null, null); INSERT INTO INSERT_TBL VALUES (null, null, null);
INSERT INTO INSERT_TBL(x,z) VALUES (2, -2); INSERT INTO INSERT_TBL(x,z) VALUES (2, -2);
...@@ -118,6 +119,23 @@ INSERT INTO INSERT_TBL(y) VALUES ('Y'); ...@@ -118,6 +119,23 @@ INSERT INTO INSERT_TBL(y) VALUES ('Y');
SELECT 'eight' AS one, currval('insert_seq'); SELECT 'eight' AS one, currval('insert_seq');
--
-- Check inheritance of defaults and constraints
--
CREATE TABLE INSERT_CHILD (cx INT default 42,
cy INT CHECK (cy > x))
INHERITS (INSERT_TBL);
INSERT INTO INSERT_CHILD(x,z,cy) VALUES (7,-7,11);
INSERT INTO INSERT_CHILD(x,z,cy) VALUES (7,-7,6);
INSERT INTO INSERT_CHILD(x,z,cy) VALUES (6,-7,7);
INSERT INTO INSERT_CHILD(x,y,z,cy) VALUES (6,'check failed',-6,7);
SELECT * FROM INSERT_CHILD;
DROP TABLE INSERT_CHILD;
-- --
-- Check constraints on INSERT INTO -- Check constraints on INSERT INTO
-- --
......
...@@ -102,9 +102,10 @@ SELECT '' AS two, * from CHECK2_TBL; ...@@ -102,9 +102,10 @@ SELECT '' AS two, * from CHECK2_TBL;
-- --
CREATE SEQUENCE INSERT_SEQ; CREATE SEQUENCE INSERT_SEQ;
CREATE TABLE INSERT_TBL (x INT DEFAULT nextval('insert_seq'), CREATE TABLE INSERT_TBL (x INT DEFAULT nextval('insert_seq'),
y TEXT DEFAULT '-NULL-', z INT DEFAULT -1 * currval('insert_seq'), y TEXT DEFAULT '-NULL-',
CONSTRAINT INSERT_CON CHECK (x >= 3 AND y <> 'check failed' AND x < 8), z INT DEFAULT -1 * currval('insert_seq'),
CHECK (x + z = 0)); CONSTRAINT INSERT_CON CHECK (x >= 3 AND y <> 'check failed' AND x < 8),
CHECK (x + z = 0));
INSERT INTO INSERT_TBL VALUES (null, null, null); INSERT INTO INSERT_TBL VALUES (null, null, null);
ERROR: ExecAppend: rejected due to CHECK constraint $2 ERROR: ExecAppend: rejected due to CHECK constraint $2
INSERT INTO INSERT_TBL(x,z) VALUES (2, -2); INSERT INTO INSERT_TBL(x,z) VALUES (2, -2);
...@@ -170,6 +171,26 @@ SELECT 'eight' AS one, currval('insert_seq'); ...@@ -170,6 +171,26 @@ SELECT 'eight' AS one, currval('insert_seq');
eight | 8 eight | 8
(1 row) (1 row)
--
-- Check inheritance of defaults and constraints
--
CREATE TABLE INSERT_CHILD (cx INT default 42,
cy INT CHECK (cy > x))
INHERITS (INSERT_TBL);
INSERT INTO INSERT_CHILD(x,z,cy) VALUES (7,-7,11);
INSERT INTO INSERT_CHILD(x,z,cy) VALUES (7,-7,6);
ERROR: ExecAppend: rejected due to CHECK constraint insert_child_cy
INSERT INTO INSERT_CHILD(x,z,cy) VALUES (6,-7,7);
ERROR: ExecAppend: rejected due to CHECK constraint $1
INSERT INTO INSERT_CHILD(x,y,z,cy) VALUES (6,'check failed',-6,7);
ERROR: ExecAppend: rejected due to CHECK constraint insert_con
SELECT * FROM INSERT_CHILD;
x | y | z | cx | cy
---+--------+----+----+----
7 | -NULL- | -7 | 42 | 11
(1 row)
DROP TABLE INSERT_CHILD;
-- --
-- Check constraints on INSERT INTO -- Check constraints on INSERT INTO
-- --
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment