Added relation name in error messages for constraint checks.

This gives more information to the user about the error and it makes such
messages consistent with the other similar messages in the code.

Reported-by: Simon Riggs
Author: Mahendra Singh and Simon Riggs
Reviewed-by: Beena Emerson and Amit Kapila
Discussion: https://postgr.es/m/CANP8+j+7YUvQvGxTrCiw77R23enMJ7DFmyA3buR+fa2pKs4XhA@mail.gmail.com
This commit is contained in:
Amit Kapila 2020-01-28 07:48:10 +05:30
parent ff8ca5fadd
commit 05f18c6b6b
17 changed files with 82 additions and 76 deletions

View File

@ -5288,8 +5288,9 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode)
ereport(ERROR,
(errcode(ERRCODE_NOT_NULL_VIOLATION),
errmsg("column \"%s\" contains null values",
NameStr(attr->attname)),
errmsg("column \"%s\" of relation \"%s\" contains null values",
NameStr(attr->attname),
RelationGetRelationName(oldrel)),
errtablecol(oldrel, attn + 1)));
}
}
@ -5304,8 +5305,9 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode)
if (!ExecCheck(con->qualstate, econtext))
ereport(ERROR,
(errcode(ERRCODE_CHECK_VIOLATION),
errmsg("check constraint \"%s\" is violated by some row",
con->name),
errmsg("check constraint \"%s\" of relation \"%s\" is violated by some row",
con->name,
RelationGetRelationName(oldrel)),
errtableconstraint(oldrel, con->name)));
break;
case CONSTR_FOREIGN:
@ -5322,11 +5324,13 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode)
if (tab->validate_default)
ereport(ERROR,
(errcode(ERRCODE_CHECK_VIOLATION),
errmsg("updated partition constraint for default partition would be violated by some row")));
errmsg("updated partition constraint for default partition \"%s\" would be violated by some row",
RelationGetRelationName(oldrel))));
else
ereport(ERROR,
(errcode(ERRCODE_CHECK_VIOLATION),
errmsg("partition constraint is violated by some row")));
errmsg("partition constraint of relation \"%s\" is violated by some row",
RelationGetRelationName(oldrel))));
}
/* Write the tuple out to the new relation */
@ -10160,8 +10164,9 @@ validateCheckConstraint(Relation rel, HeapTuple constrtup)
if (!ExecCheck(exprstate, econtext))
ereport(ERROR,
(errcode(ERRCODE_CHECK_VIOLATION),
errmsg("check constraint \"%s\" is violated by some row",
NameStr(constrForm->conname)),
errmsg("check constraint \"%s\" of relation \"%s\" is violated by some row",
NameStr(constrForm->conname),
RelationGetRelationName(rel)),
errtableconstraint(rel, NameStr(constrForm->conname))));
ResetExprContext(econtext);

View File

@ -1957,8 +1957,9 @@ ExecConstraints(ResultRelInfo *resultRelInfo,
ereport(ERROR,
(errcode(ERRCODE_NOT_NULL_VIOLATION),
errmsg("null value in column \"%s\" violates not-null constraint",
NameStr(att->attname)),
errmsg("null value in column \"%s\" of relation \"%s\" violates not-null constraint",
NameStr(att->attname),
RelationGetRelationName(orig_rel)),
val_desc ? errdetail("Failing row contains %s.", val_desc) : 0,
errtablecol(orig_rel, attrChk)));
}

View File

@ -457,10 +457,10 @@ ALTER TABLE attmp3 validate constraint attmpconstr;
ALTER TABLE attmp3 validate constraint attmpconstr;
-- Try a non-verified CHECK constraint
ALTER TABLE attmp3 ADD CONSTRAINT b_greater_than_ten CHECK (b > 10); -- fail
ERROR: check constraint "b_greater_than_ten" is violated by some row
ERROR: check constraint "b_greater_than_ten" of relation "attmp3" is violated by some row
ALTER TABLE attmp3 ADD CONSTRAINT b_greater_than_ten CHECK (b > 10) NOT VALID; -- succeeds
ALTER TABLE attmp3 VALIDATE CONSTRAINT b_greater_than_ten; -- fails
ERROR: check constraint "b_greater_than_ten" is violated by some row
ERROR: check constraint "b_greater_than_ten" of relation "attmp3" is violated by some row
DELETE FROM attmp3 WHERE NOT b > 10;
ALTER TABLE attmp3 VALIDATE CONSTRAINT b_greater_than_ten; -- succeeds
ALTER TABLE attmp3 VALIDATE CONSTRAINT b_greater_than_ten; -- succeeds
@ -476,7 +476,7 @@ CREATE TABLE attmp7 () INHERITS (attmp3);
INSERT INTO attmp6 VALUES (6, 30), (7, 16);
ALTER TABLE attmp3 ADD CONSTRAINT b_le_20 CHECK (b <= 20) NOT VALID;
ALTER TABLE attmp3 VALIDATE CONSTRAINT b_le_20; -- fails
ERROR: check constraint "b_le_20" is violated by some row
ERROR: check constraint "b_le_20" of relation "attmp6" is violated by some row
DELETE FROM attmp6 WHERE b > 20;
ALTER TABLE attmp3 VALIDATE CONSTRAINT b_le_20; -- succeeds
-- An already validated constraint must not be revalidated
@ -497,7 +497,7 @@ insert into child_noinh_convalid values (1);
alter table parent_noinh_convalid add constraint check_a_is_2 check (a = 2) no inherit not valid;
-- fail, because of the row in parent
alter table parent_noinh_convalid validate constraint check_a_is_2;
ERROR: check constraint "check_a_is_2" is violated by some row
ERROR: check constraint "check_a_is_2" of relation "parent_noinh_convalid" is violated by some row
delete from only parent_noinh_convalid;
-- ok (parent itself contains no violating rows)
alter table parent_noinh_convalid validate constraint check_a_is_2;
@ -754,7 +754,7 @@ create table atacc1 ( test int );
insert into atacc1 (test) values (2);
-- add a check constraint (fails)
alter table atacc1 add constraint atacc_test1 check (test>3);
ERROR: check constraint "atacc_test1" is violated by some row
ERROR: check constraint "atacc_test1" of relation "atacc1" is violated by some row
insert into atacc1 (test) values (4);
drop table atacc1;
-- let's do one where the check fails because the column doesn't exist
@ -867,7 +867,7 @@ DETAIL: Failing row contains (-3).
insert into atacc1 (test) values (3);
-- fail, violating row:
alter table atacc2 add constraint foo check (test>0) no inherit;
ERROR: check constraint "foo" is violated by some row
ERROR: check constraint "foo" of relation "atacc2" is violated by some row
drop table atacc2;
drop table atacc1;
-- test unique constraint adding
@ -943,7 +943,7 @@ DETAIL: Key (test)=(2) already exists.
insert into atacc1 (test) values (4);
-- inserting NULL should fail
insert into atacc1 (test) values(NULL);
ERROR: null value in column "test" violates not-null constraint
ERROR: null value in column "test" of relation "atacc1" violates not-null constraint
DETAIL: Failing row contains (4, null).
-- try adding a second primary key (should fail)
alter table atacc1 add constraint atacc_oid1 primary key(id);
@ -970,7 +970,7 @@ create table atacc1 ( test int );
insert into atacc1 (test) values (NULL);
-- add a primary key (fails)
alter table atacc1 add constraint atacc_test1 primary key (test);
ERROR: column "test" contains null values
ERROR: column "test" of relation "atacc1" contains null values
insert into atacc1 (test) values (3);
drop table atacc1;
-- let's do one where the primary key constraint fails
@ -986,7 +986,7 @@ create table atacc1 ( test int );
insert into atacc1 (test) values (0);
-- add a primary key column without a default (fails).
alter table atacc1 add column test2 int primary key;
ERROR: column "test2" contains null values
ERROR: column "test2" of relation "atacc1" contains null values
-- now add a primary key column with a default (succeeds).
alter table atacc1 add column test2 int default 0 primary key;
drop table atacc1;
@ -1011,13 +1011,13 @@ insert into atacc1 (test,test2) values (4,4);
ERROR: duplicate key value violates unique constraint "atacc_test1"
DETAIL: Key (test, test2)=(4, 4) already exists.
insert into atacc1 (test,test2) values (NULL,3);
ERROR: null value in column "test" violates not-null constraint
ERROR: null value in column "test" of relation "atacc1" violates not-null constraint
DETAIL: Failing row contains (null, 3).
insert into atacc1 (test,test2) values (3, NULL);
ERROR: null value in column "test2" violates not-null constraint
ERROR: null value in column "test2" of relation "atacc1" violates not-null constraint
DETAIL: Failing row contains (3, null).
insert into atacc1 (test,test2) values (NULL,NULL);
ERROR: null value in column "test" violates not-null constraint
ERROR: null value in column "test" of relation "atacc1" violates not-null constraint
DETAIL: Failing row contains (null, null).
-- should all succeed
insert into atacc1 (test,test2) values (4,5);
@ -1032,7 +1032,7 @@ insert into atacc1 (test2, test) values (2, 3);
ERROR: duplicate key value violates unique constraint "atacc1_pkey"
DETAIL: Key (test)=(3) already exists.
insert into atacc1 (test2, test) values (1, NULL);
ERROR: null value in column "test" violates not-null constraint
ERROR: null value in column "test" of relation "atacc1" violates not-null constraint
DETAIL: Failing row contains (null, 1).
drop table atacc1;
-- alter table / alter column [set/drop] not null tests
@ -1056,7 +1056,7 @@ alter table atacc1 drop constraint "atacc1_pkey";
alter table atacc1 alter column test drop not null;
insert into atacc1 values (null);
alter table atacc1 alter test set not null;
ERROR: column "test" contains null values
ERROR: column "test" of relation "atacc1" contains null values
delete from atacc1;
alter table atacc1 alter test set not null;
-- try altering a non-existent column, should fail
@ -1078,12 +1078,12 @@ insert into atacc1 values (null, 1);
-- constraint not cover all values, should fail
alter table atacc1 add constraint atacc1_constr_or check(test_a is not null or test_b < 10);
alter table atacc1 alter test_a set not null;
ERROR: column "test_a" contains null values
ERROR: column "test_a" of relation "atacc1" contains null values
alter table atacc1 drop constraint atacc1_constr_or;
-- not valid constraint, should fail
alter table atacc1 add constraint atacc1_constr_invalid check(test_a is not null) not valid;
alter table atacc1 alter test_a set not null;
ERROR: column "test_a" contains null values
ERROR: column "test_a" of relation "atacc1" contains null values
alter table atacc1 drop constraint atacc1_constr_invalid;
-- with valid constraint
update atacc1 set test_a = 1;
@ -1095,10 +1095,10 @@ alter table atacc1 alter test_a drop not null;
-- test multiple set not null at same time
-- test_a checked by atacc1_constr_a_valid, test_b should fail by table scan
alter table atacc1 alter test_a set not null, alter test_b set not null;
ERROR: column "test_b" contains null values
ERROR: column "test_b" of relation "atacc1" contains null values
-- commands order has no importance
alter table atacc1 alter test_b set not null, alter test_a set not null;
ERROR: column "test_b" contains null values
ERROR: column "test_b" of relation "atacc1" contains null values
-- valid one by table scan, one by check constraints
update atacc1 set test_b = 1;
alter table atacc1 alter test_b set not null, alter test_a set not null;
@ -1112,31 +1112,31 @@ create table parent (a int);
create table child (b varchar(255)) inherits (parent);
alter table parent alter a set not null;
insert into parent values (NULL);
ERROR: null value in column "a" violates not-null constraint
ERROR: null value in column "a" of relation "parent" violates not-null constraint
DETAIL: Failing row contains (null).
insert into child (a, b) values (NULL, 'foo');
ERROR: null value in column "a" violates not-null constraint
ERROR: null value in column "a" of relation "child" violates not-null constraint
DETAIL: Failing row contains (null, foo).
alter table parent alter a drop not null;
insert into parent values (NULL);
insert into child (a, b) values (NULL, 'foo');
alter table only parent alter a set not null;
ERROR: column "a" contains null values
ERROR: column "a" of relation "parent" contains null values
alter table child alter a set not null;
ERROR: column "a" contains null values
ERROR: column "a" of relation "child" contains null values
delete from parent;
alter table only parent alter a set not null;
insert into parent values (NULL);
ERROR: null value in column "a" violates not-null constraint
ERROR: null value in column "a" of relation "parent" violates not-null constraint
DETAIL: Failing row contains (null).
alter table child alter a set not null;
insert into child (a, b) values (NULL, 'foo');
ERROR: null value in column "a" violates not-null constraint
ERROR: null value in column "a" of relation "child" violates not-null constraint
DETAIL: Failing row contains (null, foo).
delete from child;
alter table child alter a set not null;
insert into child (a, b) values (NULL, 'foo');
ERROR: null value in column "a" violates not-null constraint
ERROR: null value in column "a" of relation "child" violates not-null constraint
DETAIL: Failing row contains (null, foo).
drop table child;
drop table parent;
@ -1474,7 +1474,7 @@ insert into atacc1(value) values (100);
ERROR: new row for relation "atacc1" violates check constraint "atacc1_value_check"
DETAIL: Failing row contains (2, 100).
insert into atacc1(id, value) values (null, 0);
ERROR: null value in column "id" violates not-null constraint
ERROR: null value in column "id" of relation "atacc1" violates not-null constraint
DETAIL: Failing row contains (null, 0).
drop table atacc1;
-- test inheritance
@ -3804,7 +3804,7 @@ CREATE TABLE list_parted2 (
CREATE TABLE part_2 (LIKE list_parted2);
INSERT INTO part_2 VALUES (3, 'a');
ALTER TABLE list_parted2 ATTACH PARTITION part_2 FOR VALUES IN (2);
ERROR: partition constraint is violated by some row
ERROR: partition constraint of relation "part_2" is violated by some row
-- should be ok after deleting the bad row
DELETE FROM part_2;
ALTER TABLE list_parted2 ATTACH PARTITION part_2 FOR VALUES IN (2);
@ -3813,7 +3813,7 @@ CREATE TABLE list_parted2_def PARTITION OF list_parted2 DEFAULT;
INSERT INTO list_parted2_def VALUES (11, 'z');
CREATE TABLE part_3 (LIKE list_parted2);
ALTER TABLE list_parted2 ATTACH PARTITION part_3 FOR VALUES IN (11);
ERROR: updated partition constraint for default partition would be violated by some row
ERROR: updated partition constraint for default partition "list_parted2_def" would be violated by some row
-- should be ok after deleting the bad row
DELETE FROM list_parted2_def WHERE a = 11;
ALTER TABLE list_parted2 ATTACH PARTITION part_3 FOR VALUES IN (11);
@ -3847,7 +3847,7 @@ CREATE TABLE part1 (
INSERT INTO part1 VALUES (1, 10);
-- Remember the TO bound is exclusive
ALTER TABLE range_parted ATTACH PARTITION part1 FOR VALUES FROM (1, 1) TO (1, 10);
ERROR: partition constraint is violated by some row
ERROR: partition constraint of relation "part1" is violated by some row
-- should be ok after deleting the bad row
DELETE FROM part1;
ALTER TABLE range_parted ATTACH PARTITION part1 FOR VALUES FROM (1, 1) TO (1, 10);
@ -3868,7 +3868,7 @@ ERROR: partition "partr_def2" conflicts with existing default partition "partr_
INSERT INTO partr_def1 VALUES (2, 10);
CREATE TABLE part3 (LIKE range_parted);
ALTER TABLE range_parted ATTACH partition part3 FOR VALUES FROM (2, 10) TO (2, 20);
ERROR: updated partition constraint for default partition would be violated by some row
ERROR: updated partition constraint for default partition "partr_def1" would be violated by some row
-- Attaching partitions should be successful when there are no overlapping rows
ALTER TABLE range_parted ATTACH partition part3 FOR VALUES FROM (3, 10) TO (3, 20);
-- check that leaf partitions are scanned when attaching a partitioned
@ -3880,7 +3880,7 @@ CREATE TABLE part_5 (
CREATE TABLE part_5_a PARTITION OF part_5 FOR VALUES IN ('a');
INSERT INTO part_5_a (a, b) VALUES (6, 'a');
ALTER TABLE list_parted2 ATTACH PARTITION part_5 FOR VALUES IN (5);
ERROR: partition constraint is violated by some row
ERROR: partition constraint of relation "part_5_a" is violated by some row
-- delete the faulting row and also add a constraint to skip the scan
DELETE FROM part_5_a WHERE a NOT IN (3);
ALTER TABLE part_5 ADD CONSTRAINT check_a CHECK (a IS NOT NULL AND a = 5);
@ -3931,7 +3931,7 @@ SELECT tableoid::regclass, a, b FROM part_7 order by a;
(2 rows)
ALTER TABLE list_parted2 ATTACH PARTITION part_7 FOR VALUES IN (7);
ERROR: partition constraint is violated by some row
ERROR: partition constraint of relation "part_7_a_null" is violated by some row
-- check that leaf partitions of default partition are scanned when
-- attaching a partitioned table.
ALTER TABLE part_5 DROP CONSTRAINT check_a;
@ -3940,7 +3940,7 @@ CREATE TABLE part5_def_p1 PARTITION OF part5_def FOR VALUES IN (5);
INSERT INTO part5_def_p1 VALUES (5, 'y');
CREATE TABLE part5_p1 (LIKE part_5);
ALTER TABLE part_5 ATTACH PARTITION part5_p1 FOR VALUES IN ('y');
ERROR: updated partition constraint for default partition would be violated by some row
ERROR: updated partition constraint for default partition "part5_def_p1" would be violated by some row
-- should be ok after deleting the bad row
DELETE FROM part5_def_p1 WHERE b = 'y';
ALTER TABLE part_5 ATTACH PARTITION part5_p1 FOR VALUES IN ('y');
@ -3992,7 +3992,7 @@ DROP TABLE fail_part;
CREATE TABLE hpart_2 (LIKE hash_parted);
INSERT INTO hpart_2 VALUES (3, 0);
ALTER TABLE hash_parted ATTACH PARTITION hpart_2 FOR VALUES WITH (MODULUS 4, REMAINDER 1);
ERROR: partition constraint is violated by some row
ERROR: partition constraint of relation "hpart_2" is violated by some row
-- should be ok after deleting the bad row
DELETE FROM hpart_2;
ALTER TABLE hash_parted ATTACH PARTITION hpart_2 FOR VALUES WITH (MODULUS 4, REMAINDER 1);
@ -4005,7 +4005,7 @@ CREATE TABLE hpart_5 (
CREATE TABLE hpart_5_a PARTITION OF hpart_5 FOR VALUES IN ('1', '2', '3');
INSERT INTO hpart_5_a (a, b) VALUES (7, 1);
ALTER TABLE hash_parted ATTACH PARTITION hpart_5 FOR VALUES WITH (MODULUS 4, REMAINDER 2);
ERROR: partition constraint is violated by some row
ERROR: partition constraint of relation "hpart_5_a" is violated by some row
-- should be ok after deleting the bad row
DELETE FROM hpart_5_a;
ALTER TABLE hash_parted ATTACH PARTITION hpart_5 FOR VALUES WITH (MODULUS 4, REMAINDER 2);
@ -4172,7 +4172,7 @@ alter table p1 attach partition p11 for values from (2) to (5);
insert into p1 (a, b) values (2, 3);
-- check that partition validation scan correctly detects violating rows
alter table p attach partition p1 for values from (1, 2) to (1, 10);
ERROR: partition constraint is violated by some row
ERROR: partition constraint of relation "p11" is violated by some row
-- cleanup
drop table p;
drop table p1;
@ -4200,7 +4200,7 @@ insert into defpart_attach_test_d values (1), (2);
-- error because its constraint as the default partition would be violated
-- by the row containing 1
alter table defpart_attach_test attach partition defpart_attach_test_d default;
ERROR: partition constraint is violated by some row
ERROR: partition constraint of relation "defpart_attach_test_d" is violated by some row
delete from defpart_attach_test_d where a = 1;
alter table defpart_attach_test_d add check (a > 1);
-- should be attached successfully and without needing to be scanned
@ -4210,7 +4210,7 @@ alter table defpart_attach_test attach partition defpart_attach_test_d default;
-- successfully
create table defpart_attach_test_2 (like defpart_attach_test_d);
alter table defpart_attach_test attach partition defpart_attach_test_2 for values in (2);
ERROR: updated partition constraint for default partition would be violated by some row
ERROR: updated partition constraint for default partition "defpart_attach_test_d" would be violated by some row
drop table defpart_attach_test;
-- check combinations of temporary and permanent relations when attaching
-- partitions.

View File

@ -440,7 +440,7 @@ SELECT c, d FROM forcetest WHERE a = 2;
-- should fail with not-null constraint violation
BEGIN;
COPY forcetest (a, b, c) FROM STDIN WITH (FORMAT csv, FORCE_NULL(b), FORCE_NOT_NULL(c));
ERROR: null value in column "b" violates not-null constraint
ERROR: null value in column "b" of relation "forcetest" violates not-null constraint
DETAIL: Failing row contains (3, null, , null, null).
CONTEXT: COPY forcetest, line 1: "3,,"""
ROLLBACK;

View File

@ -955,7 +955,7 @@ CREATE TABLE part_c_1_10 PARTITION OF part_c FOR VALUES FROM (1) TO (10);
create table parted_notnull_inh_test (a int default 1, b int not null default 0) partition by list (a);
create table parted_notnull_inh_test1 partition of parted_notnull_inh_test (a not null, b default 1) for values in (1);
insert into parted_notnull_inh_test (b) values (null);
ERROR: null value in column "b" violates not-null constraint
ERROR: null value in column "b" of relation "parted_notnull_inh_test1" violates not-null constraint
DETAIL: Failing row contains (1, null).
-- note that while b's default is overriden, a's default is preserved
\d parted_notnull_inh_test1

View File

@ -90,7 +90,7 @@ CREATE TABLE test_like_id_2 (LIKE test_like_id_1);
b | text | | |
INSERT INTO test_like_id_2 (b) VALUES ('b2');
ERROR: null value in column "a" violates not-null constraint
ERROR: null value in column "a" of relation "test_like_id_2" violates not-null constraint
DETAIL: Failing row contains (null, b2).
SELECT * FROM test_like_id_2; -- identity was not copied
a | b

View File

@ -542,12 +542,12 @@ ERROR: domain dnotnull does not allow null values
INSERT INTO nulltest values ('a', NULL, 'c', 'd', 'c');
ERROR: domain dnotnull does not allow null values
INSERT INTO nulltest values ('a', 'b', NULL, 'd', 'c');
ERROR: null value in column "col3" violates not-null constraint
ERROR: null value in column "col3" of relation "nulltest" violates not-null constraint
DETAIL: Failing row contains (a, b, null, d, c).
INSERT INTO nulltest values ('a', 'b', 'c', NULL, 'd'); -- Good
-- Test copy
COPY nulltest FROM stdin; --fail
ERROR: null value in column "col3" violates not-null constraint
ERROR: null value in column "col3" of relation "nulltest" violates not-null constraint
DETAIL: Failing row contains (a, b, null, d, d).
CONTEXT: COPY nulltest, line 1: "a b \N d d"
COPY nulltest FROM stdin; --fail
@ -601,14 +601,14 @@ create table defaulttest
, col8 ddef5
);
insert into defaulttest(col4) values(0); -- fails, col5 defaults to null
ERROR: null value in column "col5" violates not-null constraint
ERROR: null value in column "col5" of relation "defaulttest" violates not-null constraint
DETAIL: Failing row contains (3, 12, 5, 0, null, 88, 8000, 12.12).
alter table defaulttest alter column col5 drop default;
insert into defaulttest default values; -- succeeds, inserts domain default
-- We used to treat SET DEFAULT NULL as equivalent to DROP DEFAULT; wrong
alter table defaulttest alter column col5 set default null;
insert into defaulttest(col4) values(0); -- fails
ERROR: null value in column "col5" violates not-null constraint
ERROR: null value in column "col5" of relation "defaulttest" violates not-null constraint
DETAIL: Failing row contains (3, 12, 5, 0, null, 88, 8000, 12.12).
alter table defaulttest alter column col5 drop default;
insert into defaulttest default values;

View File

@ -406,24 +406,24 @@ CREATE TABLE gtest20a (a int PRIMARY KEY, b int GENERATED ALWAYS AS (a * 2) STOR
INSERT INTO gtest20a (a) VALUES (10);
INSERT INTO gtest20a (a) VALUES (30);
ALTER TABLE gtest20a ADD CHECK (b < 50); -- fails on existing row
ERROR: check constraint "gtest20a_b_check" is violated by some row
ERROR: check constraint "gtest20a_b_check" of relation "gtest20a" is violated by some row
CREATE TABLE gtest20b (a int PRIMARY KEY, b int GENERATED ALWAYS AS (a * 2) STORED);
INSERT INTO gtest20b (a) VALUES (10);
INSERT INTO gtest20b (a) VALUES (30);
ALTER TABLE gtest20b ADD CONSTRAINT chk CHECK (b < 50) NOT VALID;
ALTER TABLE gtest20b VALIDATE CONSTRAINT chk; -- fails on existing row
ERROR: check constraint "chk" is violated by some row
ERROR: check constraint "chk" of relation "gtest20b" is violated by some row
-- not-null constraints
CREATE TABLE gtest21a (a int PRIMARY KEY, b int GENERATED ALWAYS AS (nullif(a, 0)) STORED NOT NULL);
INSERT INTO gtest21a (a) VALUES (1); -- ok
INSERT INTO gtest21a (a) VALUES (0); -- violates constraint
ERROR: null value in column "b" violates not-null constraint
ERROR: null value in column "b" of relation "gtest21a" violates not-null constraint
DETAIL: Failing row contains (0, null).
CREATE TABLE gtest21b (a int PRIMARY KEY, b int GENERATED ALWAYS AS (nullif(a, 0)) STORED);
ALTER TABLE gtest21b ALTER COLUMN b SET NOT NULL;
INSERT INTO gtest21b (a) VALUES (1); -- ok
INSERT INTO gtest21b (a) VALUES (0); -- violates constraint
ERROR: null value in column "b" violates not-null constraint
ERROR: null value in column "b" of relation "gtest21b" violates not-null constraint
DETAIL: Failing row contains (0, null).
ALTER TABLE gtest21b ALTER COLUMN b DROP NOT NULL;
INSERT INTO gtest21b (a) VALUES (0); -- ok now

View File

@ -186,7 +186,7 @@ ERROR: column "a" of relation "itest4" is not an identity column
ALTER TABLE itest4 ALTER COLUMN a DROP IDENTITY IF EXISTS; -- noop
NOTICE: column "a" of relation "itest4" is not an identity column, skipping
INSERT INTO itest4 DEFAULT VALUES; -- fails because NOT NULL is not dropped
ERROR: null value in column "a" violates not-null constraint
ERROR: null value in column "a" of relation "itest4" violates not-null constraint
DETAIL: Failing row contains (null, ).
ALTER TABLE itest4 ALTER COLUMN a DROP NOT NULL;
INSERT INTO itest4 DEFAULT VALUES;
@ -414,7 +414,7 @@ INSERT INTO itest8 VALUES(0), (1);
ALTER TABLE itest8
ADD COLUMN f22 int NOT NULL,
ALTER COLUMN f22 ADD GENERATED ALWAYS AS IDENTITY;
ERROR: column "f22" contains null values
ERROR: column "f22" of relation "itest8" contains null values
TABLE itest8;
f1 | f2 | f3 | f4 | f5
----+----+----+----+----

View File

@ -124,7 +124,7 @@ INSERT INTO tbl SELECT 1, 2, 3*x, box('4,4,4,4') FROM generate_series(1,10) AS x
ERROR: duplicate key value violates unique constraint "covering"
DETAIL: Key (c1, c2)=(1, 2) already exists.
INSERT INTO tbl SELECT 1, NULL, 3*x, box('4,4,4,4') FROM generate_series(1,10) AS x;
ERROR: null value in column "c2" violates not-null constraint
ERROR: null value in column "c2" of relation "tbl" violates not-null constraint
DETAIL: Failing row contains (1, null, 3, (4,4),(4,4)).
INSERT INTO tbl SELECT x, 2*x, NULL, NULL FROM generate_series(1,300) AS x;
explain (costs off)
@ -202,7 +202,7 @@ INSERT INTO tbl SELECT 1, 2, 3*x, box('4,4,4,4') FROM generate_series(1,10) AS x
ERROR: duplicate key value violates unique constraint "tbl_pkey"
DETAIL: Key (c1, c2)=(1, 2) already exists.
INSERT INTO tbl SELECT 1, NULL, 3*x, box('4,4,4,4') FROM generate_series(1,10) AS x;
ERROR: null value in column "c2" violates not-null constraint
ERROR: null value in column "c2" of relation "tbl" violates not-null constraint
DETAIL: Failing row contains (1, null, 3, (4,4),(4,4)).
INSERT INTO tbl SELECT x, 2*x, NULL, NULL FROM generate_series(1,10) AS x;
DROP TABLE tbl;

View File

@ -537,7 +537,7 @@ SELECT relname, d.* FROM ONLY d, pg_class where d.tableoid = pg_class.oid;
-- Confirm PRIMARY KEY adds NOT NULL constraint to child table
CREATE TEMP TABLE z (b TEXT, PRIMARY KEY(aa, b)) inherits (a);
INSERT INTO z VALUES (NULL, 'text'); -- should fail
ERROR: null value in column "aa" violates not-null constraint
ERROR: null value in column "aa" of relation "z" violates not-null constraint
DETAIL: Failing row contains (null, text).
-- Check inherited UPDATE with all children excluded
create table some_tab (a int, b int);
@ -940,9 +940,9 @@ create table p2(f2 int);
create table c1(f3 int) inherits(p1,p2);
insert into c1 values(1,-1,2);
alter table p2 add constraint cc check (f2>0); -- fail
ERROR: check constraint "cc" is violated by some row
ERROR: check constraint "cc" of relation "c1" is violated by some row
alter table p2 add check (f2>0); -- check it without a name, too
ERROR: check constraint "p2_f2_check" is violated by some row
ERROR: check constraint "p2_f2_check" of relation "c1" is violated by some row
delete from c1;
insert into c1 values(1,1,2);
alter table p2 add check (f2>0);

View File

@ -3,7 +3,7 @@
--
create table inserttest (col1 int4, col2 int4 NOT NULL, col3 text default 'testing');
insert into inserttest (col1, col2, col3) values (DEFAULT, DEFAULT, DEFAULT);
ERROR: null value in column "col2" violates not-null constraint
ERROR: null value in column "col2" of relation "inserttest" violates not-null constraint
DETAIL: Failing row contains (null, null, testing).
insert into inserttest (col2, col3) values (3, DEFAULT);
insert into inserttest (col1, col2, col3) values (DEFAULT, 5, DEFAULT);

View File

@ -592,13 +592,13 @@ ERROR: duplicate key value violates unique constraint "t1_pkey"
UPDATE t1 SET c2 = 1; -- fail, but row not shown
ERROR: duplicate key value violates unique constraint "t1_pkey"
INSERT INTO t1 (c1, c2) VALUES (null, null); -- fail, but see columns being inserted
ERROR: null value in column "c1" violates not-null constraint
ERROR: null value in column "c1" of relation "t1" violates not-null constraint
DETAIL: Failing row contains (c1, c2) = (null, null).
INSERT INTO t1 (c3) VALUES (null); -- fail, but see columns being inserted or have SELECT
ERROR: null value in column "c1" violates not-null constraint
ERROR: null value in column "c1" of relation "t1" violates not-null constraint
DETAIL: Failing row contains (c1, c3) = (null, null).
INSERT INTO t1 (c1) VALUES (5); -- fail, but see columns being inserted or have SELECT
ERROR: null value in column "c2" violates not-null constraint
ERROR: null value in column "c2" of relation "t1" violates not-null constraint
DETAIL: Failing row contains (c1) = (5).
UPDATE t1 SET c3 = 10; -- fail, but see columns with SELECT rights, or being modified
ERROR: new row for relation "t1" violates check constraint "t1_c3_check"

View File

@ -100,7 +100,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass;
(1 row)
INSERT INTO reloptions_test VALUES (1, NULL), (NULL, NULL);
ERROR: null value in column "i" violates not-null constraint
ERROR: null value in column "i" of relation "reloptions_test" violates not-null constraint
DETAIL: Failing row contains (null, null).
VACUUM reloptions_test;
SELECT pg_relation_size('reloptions_test') > 0;
@ -125,7 +125,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass;
(1 row)
INSERT INTO reloptions_test VALUES (1, NULL), (NULL, NULL);
ERROR: null value in column "i" violates not-null constraint
ERROR: null value in column "i" of relation "reloptions_test" violates not-null constraint
DETAIL: Failing row contains (null, null).
VACUUM reloptions_test;
SELECT pg_relation_size('reloptions_test') = 0;

View File

@ -69,7 +69,7 @@ INSERT INTO serialTest1 VALUES ('foo');
INSERT INTO serialTest1 VALUES ('bar');
INSERT INTO serialTest1 VALUES ('force', 100);
INSERT INTO serialTest1 VALUES ('wrong', NULL);
ERROR: null value in column "f2" violates not-null constraint
ERROR: null value in column "f2" of relation "serialtest1" violates not-null constraint
DETAIL: Failing row contains (wrong, null).
SELECT * FROM serialTest1;
f1 | f2

View File

@ -164,7 +164,7 @@ VACUUM (INDEX_CLEANUP FALSE, FREEZE TRUE) vaccluster;
CREATE TABLE vac_truncate_test(i INT NOT NULL, j text)
WITH (vacuum_truncate=true, autovacuum_enabled=false);
INSERT INTO vac_truncate_test VALUES (1, NULL), (NULL, NULL);
ERROR: null value in column "i" violates not-null constraint
ERROR: null value in column "i" of relation "vac_truncate_test" violates not-null constraint
DETAIL: Failing row contains (null, null).
VACUUM (TRUNCATE FALSE) vac_truncate_test;
SELECT pg_relation_size('vac_truncate_test') > 0;

View File

@ -377,7 +377,7 @@ DETAIL: Key (i)=(1) already exists.
INSERT INTO PRIMARY_TBL VALUES (4, 'three');
INSERT INTO PRIMARY_TBL VALUES (5, 'one');
INSERT INTO PRIMARY_TBL (t) VALUES ('six');
ERROR: null value in column "i" violates not-null constraint
ERROR: null value in column "i" of relation "primary_tbl" violates not-null constraint
DETAIL: Failing row contains (null, six).
SELECT '' AS four, * FROM PRIMARY_TBL;
four | i | t
@ -397,7 +397,7 @@ INSERT INTO PRIMARY_TBL VALUES (1, 'three');
INSERT INTO PRIMARY_TBL VALUES (4, 'three');
INSERT INTO PRIMARY_TBL VALUES (5, 'one');
INSERT INTO PRIMARY_TBL (t) VALUES ('six');
ERROR: null value in column "i" violates not-null constraint
ERROR: null value in column "i" of relation "primary_tbl" violates not-null constraint
DETAIL: Failing row contains (null, six).
SELECT '' AS three, * FROM PRIMARY_TBL;
three | i | t