Block using rules with hypertables

This commit is contained in:
Matvey Arye 2018-07-24 14:19:19 -04:00 committed by Matvey Arye
parent 37142e9094
commit 0c5c21b2e4
4 changed files with 89 additions and 0 deletions

View File

@ -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

View File

@ -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:
/*

View File

@ -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

View File

@ -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