mirror of
https://github.com/postgres/postgres.git
synced 2025-11-22 12:22:45 +03:00
Disallow NULLS NOT DISTINCT indexes for primary keys
A unique index which is created with non-distinct NULLS cannot be used for backing a primary key constraint. Make sure to disallow such table alterations and teach pg_dump to drop the non-distinct NULLS clause on indexes where this has been set. Bug: 17720 Reported-by: Reiner Peterke <zedaardv@drizzle.com> Reviewed-by: Peter Eisentraut <peter.eisentraut@enterprisedb.com> Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://postgr.es/m/17720-dab8ee0fa85d316d@postgresql.org
This commit is contained in:
@@ -225,6 +225,19 @@ index_check_primary_key(Relation heapRel,
|
||||
RelationGetRelationName(heapRel))));
|
||||
}
|
||||
|
||||
/*
|
||||
* Indexes created with NULLS NOT DISTINCT cannot be used for primary key
|
||||
* constraints. While there is no direct syntax to reach here, it can be
|
||||
* done by creating a separate index and attaching it via ALTER TABLE ..
|
||||
* USING INDEX.
|
||||
*/
|
||||
if (indexInfo->ii_NullsNotDistinct)
|
||||
{
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_TABLE_DEFINITION),
|
||||
errmsg("primary keys cannot use NULLS NOT DISTINCT indexes")));
|
||||
}
|
||||
|
||||
/*
|
||||
* Check that all of the attributes in a primary key are marked as not
|
||||
* null. (We don't really expect to see that; it'd mean the parser messed
|
||||
|
||||
Reference in New Issue
Block a user