Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1aeCcU-0007Qz-2T for pgsql-bugs@arkaria.postgresql.org; Fri, 11 Mar 2016 02:16:02 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aeCcT-00026k-Fp for pgsql-bugs@arkaria.postgresql.org; Fri, 11 Mar 2016 02:16:01 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ae6WG-0005Ml-48 for pgsql-bugs@postgresql.org; Thu, 10 Mar 2016 19:45:12 +0000 Received: from mail-qg0-x234.google.com ([2607:f8b0:400d:c04::234]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1ae6WC-00059A-OX for pgsql-bugs@postgresql.org; Thu, 10 Mar 2016 19:45:10 +0000 Received: by mail-qg0-x234.google.com with SMTP id t4so79837752qge.0 for ; Thu, 10 Mar 2016 11:45:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=commoninf-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:mime-version:thread-index :content-language; bh=LlUwkBQSxiAOO6DLLuNiaslurB6hRR2PdfruQv25rqw=; b=IF8/lnqNQyhiEUfNyd3uqYRp5SNg+13KQQAXzYLxzD1gSdxj5fpbByK+MLrjpdI0N5 viQSrXaHyDqa6XLahtgA7R5osjAOGnOHezKC+OZuoW8trqHPsDRdgveTsKnZjQUpwBf6 GnN+V3o2iKe6XhhLSbIfwHy+YPXagN8KsW0y3AjWOYxvZOyAJFtsn52N1sHRxkW57r/X /Pb6ZSkXVapuKOQzgDxMWcTUHM2y6HD2bDbxub2yKkeCSUPgwAWdN4OwP6wht0qG8htS T0u+kQ00OlNRXdh/S9IZKb8ikalVcgEnPvWM4ZKdH1oMikgd6jku5S7/RvkwDE3mq3+N LRIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :thread-index:content-language; bh=LlUwkBQSxiAOO6DLLuNiaslurB6hRR2PdfruQv25rqw=; b=BMgLd6B142rgE3W9IApvCec/sMoHM1dRozulLTETEWgbhDIvEZ3HzN8Y0tTLb5einz 3rDluYqnwAS5+qd5n5hLtArj52RXMDDaoiaFwocJOG5VCdAgX4jPXDCVtMYBx1syvVh7 IRdMWRtgEp+V8Zu1OXqR7skpcy8+lKOF8vMnXq+EWlK2hV/icbWaVUCKnIBxT3FvTxcR FfF2kTWrxBpxVVpZblutF7y/MlDp1tub0JArZR81jzDCPc6s2GVpwOMfvMzEvuPgpJvk ClojjldHuOg6jx1YwlTBR20UVCtnhhz900UQtY0dN7p01W8HmCciI4gEbcL1YeaCSTti c1Sw== X-Gm-Message-State: AD7BkJLslrxJBa9EDPe3u59UbMUNecltHp57JML1MiXyxaI7cHc5g48BNaFsOcn1WGt5+Q== X-Received: by 10.140.248.135 with SMTP id t129mr6824737qhc.53.1457639107246; Thu, 10 Mar 2016 11:45:07 -0800 (PST) Received: from rschaaf-PC ([50.245.58.42]) by smtp.gmail.com with ESMTPSA id h9sm2324262qhh.29.2016.03.10.11.45.06 for (version=TLSv1/SSLv3 cipher=OTHER); Thu, 10 Mar 2016 11:45:06 -0800 (PST) Received: from rschaafPC by rschaaf-PC (PGP Universal service); Thu, 10 Mar 2016 14:44:49 -0500 X-PGP-Universal: processed; by rschaaf-PC on Thu, 10 Mar 2016 14:44:49 -0500 From: "Rich Schaaf" To: Subject: Bad interaction between pg_dump/pg_restore and table inheritance Date: Thu, 10 Mar 2016 14:44:39 -0500 Message-ID: <011001d17b05$4e70c000$eb524000$@commoninf.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 14.0 Thread-Index: AdF7A0QQxb6SYGKeQaGQ2xRqEljnkg== Content-Type: multipart/alternative; boundary="----=_NextPart_000_0111_01D17ADB.659CB3D0" Content-Language: en-us X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org This is a multipart message in MIME format. ------=_NextPart_000_0111_01D17ADB.659CB3D0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit PostgreSQL Version: PostgreSQL 9.4.1, compiled by Visual C++ build 1800, 64-bit OS Version: Windows 7 Professional, SP 1 Short Description: Bad interaction between pg_dump/pg_restore and table inheritance Details: Using pg_dump/pg_restore can lead to changes in a constraint definition such that inheritance no longer works. The following steps (see below for SQL statements) may be followed to reproduce the problem. The basic idea is: 1. Create two tables (test_master and test_sub) that have the same column names/data types and the same check constraint definition. 2. Alter test_sub to inherit from test_master and verify that a SELECT on the test_master table works. 3. Use pg_dump to export the schema containing the two tables 4. Use pg_restore to restore the schema 5. Recreate the test_sub table 6. Attempt to alter test_sub to inherit from test_master. The ALTER statements fails with the following error; ERROR: child table "test_sub" has different definition for check constraint "yn_check" DROP SCHEMA IF EXISTS test_check CASCADE; CREATE SCHEMA test_check; CREATE TABLE test_check.test_master ( descript VARCHAR(10), yn VARCHAR(1), CONSTRAINT yn_check CHECK (yn IN ('Y', 'N'))); DROP TABLE IF EXISTS test_check.test_sub; CREATE TABLE test_check.test_sub ( descript VARCHAR(10), yn VARCHAR(1), CONSTRAINT yn_check CHECK (yn IN ('Y', 'N'))); INSERT INTO test_check.test_sub (descript, yn) VALUES ('descript1', 'Y'); ALTER TABLE test_check.test_sub INHERIT test_check.test_master; -- Verify the query returns the expected result of one row SELECT * FROM test_check.test_master; -- Export the test_check schema -- C:\Program Files (x86)\pgAdmin III\1.20\pg_dump.exe --host localhost --port 5432 --username "ldx" --no-password --format custom --verbose --file "C:\Temp\test_check.backup" --schema "test_check" "ldx" -- Rename the original schema ALTER SCHEMA test_check RENAME TO test_check_orig; -- Create a new schema named test_check CREATE SCHEMA test_check; -- Import the data from the backup file -- C:\Program Files (x86)\pgAdmin III\1.20\pg_restore.exe --host localhost --port 5432 --username "ldx" --dbname "ldx" --no-password --schema test_check --verbose "C:\Temp\test_check.backup" -- DROP the imported version of the test_sub table and recreate it DROP TABLE IF EXISTS test_check.test_sub; CREATE TABLE test_check.test_sub ( descript VARCHAR(10), yn VARCHAR(1), CONSTRAINT yn_check CHECK (yn IN ('Y', 'N'))); INSERT INTO test_check.test_sub (descript, yn) VALUES ('descript1', 'Y'); -- Attempt to set up the inherit relationship with test_master ALTER TABLE test_check.test_sub INHERIT test_check.test_master; -- The ALTER TABLE statement returns the following error -- ERROR: child table "test_sub" has different definition for check constraint "yn_check" -- SQL state: 42804 -- Here is the DDL for the original version ot the test_master table: CREATE TABLE test_check_orig.test_master ( descript character varying(10), yn character varying(1), CONSTRAINT yn_check CHECK (yn::text = ANY (ARRAY['Y'::character varying, 'N'::character varying]::text[])) ) -- Here is the DDL for the version of the table imported from a schema backup CREATE TABLE test_check.test_master ( descript character varying(10), yn character varying(1), CONSTRAINT yn_check CHECK (yn::text = ANY (ARRAY['Y'::character varying::text, 'N'::character varying::text])) ) Kind regards, Rich ------=_NextPart_000_0111_01D17ADB.659CB3D0 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

PostgreSQL = Version: PostgreSQL 9.4.1, compiled by Visual C++ build 1800, = 64-bit

OS Version: Windows 7 = Professional, SP 1

 

Short = Description:

Bad interaction between = pg_dump/pg_restore and table inheritance

 

Details:

Using = pg_dump/pg_restore can lead to changes in a constraint definition such = that inheritance no longer works.

 

The = following steps (see below for SQL statements) may be followed to = reproduce the problem.  The basic idea is:

1.       = Create two tables (test_master and test_sub) = that have the same column names/data types and the same check constraint = definition.

2.       = Alter test_sub to inherit from test_master and = verify that a SELECT on the test_master table works.

3.       Use = pg_dump to export the schema containing the two tables

4.       Use = pg_restore to restore the schema

5.       = Recreate the test_sub table

6.       = Attempt to alter test_sub to inherit from = test_master.  The ALTER statements fails with the following = error;
ERROR: child table "test_sub" has different = definition for check constraint "yn_check"

 

DROP SCHEMA IF = EXISTS test_check CASCADE;

CREATE SCHEMA test_check;

 

CREATE TABLE = test_check.test_master (

    = descript VARCHAR(10),

    = yn VARCHAR(1),

    = CONSTRAINT yn_check CHECK (yn IN ('Y', 'N')));

 

DROP TABLE IF EXISTS = test_check.test_sub;

CREATE TABLE = test_check.test_sub (

    = descript VARCHAR(10),

    = yn VARCHAR(1),

    = CONSTRAINT yn_check CHECK (yn IN ('Y', 'N')));

INSERT INTO test_check.test_sub (descript, yn) VALUES = ('descript1', 'Y');

 

ALTER TABLE = test_check.test_sub INHERIT = test_check.test_master;

 

-- Verify the query = returns the expected result of one row

SELECT * FROM test_check.test_master;

 

-- Export the = test_check schema

-- C:\Program Files = (x86)\pgAdmin III\1.20\pg_dump.exe --host localhost --port 5432 = --username "ldx" --no-password  --format custom --verbose = --file "C:\Temp\test_check.backup" --schema = "test_check" "ldx"

 

-- Rename the = original schema

ALTER SCHEMA = test_check RENAME TO test_check_orig;

 

-- Create a new = schema named test_check

CREATE SCHEMA = test_check;

 

-- Import the data = from the backup file

-- C:\Program Files = (x86)\pgAdmin III\1.20\pg_restore.exe --host localhost --port 5432 = --username "ldx" --dbname "ldx" --no-password  = --schema test_check --verbose = "C:\Temp\test_check.backup"

 

-- DROP the imported = version of the test_sub table and recreate it

DROP TABLE IF EXISTS test_check.test_sub;

CREATE TABLE test_check.test_sub (

    descript VARCHAR(10),

    yn VARCHAR(1),

    CONSTRAINT yn_check CHECK (yn IN ('Y', = 'N')));

INSERT INTO = test_check.test_sub (descript, yn) VALUES ('descript1', = 'Y');

 

-- Attempt to set up = the inherit relationship with test_master

ALTER TABLE test_check.test_sub INHERIT = test_check.test_master;

 

-- The ALTER TABLE = statement returns the following error

-- ERROR: child table "test_sub" has different = definition for check constraint = "yn_check"

-- SQL state: = 42804

 

-- Here is the DDL = for the original version ot the test_master = table:

CREATE TABLE = test_check_orig.test_master

(

  descript = character varying(10),

  yn character = varying(1),

  CONSTRAINT = yn_check CHECK (yn::text =3D ANY (ARRAY['Y'::character varying, = 'N'::character varying]::text[]))

)

  =

-- Here is the DDL = for the version of the table imported from a schema = backup

CREATE TABLE = test_check.test_master

(

  descript = character varying(10),

  yn character = varying(1),

  CONSTRAINT = yn_check CHECK (yn::text =3D ANY (ARRAY['Y'::character varying::text, = 'N'::character varying::text]))

)

 

Kind = regards,

Rich

 

------=_NextPart_000_0111_01D17ADB.659CB3D0--