Skip to content

Commit

Permalink
Added check for TSQL dialect, changed hook name
Browse files Browse the repository at this point in the history
Task: BABEL-2170

Signed-off-by: Deepakshi Mittal <[email protected]>
  • Loading branch information
deepakshi-mittal committed Oct 9, 2023
1 parent df30c57 commit 0be4bf6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/backend/commands/trigger.c
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,12 @@ CreateTriggerFiringOn(CreateTrigStmt *stmt, const char *queryString,
RelationGetRelationName(rel)),
errdetail("Triggers on foreign tables cannot have transition tables.")));

if (rel->rd_rel->relkind == RELKIND_VIEW && sql_dialect != SQL_DIALECT_TSQL)
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("\"%s\" is a view",
RelationGetRelationName(rel)),
errdetail("Triggers on views cannot have transition tables.")));

/*
* We currently don't allow row-level triggers with transition
Expand Down
6 changes: 3 additions & 3 deletions src/backend/rewrite/rewriteHandler.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#include "utils/lsyscache.h"
#include "utils/rel.h"

ViewInsteadStmtTrigger_hook_type ViewInsteadStmtTrigger_hook = NULL;
bbfViewHasInsteadofTrigger_hook_type bbfViewHasInsteadofTrigger_hook = NULL; /** BBF Hook to check Instead Of trigger on View */

/* We use a list of these to detect recursion in RewriteQuery */
typedef struct rewrite_event
Expand Down Expand Up @@ -1475,7 +1475,7 @@ rewriteValuesRTE(Query *parsetree, RangeTblEntry *rte, int rti,
isAutoUpdatableView = false;
if (target_relation->rd_rel->relkind == RELKIND_VIEW &&
(!view_has_instead_trigger(target_relation, CMD_INSERT) &&
!(sql_dialect == SQL_DIALECT_TSQL && ViewInsteadStmtTrigger_hook && (ViewInsteadStmtTrigger_hook)(target_relation, CMD_INSERT))))
!(sql_dialect == SQL_DIALECT_TSQL && bbfViewHasInsteadofTrigger_hook && (bbfViewHasInsteadofTrigger_hook)(target_relation, CMD_INSERT))))
{
List *locks;
bool hasUpdate;
Expand Down Expand Up @@ -3957,7 +3957,7 @@ RewriteQuery(Query *parsetree, List *rewrite_events, int orig_rt_length)
if (!instead &&
rt_entry_relation->rd_rel->relkind == RELKIND_VIEW &&
(!view_has_instead_trigger(rt_entry_relation, event)
&& !(sql_dialect == SQL_DIALECT_TSQL && ViewInsteadStmtTrigger_hook && (ViewInsteadStmtTrigger_hook)(rt_entry_relation, event))))
&& !(sql_dialect == SQL_DIALECT_TSQL && bbfViewHasInsteadofTrigger_hook && (bbfViewHasInsteadofTrigger_hook)(rt_entry_relation, event))))
{
/*
* If there were any qualified INSTEAD rules, don't allow the view
Expand Down
4 changes: 2 additions & 2 deletions src/include/executor/executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ extern PGDLLIMPORT ExecutorCheckPerms_hook_type ExecutorCheckPerms_hook;
typedef bool (*TriggerRecuresiveCheck_hook_type) (ResultRelInfo *resultRelInfo);
extern PGDLLIMPORT TriggerRecuresiveCheck_hook_type TriggerRecuresiveCheck_hook;

typedef bool (*ViewInsteadStmtTrigger_hook_type) (Relation view, CmdType event);
extern PGDLLIMPORT ViewInsteadStmtTrigger_hook_type ViewInsteadStmtTrigger_hook;
typedef bool (*bbfViewHasInsteadofTrigger_hook_type) (Relation view, CmdType event);
extern PGDLLIMPORT bbfViewHasInsteadofTrigger_hook_type bbfViewHasInsteadofTrigger_hook;

typedef bool (*check_rowcount_hook_type) (int es_processed);
extern PGDLLIMPORT check_rowcount_hook_type check_rowcount_hook;
Expand Down

0 comments on commit 0be4bf6

Please sign in to comment.