pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #14025: Unable to validate constraints
3+ messages / 3 participants
[nested] [flat]

* BUG #14025: Unable to validate constraints
@ 2016-03-16 15:08  jan.kort@genetics.nl
  0 siblings, 1 reply; 3+ messages in thread

From: jan.kort@genetics.nl @ 2016-03-16 15:08 UTC (permalink / raw)
  To: pgsql-bugs

The following bug has been logged on the website:

Bug reference:      14025
Logged by:          Jan
Email address:      jan.kort@genetics.nl
PostgreSQL version: 9.4.1
Operating system:   Windows 2012 Server
Description:        

When I do:
- disable trigger all
- incorrect foreign key reference
- enable trigger all
- validate
Then I get no error, I was expecting an error.

For example:

-- This succeeds (expected)
drop table if exists test1;
drop table if exists test2;
create table test2 (id int primary key);
create table test1 (id int primary key, test2_id int references test2(id));
insert into test2 (id) values (1);
insert into test1 (id, test2_id) values (1, 1);

-- This fails (expected)
drop table if exists test1;
drop table if exists test2;
create table test2 (id int primary key);
create table test1 (id int primary key, test2_id int references test2(id));
alter table test1 disable trigger user;
insert into test1 (id, test2_id) values (1, 1);
alter table test1 enable trigger user;

-- This succeeds (unexpected)
drop table if exists test1;
drop table if exists test2;
create table test2 (id int primary key);
create table test1 (id int primary key, test2_id int references test2(id));
alter table test1 disable trigger all;
insert into test1 (id, test2_id) values (1, 1);
alter table test1 enable trigger all;
alter table test1 validate constraint test1_test2_id_fkey;

Regards,

Jan




-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #14025: Unable to validate constraints
@ 2016-03-17 23:33  Tom Lane <tgl@sss.pgh.pa.us>
  parent: jan.kort@genetics.nl
  0 siblings, 1 reply; 3+ messages in thread

From: Tom Lane @ 2016-03-17 23:33 UTC (permalink / raw)
  To: jan.kort@genetics.nl; +Cc: pgsql-bugs

jan.kort@genetics.nl writes:
> When I do:
> - disable trigger all
> - incorrect foreign key reference
> - enable trigger all
> - validate
> Then I get no error, I was expecting an error.

AFAIK, disabling a foreign key trigger is not supported; if you do it,
we give absolutely zero guarantees about the subsequent behavior of the
foreign key.

ALTER TABLE VALIDATE CONSTRAINT is not meant to fix that.  It is meant
to finish up a foreign key addition started with
ALTER TABLE ... ADD FOREIGN KEY ... NOT VALID.

			regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #14025: Unable to validate constraints
@ 2016-03-18 01:02  David G. Johnston <david.g.johnston@gmail.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 3+ messages in thread

From: David G. Johnston @ 2016-03-18 01:02 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: jan.kort@genetics.nl <jan.kort@genetics.nl>; pgsql-bugs

On Thursday, March 17, 2016, Tom Lane <tgl@sss.pgh.pa.us> wrote:

> jan.kort@genetics.nl <javascript:;> writes:
> > When I do:
> > - disable trigger all
> > - incorrect foreign key reference
> > - enable trigger all
> > - validate
> > Then I get no error, I was expecting an error.
>
> AFAIK, disabling a foreign key trigger is not supported; if you do it,
> we give absolutely zero guarantees about the subsequent behavior of the
> foreign key.
>
> ALTER TABLE VALIDATE CONSTRAINT is not meant to fix that.  It is meant
> to finish up a foreign key addition started with
> ALTER TABLE ... ADD FOREIGN KEY ... NOT VALID.
>
> Documented in the relevant sections here.

 http://www.postgresql.org/docs/9.5/interactive/sql-altertable.html

We technically support disabling FK (an internal constraint) triggers but
it's intended usage is to bulk load known good data into tables without the
overhead of validation when you already known it is good.

The system as a rule only performs validation on data when newly inserting
it (under MVCC semantics).  The few instances of stated re-evaluation
operate on explicitly deferred constructs created using (in this case at
least) NOT VALID.  Once an FK has become valid it is never expected to
become invalid again.

While there isn't any particular reason we couldn't validate any named
constraint there is little incentive to make that particular change given
these operating assumptions.  And in the rare case you need the ability it
can usually be had in some other way.

David J.

^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2016-03-18 01:02 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-03-16 15:08 BUG #14025: Unable to validate constraints jan.kort@genetics.nl
2016-03-17 23:33 ` Tom Lane <tgl@sss.pgh.pa.us>
2016-03-18 01:02   ` David G. Johnston <david.g.johnston@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox