diff --git a/src/process_utility.c b/src/process_utility.c index 4d979ee2b..be4bb4f72 100644 --- a/src/process_utility.c +++ b/src/process_utility.c @@ -2711,6 +2711,18 @@ process_index_start(ProcessUtilityArgs *args) /* Make the RangeVar for the underlying materialization hypertable */ stmt->relation = makeRangeVar(NameStr(ht->fd.schema_name), NameStr(ht->fd.table_name), -1); } + else if (TS_HYPERTABLE_HAS_COMPRESSION_ENABLED(ht)) + { + /* unique indexes are not allowed on compressed hypertables*/ + if (stmt->unique || stmt->primary || stmt->isconstraint) + { + ts_cache_release(hcache); + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("operation not supported on hypertables that have compression " + "enabled"))); + } + } ts_hypertable_permissions_check_by_id(ht->fd.id); add_hypertable_to_process_args(args, ht); diff --git a/tsl/test/expected/compression_ddl.out b/tsl/test/expected/compression_ddl.out index c5712da5a..49c9e2ab7 100644 --- a/tsl/test/expected/compression_ddl.out +++ b/tsl/test/expected/compression_ddl.out @@ -62,6 +62,13 @@ DROP INDEX new_index; ALTER TABLE test1 SET (fillfactor=100); ALTER TABLE test1 RESET (fillfactor); ALTER TABLE test1 ALTER COLUMN b SET STATISTICS 10; +-- make sure we cannot create constraints or unique indexes on compressed hypertables +\set ON_ERROR_STOP 0 +ALTER TABLE test1 ADD CONSTRAINT c1 UNIQUE(time,i); +ERROR: operation not supported on hypertables that have compression enabled +CREATE UNIQUE INDEX unique_index ON test1(time,i); +ERROR: operation not supported on hypertables that have compression enabled +\set ON_ERROR_STOP 1 --test adding boolean columns with default and not null CREATE TABLE records (time timestamp NOT NULL); SELECT create_hypertable('records', 'time'); diff --git a/tsl/test/sql/compression_ddl.sql b/tsl/test/sql/compression_ddl.sql index 1a4cd382b..8038973ea 100644 --- a/tsl/test/sql/compression_ddl.sql +++ b/tsl/test/sql/compression_ddl.sql @@ -42,6 +42,12 @@ ALTER TABLE test1 SET (fillfactor=100); ALTER TABLE test1 RESET (fillfactor); ALTER TABLE test1 ALTER COLUMN b SET STATISTICS 10; +-- make sure we cannot create constraints or unique indexes on compressed hypertables +\set ON_ERROR_STOP 0 +ALTER TABLE test1 ADD CONSTRAINT c1 UNIQUE(time,i); +CREATE UNIQUE INDEX unique_index ON test1(time,i); +\set ON_ERROR_STOP 1 + --test adding boolean columns with default and not null CREATE TABLE records (time timestamp NOT NULL); SELECT create_hypertable('records', 'time');