mirror of
https://github.com/postgres/postgres.git
synced 2025-07-05 07:21:24 +03:00
Fix duplicate primary keys in partitions
When using the CREATE TABLE .. PARTITION OF syntax, it's possible to cause a partition to get two primary keys if the parent already has one. Tighten the check to disallow that. Reported-by: Rajkumar Raghuwanshi Author: Amul Sul Discussion: https://postgr.es/m/CAKcux6=OnSV3-qd8Gb6W=KPPwcCz6Fe_O_MQYjTa24__Xn8XxA@mail.gmail.com
This commit is contained in:
@ -218,12 +218,12 @@ index_check_primary_key(Relation heapRel,
|
||||
int i;
|
||||
|
||||
/*
|
||||
* If ALTER TABLE, check that there isn't already a PRIMARY KEY. In CREATE
|
||||
* TABLE, we have faith that the parser rejected multiple pkey clauses;
|
||||
* and CREATE INDEX doesn't have a way to say PRIMARY KEY, so it's no
|
||||
* problem either.
|
||||
* If ALTER TABLE and CREATE TABLE .. PARTITION OF, check that there isn't
|
||||
* already a PRIMARY KEY. In CREATE TABLE for an ordinary relations, we
|
||||
* have faith that the parser rejected multiple pkey clauses; and CREATE
|
||||
* INDEX doesn't have a way to say PRIMARY KEY, so it's no problem either.
|
||||
*/
|
||||
if (is_alter_table &&
|
||||
if ((is_alter_table || heapRel->rd_rel->relispartition) &&
|
||||
relationHasPrimaryKey(heapRel))
|
||||
{
|
||||
ereport(ERROR,
|
||||
|
Reference in New Issue
Block a user