diff options
Diffstat (limited to 'src/backend/commands/tablecmds.c')
-rw-r--r-- | src/backend/commands/tablecmds.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 7808241d3fd..d9bbeafd82c 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -103,6 +103,7 @@ #include "utils/syscache.h" #include "utils/timestamp.h" #include "utils/typcache.h" +#include "utils/usercontext.h" /* * ON COMMIT action list @@ -1762,7 +1763,7 @@ ExecuteTruncate(TruncateStmt *stmt) } ExecuteTruncateGuts(rels, relids, relids_logged, - stmt->behavior, stmt->restart_seqs); + stmt->behavior, stmt->restart_seqs, false); /* And close the rels */ foreach(cell, rels) @@ -1790,7 +1791,8 @@ void ExecuteTruncateGuts(List *explicit_rels, List *relids, List *relids_logged, - DropBehavior behavior, bool restart_seqs) + DropBehavior behavior, bool restart_seqs, + bool run_as_table_owner) { List *rels; List *seq_relids = NIL; @@ -1929,7 +1931,14 @@ ExecuteTruncateGuts(List *explicit_rels, resultRelInfo = resultRelInfos; foreach(cell, rels) { + UserContext ucxt; + + if (run_as_table_owner) + SwitchToUntrustedUser(resultRelInfo->ri_RelationDesc->rd_rel->relowner, + &ucxt); ExecBSTruncateTriggers(estate, resultRelInfo); + if (run_as_table_owner) + RestoreUserContext(&ucxt); resultRelInfo++; } @@ -2134,7 +2143,14 @@ ExecuteTruncateGuts(List *explicit_rels, resultRelInfo = resultRelInfos; foreach(cell, rels) { + UserContext ucxt; + + if (run_as_table_owner) + SwitchToUntrustedUser(resultRelInfo->ri_RelationDesc->rd_rel->relowner, + &ucxt); ExecASTruncateTriggers(estate, resultRelInfo); + if (run_as_table_owner) + RestoreUserContext(&ucxt); resultRelInfo++; } |