Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6f25c62

Browse filesBrowse files
committed
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.
1 parent 0d79c0a commit 6f25c62
Copy full SHA for 6f25c62

File tree

Expand file treeCollapse file tree

1 file changed

+10
-5
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+10
-5
lines changed

‎src/backend/commands/tablecmds.c

Copy file name to clipboardExpand all lines: src/backend/commands/tablecmds.c
+10-5Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8710,21 +8710,26 @@ static void
87108710
ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, char *tablespacename, LOCKMODE lockmode)
87118711
{
87128712
Oid tablespaceId;
8713-
AclResult aclresult;
87148713

87158714
/* Check that the tablespace exists */
87168715
tablespaceId = get_tablespace_oid(tablespacename, false);
87178716

8718-
/* Check its permissions */
8719-
aclresult = pg_tablespace_aclcheck(tablespaceId, GetUserId(), ACL_CREATE);
8720-
if (aclresult != ACLCHECK_OK)
8721-
aclcheck_error(aclresult, ACL_KIND_TABLESPACE, tablespacename);
8717+
/* Check permissions except when moving to database's default */
8718+
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
8719+
{
8720+
AclResult aclresult;
8721+
8722+
aclresult = pg_tablespace_aclcheck(tablespaceId, GetUserId(), ACL_CREATE);
8723+
if (aclresult != ACLCHECK_OK)
8724+
aclcheck_error(aclresult, ACL_KIND_TABLESPACE, tablespacename);
8725+
}
87228726

87238727
/* Save info for Phase 3 to do the real work */
87248728
if (OidIsValid(tab->newTableSpace))
87258729
ereport(ERROR,
87268730
(errcode(ERRCODE_SYNTAX_ERROR),
87278731
errmsg("cannot have multiple SET TABLESPACE subcommands")));
8732+
87288733
tab->newTableSpace = tablespaceId;
87298734
}
87308735

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.