diff options
| author | Alvaro Herrera | 2016-04-05 21:38:54 +0000 |
|---|---|---|
| committer | Alvaro Herrera | 2016-04-05 21:38:54 +0000 |
| commit | f2fcad27d59c8e5c48f8fa0a96c8355e40f24273 (patch) | |
| tree | 8630b838513cbd3e2d846a68bf9db6a5f2f9c7b1 /src/backend/commands | |
| parent | 41ea0c23761ca108e2f08f6e3151e3cb1f9652a1 (diff) | |
Support ALTER THING .. DEPENDS ON EXTENSION
This introduces a new dependency type which marks an object as depending
on an extension, such that if the extension is dropped, the object
automatically goes away; and also, if the database is dumped, the object
is included in the dump output. Currently the grammar supports this for
indexes, triggers, materialized views and functions only, although the
utility code is generic so adding support for more object types is a
matter of touching the parser rules only.
Author: Abhijit Menon-Sen
Reviewed-by: Alexander Korotkov, Álvaro Herrera
Discussion: http://www.postgresql.org/message-id/20160115062649.GA5068@toroid.org
Diffstat (limited to 'src/backend/commands')
| -rw-r--r-- | src/backend/commands/alter.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/backend/commands/alter.c b/src/backend/commands/alter.c index 5af0f2ffdf3..7e39422ecd6 100644 --- a/src/backend/commands/alter.c +++ b/src/backend/commands/alter.c @@ -391,6 +391,43 @@ ExecRenameStmt(RenameStmt *stmt) } /* + * Executes an ALTER OBJECT / DEPENDS ON [EXTENSION] statement. + * + * Return value is the address of the altered object. refAddress is an output + * argument which, if not null, receives the address of the object that the + * altered object now depends on. + */ +ObjectAddress +ExecAlterObjectDependsStmt(AlterObjectDependsStmt *stmt, ObjectAddress *refAddress) +{ + ObjectAddress address; + ObjectAddress refAddr; + Relation rel; + + address = + get_object_address_rv(stmt->objectType, stmt->relation, stmt->objname, + stmt->objargs, &rel, AccessExclusiveLock, false); + + /* + * If a relation was involved, it would have been opened and locked. + * We don't need the relation here, but we'll retain the lock until + * commit. + */ + if (rel) + heap_close(rel, NoLock); + + refAddr = get_object_address(OBJECT_EXTENSION, list_make1(stmt->extname), + NULL, &rel, AccessExclusiveLock, false); + Assert(rel == NULL); + if (refAddress) + *refAddress = refAddr; + + recordDependencyOn(&address, refAddress, DEPENDENCY_AUTO_EXTENSION); + + return address; +} + +/* * Executes an ALTER OBJECT / SET SCHEMA statement. Based on the object * type, the function appropriate to that type is executed. * |
