Query related to alter table ... attach partition

From: Ashutosh Sharma <ashu(dot)coek88(at)gmail(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Query related to alter table ... attach partition
Date: 2018-01-23 05:35:14
Message-ID: CAE9k0PnLN-q3upFeQO+ssLjNwLtqbPD-F6nRXaoUPR7OyHcaiw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi All,

I have created a regular table with CHECK constraint on the partition
key column and it conflicts with the partition constraint but, still,
i could attach the table with the partitioned table. Here is what i am
trying to do,

postgres[76308]=# create table part_tab (b int, a int) partition by range (a);
CREATE TABLE

postgres[76308]=# create table part1 (a int, b int CHECK (a >= 5));
CREATE TABLE

postgres[76308]=# alter table part_tab attach partition part1 for
values from (0) to (5); -- the partition constraint applied here
conflicts with CHECK (a >= 5) applied on part1.
ALTER TABLE

postgres[76308]=# \d+ part1;
Table "public.part1"
+--------+---------+-----------+----------+---------+---------+--------------+-------------+
| Column | Type | Collation | Nullable | Default | Storage | Stats
target | Description |
+--------+---------+-----------+----------+---------+---------+--------------+-------------+
| a | integer | | | | plain |
| |
| b | integer | | | | plain |
| |
+--------+---------+-----------+----------+---------+---------+--------------+-------------+
Partition of: part_tab FOR VALUES FROM (0) TO (5)
Partition constraint: ((a IS NOT NULL) AND (a >= 0) AND (a < 5))
Check constraints:
"part1_a_check" CHECK (a >= 5)
Options: storage_engine=zheap

As shown in the description of part1 (child table) above, Partition
constraint i.e. (a >= 0) AND (a < 5) and the CHECK constraint a >= 5
conflicts with each other but still alter table ... attach partition
succeeded. Isn't that a bug?

--
With Regards,
Ashutosh Sharma
EnterpriseDB:http://www.enterprisedb.com

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Masahiko Sawada 2018-01-23 05:35:42 Failed to request an autovacuum work-item in silence
Previous Message Jeff Davis 2018-01-23 05:08:06 Re: Rangejoin rebased