Commit e28b1156 authored by Robert Haas's avatar Robert Haas

Don't disallow dropping NOT NULL for a list partition key.

Range partitioning doesn't support nulls in the partitioning columns,
but list partitioning does.

Amit Langote, per a complaint from Amul Sul
parent 8d396a0a
...@@ -5593,6 +5593,9 @@ ATExecDropNotNull(Relation rel, const char *colName, LOCKMODE lockmode) ...@@ -5593,6 +5593,9 @@ ATExecDropNotNull(Relation rel, const char *colName, LOCKMODE lockmode)
if (rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE) if (rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
{ {
PartitionKey key = RelationGetPartitionKey(rel); PartitionKey key = RelationGetPartitionKey(rel);
if (get_partition_strategy(key) == PARTITION_STRATEGY_RANGE)
{
int partnatts = get_partition_natts(key), int partnatts = get_partition_natts(key),
i; i;
...@@ -5607,6 +5610,7 @@ ATExecDropNotNull(Relation rel, const char *colName, LOCKMODE lockmode) ...@@ -5607,6 +5610,7 @@ ATExecDropNotNull(Relation rel, const char *colName, LOCKMODE lockmode)
colName))); colName)));
} }
} }
}
/* /*
* Okay, actually perform the catalog change ... if needed * Okay, actually perform the catalog change ... if needed
......
...@@ -3029,6 +3029,10 @@ ERROR: cannot alter type of column referenced in partition key expression ...@@ -3029,6 +3029,10 @@ ERROR: cannot alter type of column referenced in partition key expression
-- cannot drop NOT NULL on columns in the range partition key -- cannot drop NOT NULL on columns in the range partition key
ALTER TABLE partitioned ALTER COLUMN a DROP NOT NULL; ALTER TABLE partitioned ALTER COLUMN a DROP NOT NULL;
ERROR: column "a" is in range partition key ERROR: column "a" is in range partition key
-- it's fine however to drop one on the list partition key column
CREATE TABLE list_partitioned (a int not null) partition by list (a);
ALTER TABLE list_partitioned ALTER a DROP NOT NULL;
DROP TABLE list_partitioned;
-- partitioned table cannot participate in regular inheritance -- partitioned table cannot participate in regular inheritance
CREATE TABLE foo ( CREATE TABLE foo (
a int, a int,
......
...@@ -1917,6 +1917,11 @@ ALTER TABLE partitioned ALTER COLUMN b TYPE char(5); ...@@ -1917,6 +1917,11 @@ ALTER TABLE partitioned ALTER COLUMN b TYPE char(5);
-- cannot drop NOT NULL on columns in the range partition key -- cannot drop NOT NULL on columns in the range partition key
ALTER TABLE partitioned ALTER COLUMN a DROP NOT NULL; ALTER TABLE partitioned ALTER COLUMN a DROP NOT NULL;
-- it's fine however to drop one on the list partition key column
CREATE TABLE list_partitioned (a int not null) partition by list (a);
ALTER TABLE list_partitioned ALTER a DROP NOT NULL;
DROP TABLE list_partitioned;
-- partitioned table cannot participate in regular inheritance -- partitioned table cannot participate in regular inheritance
CREATE TABLE foo ( CREATE TABLE foo (
a int, a int,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment