diff --git a/src/process_utility.c b/src/process_utility.c index 64ed55c07a7..cdbb206d074 100644 --- a/src/process_utility.c +++ b/src/process_utility.c @@ -143,7 +143,6 @@ check_chunk_alter_table_operation_allowed(Oid relid, AlterTableStmt *stmt) switch (cmd->subtype) { - case AT_AddConstraint: case AT_SetOptions: case AT_ResetOptions: case AT_SetRelOptions: @@ -162,6 +161,18 @@ check_chunk_alter_table_operation_allowed(Oid relid, AlterTableStmt *stmt) #endif /* allowed on chunks */ break; + case AT_AddConstraint: + { + /* if this is an OSM chunk, block the operation */ + Chunk *chunk = ts_chunk_get_by_relid(relid, false /* fail_if_not_found */); + if (chunk && chunk->fd.osm_chunk) + { + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("operation not supported on OSM chunk tables"))); + } + break; + } default: /* disable by default */ all_allowed = false; diff --git a/tsl/test/expected/chunk_utils_internal.out b/tsl/test/expected/chunk_utils_internal.out index d8232c16b4b..3e1d1b1aebe 100644 --- a/tsl/test/expected/chunk_utils_internal.out +++ b/tsl/test/expected/chunk_utils_internal.out @@ -1330,6 +1330,27 @@ SELECT * FROM test_chunkapp ORDER BY 1; Thu Jan 02 01:00:00 2020 PST | 2 (2 rows) +\set ON_ERROR_STOP 0 +-- test adding constraint directly on OSM chunk is blocked +ALTER TABLE test_chunkapp_fdw_child ADD CHECK (a > 0); -- non-dimensional +ERROR: operation not supported on OSM chunk tables +ALTER TABLE test_chunkapp_fdw_child ADD CHECK (time > '1600-01-01'::timestamptz); -- dimensional +ERROR: operation not supported on OSM chunk tables +-- but on hypertable, it is allowed +ALTER TABLE test_chunkapp ADD CHECK (a > 0); +\d+ test_chunkapp_fdw_child + Foreign table "public.test_chunkapp_fdw_child" + Column | Type | Collation | Nullable | Default | FDW options | Storage | Stats target | Description +--------+--------------------------+-----------+----------+---------+-------------+---------+--------------+------------- + time | timestamp with time zone | | not null | | | plain | | + a | integer | | | | | plain | | +Check constraints: + "test_chunkapp_a_check" CHECK (a > 0) +Server: s3_server +FDW options: (schema_name 'public', table_name 'test_chunkapp_fdw') +Inherits: test_chunkapp + +\set ON_ERROR_STOP 1 -- test error is triggered when time dimension not found CREATE TABLE test2(time timestamptz not null, a int); SELECT create_hypertable('test2', 'time'); diff --git a/tsl/test/sql/chunk_utils_internal.sql b/tsl/test/sql/chunk_utils_internal.sql index 69b8844e1a3..47918882af8 100644 --- a/tsl/test/sql/chunk_utils_internal.sql +++ b/tsl/test/sql/chunk_utils_internal.sql @@ -704,6 +704,15 @@ SELECT _timescaledb_functions.hypertable_osm_range_update('test_chunkapp', NULL: EXPLAIN SELECT * FROM test_chunkapp ORDER BY 1; SELECT * FROM test_chunkapp ORDER BY 1; +\set ON_ERROR_STOP 0 +-- test adding constraint directly on OSM chunk is blocked +ALTER TABLE test_chunkapp_fdw_child ADD CHECK (a > 0); -- non-dimensional +ALTER TABLE test_chunkapp_fdw_child ADD CHECK (time > '1600-01-01'::timestamptz); -- dimensional +-- but on hypertable, it is allowed +ALTER TABLE test_chunkapp ADD CHECK (a > 0); +\d+ test_chunkapp_fdw_child +\set ON_ERROR_STOP 1 + -- test error is triggered when time dimension not found CREATE TABLE test2(time timestamptz not null, a int); SELECT create_hypertable('test2', 'time');