1
0
mirror of https://github.com/postgres/postgres.git synced 2025-05-01 01:04:50 +03:00

Allow SET TABLESPACE to database default

We've always allowed CREATE TABLE to create tables in the database's default
tablespace without checking for CREATE permissions on that tablespace.
Unfortunately, the original implementation of ALTER TABLE ... SET TABLESPACE
didn't pick up on that exception.

This changes ALTER TABLE ... SET TABLESPACE to allow the database's default
tablespace without checking for CREATE rights on that tablespace, just as
CREATE TABLE works today.  Users could always do this through a series of
commands (CREATE TABLE ... AS SELECT * FROM ...; DROP TABLE ...; etc), so
let's fix the oversight in SET TABLESPACE's original implementation.
This commit is contained in:
Stephen Frost 2014-01-18 18:41:52 -05:00
parent 526e38751a
commit 1fe06595ab

View File

@ -8462,21 +8462,26 @@ static void
ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, char *tablespacename, LOCKMODE lockmode) ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, char *tablespacename, LOCKMODE lockmode)
{ {
Oid tablespaceId; Oid tablespaceId;
AclResult aclresult;
/* Check that the tablespace exists */ /* Check that the tablespace exists */
tablespaceId = get_tablespace_oid(tablespacename, false); tablespaceId = get_tablespace_oid(tablespacename, false);
/* Check its permissions */ /* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
{
AclResult aclresult;
aclresult = pg_tablespace_aclcheck(tablespaceId, GetUserId(), ACL_CREATE); aclresult = pg_tablespace_aclcheck(tablespaceId, GetUserId(), ACL_CREATE);
if (aclresult != ACLCHECK_OK) if (aclresult != ACLCHECK_OK)
aclcheck_error(aclresult, ACL_KIND_TABLESPACE, tablespacename); aclcheck_error(aclresult, ACL_KIND_TABLESPACE, tablespacename);
}
/* Save info for Phase 3 to do the real work */ /* Save info for Phase 3 to do the real work */
if (OidIsValid(tab->newTableSpace)) if (OidIsValid(tab->newTableSpace))
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR), (errcode(ERRCODE_SYNTAX_ERROR),
errmsg("cannot have multiple SET TABLESPACE subcommands"))); errmsg("cannot have multiple SET TABLESPACE subcommands")));
tab->newTableSpace = tablespaceId; tab->newTableSpace = tablespaceId;
} }