Skip to content

Commit 82a8d6e

Browse files
committed
Remove blocker for unique constraints with ADD COLUMN
Remove special handling for ADD COLUMN with unique/primary key constraints on compressed hypertables. This patch makes the behaviour consistent with uncompressed hypertable where ADD COLUMN with unique/ primary key constraint is blocked because those constraints require all partitioning columns to be included.
1 parent b29d578 commit 82a8d6e

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

.unreleased/pr_7877

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Implements: #7877 Remove blocker for unique constraints with ADD COLUMN

src/process_utility.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,14 @@ check_altertable_add_column_for_compressed(Hypertable *ht, ColumnDef *col)
327327
Constraint *constraint = lfirst_node(Constraint, lc);
328328
switch (constraint->contype)
329329
{
330+
/*
331+
* These will fail in combination with ADD COLUMN because this will
332+
* be a single column constraint and we require all partitioning
333+
* columns to be part if the unique/primary key constraint.
334+
*/
335+
case CONSTR_PRIMARY:
336+
case CONSTR_UNIQUE:
337+
break;
330338
/*
331339
* We can safelly ignore NULL constraints because it does nothing
332340
* and according to Postgres docs is useless and exist just for

tsl/test/expected/compression_errors.out

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,11 @@ alter table table_constr drop constraint table_constr_exclu ;
366366
ALTER TABLE table_constr set (timescaledb.compress, timescaledb.compress_orderby = 'timec', timescaledb.compress_segmentby = 'device_id, location, d');
367367
-- ddl ADD column variants that are not supported
368368
ALTER TABLE table_constr ADD COLUMN newcol integer UNIQUE;
369-
ERROR: cannot add column with constraints to a hypertable that has compression enabled
369+
ERROR: cannot create a unique index without the column "timec" (used in partitioning)
370+
HINT: If you're creating a hypertable on a table with a primary key, ensure the partitioning column is part of the primary or composite key.
370371
ALTER TABLE table_constr ADD COLUMN newcol integer PRIMARY KEY;
371-
ERROR: cannot add column with constraints to a hypertable that has compression enabled
372+
ERROR: cannot create a unique index without the column "timec" (used in partitioning)
373+
HINT: If you're creating a hypertable on a table with a primary key, ensure the partitioning column is part of the primary or composite key.
372374
ALTER TABLE table_constr ADD COLUMN newcol integer NOT NULL;
373375
ERROR: cannot add column with NOT NULL constraint without default to a hypertable that has compression enabled
374376
ALTER TABLE table_constr ADD COLUMN newcol integer DEFAULT random() + random();

0 commit comments

Comments
 (0)