diff --git a/contrib/babelfishpg_tsql/src/hooks.c b/contrib/babelfishpg_tsql/src/hooks.c index ed8674f3ad7..600f4018a0d 100644 --- a/contrib/babelfishpg_tsql/src/hooks.c +++ b/contrib/babelfishpg_tsql/src/hooks.c @@ -745,22 +745,16 @@ pltsql_bbfViewHasInsteadofTrigger(Relation view, CmdType event) Oid current_tgoid = trigger->tgoid; Oid prev_tgoid = InvalidOid; prev_tgoid = lfirst_oid(list_tail(triggerInvocationSequence)); - if (list_length(triggerInvocationSequence) > 32) + if (prev_tgoid == current_tgoid) { - ereport(ERROR, - (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32)"))); - } - else if (prev_tgoid == current_tgoid) - { - return false; /** A trigger called recursively by itself*/ + return false; /** Loop trigger call by itself*/ } - else if (list_member_oid(triggerInvocationSequence, current_tgoid)) + else if (list_length(triggerInvocationSequence) > TRIGGER_MAX_NEST_LEVEL || list_member_oid(triggerInvocationSequence, current_tgoid)) { - /** A trigger called recursively by another trigger */ + /** Loop trigger call by another trigger */ ereport(ERROR, - (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32)"))); + (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), + errmsg("Maximum stored procedure, function, trigger, or view nesting level exceeded (limit %d)", TRIGGER_MAX_NEST_LEVEL))); } } } diff --git a/contrib/babelfishpg_tsql/src/pltsql.h b/contrib/babelfishpg_tsql/src/pltsql.h index 12c83d807e6..700d7246778 100644 --- a/contrib/babelfishpg_tsql/src/pltsql.h +++ b/contrib/babelfishpg_tsql/src/pltsql.h @@ -62,6 +62,8 @@ /* Max number of Args allowed for Prepared stmts. */ #define PREPARE_STMT_MAX_ARGS 2100 +#define MAX_TRIGGER_NEST_LEVEL 32 /* Maximum allowed trigger nesting level*/ + /* * Compiler's namespace item types */