Thread: pgsql: Fix some issues with temp/transient tables in extension scripts.

Fix some issues with temp/transient tables in extension scripts.

Phil Sorber reported that a rewriting ALTER TABLE within an extension
update script failed, because it creates and then drops a placeholder
table; the drop was being disallowed because the table was marked as an
extension member.  We could hack that specific case but it seems likely
that there might be related cases now or in the future, so the most
practical solution seems to be to create an exception to the general rule
that extension member objects can only be dropped by dropping the owning
extension.  To wit: if the DROP is issued within the extension's own
creation or update scripts, we'll allow it, implicitly performing an
"ALTER EXTENSION DROP object" first.  This will simplify cases such as
extension downgrade scripts anyway.

No docs change since we don't seem to have documented the idea that you
would need ALTER EXTENSION DROP for such an action to begin with.

Also, arrange for explicitly temporary tables to not get linked as
extension members in the first place, and the same for the magic
pg_temp_nnn schemas that are created to hold them.  This prevents assorted
unpleasant results if an extension script creates a temp table: the forced
drop at session end would either fail or remove the entire extension, and
neither of those outcomes is desirable.  Note that this doesn't fix the
ALTER TABLE scenario, since the placeholder table is not temp (unless the
table being rewritten is).

Back-patch to 9.1.

Branch
------
REL9_1_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/ad05b5d28d99e1511a10b542c72ada2e97cc0228

Modified Files
--------------
src/backend/catalog/dependency.c   |   31 +++++++++++++++++++++++++------
src/backend/catalog/heap.c         |    9 ++++++++-
src/backend/catalog/namespace.c    |    6 ++++--
src/backend/catalog/pg_namespace.c |   15 ++++++++++++---
src/backend/commands/schemacmds.c  |    2 +-
src/include/catalog/pg_namespace.h |    2 +-
6 files changed, 51 insertions(+), 14 deletions(-)