Re: BUG #14629: ALTER TABLE VALIDATE CONSTRAINTS does not obey NO INHERIT clause

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>
Cc: Hans Buschmann <buschmann(at)nidsa(dot)net>, Postgres-Bugs <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #14629: ALTER TABLE VALIDATE CONSTRAINTS does not obey NO INHERIT clause
Date: 2017-04-28 19:00:28
Message-ID: CA+TgmoaxAE2axM=V3rwuEJDTc29ny2wyzu+5QpvRWHtOOj5z1w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

On Mon, Apr 24, 2017 at 12:16 AM, Amit Langote
<Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp> wrote:
> On 2017/04/22 3:40, buschmann(at)nidsa(dot)net wrote:
>> The following bug has been logged on the website:
>>
>> Bug reference: 14629
>> Logged by: Hans Buschmann
>> Email address: buschmann(at)nidsa(dot)net
>> PostgreSQL version: 9.6.2
>> Operating system: Windows x64
>> Description:
>>
>>
>> Given these both tables (orders_archiv inherits orders) on 9.6.2 Windows
>> x64
>> (cut/paste from psql)
>>
>> xxxdb=# \d orders_archiv;
>> ...
>> Check constraints:
>> "ck_or_old" CHECK (or_season < 24) NO INHERIT
>> Inherits: orders
>>
>>
>> xxxdb=# \d orders
>> ...
>> Check constraints:
>> "ck_or_new" CHECK (or_season >= 24) NO INHERIT NOT VALID
>> Triggers:
>> tr_orders_insert BEFORE INSERT ON orders FOR EACH ROW WHEN
>> (new.or_season < 24) EXECUTE PROCEDURE fn_orders_insert()
>> Number of child tables: 1 (Use \d+ to list them.)
>>
>>
>> When applying these commands to the parent table, the following errors are
>> returned:
>>
>> xxxdb=# alter table orders validate constraint ck_or_new;
>> ERROR: constraint "ck_or_new" of relation "orders_archiv" does not exist
>>
>>
>> xxxdb=# alter table only orders validate constraint ck_or_new;
>> ERROR: constraint must be validated on child tables too
>>
>> Background:
>> From our original partitioning of quite a lot of tables according to
>> xx_season columns (a season is a half year period) I dropped and recreated
>> the check constraintsin a not valid state.
>>
>> At the end of the script to move the data from 2 seasons into the archiv
>> tables I tried to reenable the check constraints and encountered those two
>> errors.
>>
>> It seems that I can circumvent these errors by recreating the constraints
>> without the not valid clause.
>>
>> Do I miss something here ?
>
> Looks indeed like a bug to me. Performing VALIDATE CONSTRAINT on what is
> a non-inheritable constraint shouldn't look for that constraint in the
> child tables. Attached patch fixes that. Should be applied in all of the
> supported branches.

Done.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Peter Eisentraut 2017-04-28 19:34:08 Re: typo in 9.6 release-note
Previous Message Tom Lane 2017-04-28 14:46:46 Re: No INSTALL file in git repo, inaccuracy in readme file

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2017-04-28 19:00:47 Re: [PROPOSAL] Use SnapshotAny in get_actual_variable_range
Previous Message Robert Haas 2017-04-28 18:55:27 Re: identity columns