diff --git a/contrib/babelfishpg_tsql/src/pl_handler.c b/contrib/babelfishpg_tsql/src/pl_handler.c index f56aac0eca..e957bec272 100644 --- a/contrib/babelfishpg_tsql/src/pl_handler.c +++ b/contrib/babelfishpg_tsql/src/pl_handler.c @@ -793,6 +793,29 @@ pltsql_post_parse_analyze(ParseState *pstate, Query *query, JumbleState *jstate) switch (nodeTag(parsetree)) { + case T_CreateFunctionStmt: + { + ListCell *option; + CreateTrigStmt *trigStmt; + Relation rel; + foreach (option, ((CreateFunctionStmt *) parsetree)->options){ + DefElem *defel = (DefElem *) lfirst(option); + if (strcmp(defel->defname, "trigStmt") == 0) + { + trigStmt = (CreateTrigStmt *) defel->arg; + rel = table_openrv(trigStmt->relation, ShareRowExclusiveLock); + if (rel->rd_islocaltemp){ + ereport(ERROR, + (errcode(ERRCODE_WRONG_OBJECT_TYPE), + errmsg("Cannot create trigger on a temporary object."), + "Cannot create trigger on a temporary object." + )); + } + table_close(rel, NoLock); + } + } + } + break; case T_CreateStmt: { CreateStmt *stmt = (CreateStmt *) parsetree; diff --git a/test/JDBC/expected/babel_trigger.out b/test/JDBC/expected/babel_trigger.out index 029a7255e6..01bc3ba21e 100644 --- a/test/JDBC/expected/babel_trigger.out +++ b/test/JDBC/expected/babel_trigger.out @@ -435,6 +435,23 @@ babel_trigger_trig2#!#babel_trigger_sch1 ~~END~~ +CREATE TABLE #babel_2177(id int) +go + +-- will fail and print error when trying to create trigger on temp table +CREATE TRIGGER trigger_babel_2177 ON #babel_2177 +AFTER INSERT +AS + INSERT into #babel_2177 VALUES (7) +go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Cannot create trigger on a temporary object.)~~ + + +drop table #babel_2177; +GO + -- clean up drop trigger babel_trigger_sch1.babel_trigger_trig1 GO diff --git a/test/JDBC/input/babel_trigger.sql b/test/JDBC/input/babel_trigger.sql index afab668bc6..3a7cbe6e04 100644 --- a/test/JDBC/input/babel_trigger.sql +++ b/test/JDBC/input/babel_trigger.sql @@ -343,6 +343,19 @@ GO select name,schema_name(schema_id) from sys.objects where name in ('babel_trigger_trig1','babel_trigger_trig2','babel_trigger_trig3','babel_trigger_trig4') order by name; GO +CREATE TABLE #babel_2177(id int) +go + +-- will fail and print error when trying to create trigger on temp table +CREATE TRIGGER trigger_babel_2177 ON #babel_2177 +AFTER INSERT +AS + INSERT into #babel_2177 VALUES (7) +go + +drop table #babel_2177; +GO + -- clean up drop trigger babel_trigger_sch1.babel_trigger_trig1 GO