pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: swingi@gmail.com
To: pgsql-bugs@postgresql.org
Subject: BUG #13656: table inheritance, pg_dump emits same constraint for all inheritors causing errors
Date: Thu, 01 Oct 2015 10:17:33 +0000
Message-ID: <20151001101733.368.10010@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

The following bug has been logged on the website:

Bug reference:      13656
Logged by:          Ingmar Brouns
Email address:      swingi@gmail.com
PostgreSQL version: 9.4.4
Operating system:   fedora 21
Description:        


Hi,

I just noticed that when you add a not valid constraint to a table that is
inherited, this will result in pg_dump emitting an add constraint operation
for every table in the inheritance hierarchy. Therefore restoring a dump
will cause errors. Below is an example, first with a valid constraint (goes
well), and then the not valid constraint.


$ psql
psql (9.4.4)
Type "help" for help.

testdb=# create table foo ( a integer );
CREATE TABLE
testdb=# create table bar ( b integer) inherits (foo);
CREATE TABLE
testdb=# alter table foo add constraint foo_constraint check (true);
ALTER TABLE
testdb=# \q
$ pg_dump testdb > db.sql
$ dropdb testdb
$ createdb testdb
$ psql -d testdb -f db.sql
SET
SET
SET
SET
SET
SET
CREATE EXTENSION
COMMENT
SET
SET
SET
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
COPY 0
COPY 0
REVOKE
REVOKE
GRANT
GRANT


$ psql
psql (9.4.4)
Type "help" for help.

testdb=# alter table foo drop constraint foo_constraint;
ALTER TABLE
testdb=# alter table foo add constraint foo_constraint check (true) not
valid;
ALTER TABLE
testdb=# \q
$ pg_dump testdb > db.sql
$ dropdb testdb
$ createdb testdb
$ psql -d testdb -f db.sql
SET
SET
SET
SET
SET
SET
CREATE EXTENSION
COMMENT
SET
SET
SET
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
COPY 0
COPY 0
ALTER TABLE
psql:db.sql:84: ERROR:  constraint "foo_constraint" for relation "bar"
already exists
REVOKE
REVOKE
GRANT
GRANT


When looking in the dump file, you see that in the case that goes well the
constraint is part of the table definition

CREATE TABLE foo (
    a integer,
    CONSTRAINT foo_constraint CHECK (true)
);

However, for the not valid constraint, a separate ddl operation is there for
every table:


ALTER TABLE foo
    ADD CONSTRAINT foo_constraint CHECK (true) NOT VALID;


ALTER TABLE bar
    ADD CONSTRAINT foo_constraint CHECK (true) NOT VALID;


Regards,

Ingmar Brouns



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



view thread (4+ messages)  latest in thread

Message-ID: <20151001101733.368.10010@wrigleys.postgresql.org>
Permalink:  ../20151001101733.368.10010@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/20151001101733.368.10010@wrigleys.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: swingi@gmail.com
  Subject: Re: BUG #13656: table inheritance, pg_dump emits same constraint for all inheritors causing errors
  In-Reply-To: <20151001101733.368.10010@wrigleys.postgresql.org>
  References: <20151001101733.368.10010@wrigleys.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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