mirror of
https://github.com/timescale/timescaledb.git
synced 2025-04-20 13:53:19 +08:00
Block using rules with hypertables
This commit is contained in:
parent
37142e9094
commit
0c5c21b2e4
@ -839,6 +839,12 @@ table_has_replica_identity(Relation rel)
|
||||
return rel->rd_rel->relreplident != REPLICA_IDENTITY_DEFAULT;
|
||||
}
|
||||
|
||||
static bool inline
|
||||
table_has_rules(Relation rel)
|
||||
{
|
||||
return rel->rd_rules != NULL;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
hypertable_has_tuples(Oid table_relid, LOCKMODE lockmode)
|
||||
@ -1237,6 +1243,13 @@ hypertable_create(PG_FUNCTION_ARGS)
|
||||
errmsg("table \"%s\" has replica identity set", get_rel_name(table_relid)),
|
||||
errdetail("Logical replication is not supported on hypertables.")));
|
||||
|
||||
if (table_has_rules(rel))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("hypertables do not support rules"),
|
||||
errdetail("Table \"%s\" has attached rules, which do not work on hypertables.", get_rel_name(table_relid)),
|
||||
errhint("Remove the rules before calling create_hypertable")));
|
||||
|
||||
/*
|
||||
* Create the associated schema where chunks are stored, or, check
|
||||
* permissions if it already exists
|
||||
|
@ -1618,6 +1618,14 @@ process_altertable_end_subcmd(Hypertable *ht, Node *parsetree, ObjectAddress *ob
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("hypertables do not support logical replication")));
|
||||
case AT_EnableRule:
|
||||
case AT_EnableAlwaysRule:
|
||||
case AT_EnableReplicaRule:
|
||||
case AT_DisableRule:
|
||||
/* should never actually get here but just in case */
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("hypertables do not support rules")));
|
||||
break;
|
||||
case AT_SetRelOptions:
|
||||
case AT_ResetRelOptions:
|
||||
@ -1752,6 +1760,20 @@ process_create_trigger_start(Node *parsetree)
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
process_create_rule_start(Node *parsetree)
|
||||
{
|
||||
RuleStmt *stmt = (RuleStmt *) parsetree;
|
||||
|
||||
if (hypertable_relid(stmt->relation) == InvalidOid)
|
||||
return;
|
||||
|
||||
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("hypertables do not support rules")));
|
||||
}
|
||||
|
||||
static void
|
||||
process_create_trigger_end(Node *parsetree)
|
||||
{
|
||||
@ -1791,6 +1813,9 @@ process_ddl_command_start(ProcessUtilityArgs *args)
|
||||
case T_CreateTrigStmt:
|
||||
process_create_trigger_start(args->parsetree);
|
||||
break;
|
||||
case T_RuleStmt:
|
||||
process_create_rule_start(args->parsetree);
|
||||
break;
|
||||
case T_DropStmt:
|
||||
|
||||
/*
|
||||
|
@ -93,3 +93,29 @@ ERROR: table "Hypertable_1_replica_ident" has replica identity set
|
||||
ALTER TABLE "Hypertable_1" REPLICA IDENTITY FULL;
|
||||
ERROR: hypertables do not support logical replication
|
||||
\set ON_ERROR_STOP 1
|
||||
CREATE TABLE PUBLIC."Hypertable_1_rule" (
|
||||
time BIGINT NOT NULL,
|
||||
"Device_id" TEXT NOT NULL,
|
||||
temp_c int NOT NULL DEFAULT -1
|
||||
);
|
||||
CREATE RULE notify_me AS ON UPDATE TO "Hypertable_1_rule" DO ALSO NOTIFY "Hypertable_1_rule";
|
||||
\set ON_ERROR_STOP 0
|
||||
SELECT * FROM create_hypertable('"public"."Hypertable_1_rule"', 'time', chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'));
|
||||
ERROR: hypertables do not support rules
|
||||
\set ON_ERROR_STOP 1
|
||||
ALTER TABLE "Hypertable_1_rule" DISABLE RULE notify_me;
|
||||
\set ON_ERROR_STOP 0
|
||||
SELECT * FROM create_hypertable('"public"."Hypertable_1_rule"', 'time', chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'));
|
||||
ERROR: hypertables do not support rules
|
||||
\set ON_ERROR_STOP 1
|
||||
DROP RULE notify_me ON "Hypertable_1_rule";
|
||||
SELECT * FROM create_hypertable('"public"."Hypertable_1_rule"', 'time', chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'));
|
||||
create_hypertable
|
||||
-------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
\set ON_ERROR_STOP 0
|
||||
CREATE RULE notify_me AS ON UPDATE TO "Hypertable_1_rule" DO ALSO NOTIFY "Hypertable_1_rule";
|
||||
ERROR: hypertables do not support rules
|
||||
\set ON_ERROR_STOP 0
|
||||
|
@ -86,3 +86,28 @@ ALTER TABLE "Hypertable_1_replica_ident" REPLICA IDENTITY FULL;
|
||||
SELECT * FROM create_hypertable('"public"."Hypertable_1_replica_ident"', 'time', chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'));
|
||||
ALTER TABLE "Hypertable_1" REPLICA IDENTITY FULL;
|
||||
\set ON_ERROR_STOP 1
|
||||
|
||||
|
||||
CREATE TABLE PUBLIC."Hypertable_1_rule" (
|
||||
time BIGINT NOT NULL,
|
||||
"Device_id" TEXT NOT NULL,
|
||||
temp_c int NOT NULL DEFAULT -1
|
||||
);
|
||||
CREATE RULE notify_me AS ON UPDATE TO "Hypertable_1_rule" DO ALSO NOTIFY "Hypertable_1_rule";
|
||||
|
||||
\set ON_ERROR_STOP 0
|
||||
SELECT * FROM create_hypertable('"public"."Hypertable_1_rule"', 'time', chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'));
|
||||
\set ON_ERROR_STOP 1
|
||||
|
||||
ALTER TABLE "Hypertable_1_rule" DISABLE RULE notify_me;
|
||||
|
||||
\set ON_ERROR_STOP 0
|
||||
SELECT * FROM create_hypertable('"public"."Hypertable_1_rule"', 'time', chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'));
|
||||
\set ON_ERROR_STOP 1
|
||||
|
||||
DROP RULE notify_me ON "Hypertable_1_rule";
|
||||
SELECT * FROM create_hypertable('"public"."Hypertable_1_rule"', 'time', chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'));
|
||||
|
||||
\set ON_ERROR_STOP 0
|
||||
CREATE RULE notify_me AS ON UPDATE TO "Hypertable_1_rule" DO ALSO NOTIFY "Hypertable_1_rule";
|
||||
\set ON_ERROR_STOP 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user