1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-17 06:41:09 +03:00

Support SET FROM CURRENT in CREATE/ALTER FUNCTION, ALTER DATABASE, ALTER ROLE.

(Actually, it works as a plain statement too, but I didn't document that
because it seems a bit useless.)  Unify VariableResetStmt with
VariableSetStmt, and clean up some ancient cruft in the representation of
same.
This commit is contained in:
Tom Lane
2007-09-03 18:46:30 +00:00
parent dd4594e332
commit e7889b83b7
17 changed files with 382 additions and 360 deletions

View File

@ -13,7 +13,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.197 2007/08/01 22:45:08 tgl Exp $
* $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.198 2007/09/03 18:46:29 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -886,7 +886,7 @@ AlterDatabaseSet(AlterDatabaseSetStmt *stmt)
char repl_null[Natts_pg_database];
char repl_repl[Natts_pg_database];
valuestr = flatten_set_variable_args(stmt->variable, stmt->value);
valuestr = ExtractSetVariableArgs(stmt->setstmt);
/*
* Get the old tuple. We don't need a lock on the database per se,
@ -910,12 +910,12 @@ AlterDatabaseSet(AlterDatabaseSetStmt *stmt)
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_DATABASE,
stmt->dbname);
MemSet(repl_repl, ' ', sizeof(repl_repl));
memset(repl_repl, ' ', sizeof(repl_repl));
repl_repl[Anum_pg_database_datconfig - 1] = 'r';
if (strcmp(stmt->variable, "all") == 0 && valuestr == NULL)
if (stmt->setstmt->kind == VAR_RESET_ALL)
{
/* RESET ALL */
/* RESET ALL, so just set datconfig to null */
repl_null[Anum_pg_database_datconfig - 1] = 'n';
repl_val[Anum_pg_database_datconfig - 1] = (Datum) 0;
}
@ -927,15 +927,16 @@ AlterDatabaseSet(AlterDatabaseSetStmt *stmt)
repl_null[Anum_pg_database_datconfig - 1] = ' ';
/* Extract old value of datconfig */
datum = heap_getattr(tuple, Anum_pg_database_datconfig,
RelationGetDescr(rel), &isnull);
a = isnull ? NULL : DatumGetArrayTypeP(datum);
/* Update (valuestr is NULL in RESET cases) */
if (valuestr)
a = GUCArrayAdd(a, stmt->variable, valuestr);
a = GUCArrayAdd(a, stmt->setstmt->name, valuestr);
else
a = GUCArrayDelete(a, stmt->variable);
a = GUCArrayDelete(a, stmt->setstmt->name);
if (a)
repl_val[Anum_pg_database_datconfig - 1] = PointerGetDatum(a);
@ -943,7 +944,8 @@ AlterDatabaseSet(AlterDatabaseSetStmt *stmt)
repl_null[Anum_pg_database_datconfig - 1] = 'n';
}
newtuple = heap_modifytuple(tuple, RelationGetDescr(rel), repl_val, repl_null, repl_repl);
newtuple = heap_modifytuple(tuple, RelationGetDescr(rel),
repl_val, repl_null, repl_repl);
simple_heap_update(rel, &tuple->t_self, newtuple);
/* Update indexes */

View File

@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/functioncmds.c,v 1.84 2007/09/03 00:39:15 tgl Exp $
* $PostgreSQL: pgsql/src/backend/commands/functioncmds.c,v 1.85 2007/09/03 18:46:29 tgl Exp $
*
* DESCRIPTION
* These routines take the parse tree and pick out the
@ -354,7 +354,7 @@ interpret_func_volatility(DefElem *defel)
}
/*
* Update a proconfig value according to a list of SET and RESET items.
* Update a proconfig value according to a list of VariableSetStmt items.
*
* The input and result may be NULL to signify a null entry.
*/
@ -365,33 +365,20 @@ update_proconfig_value(ArrayType *a, List *set_items)
foreach(l, set_items)
{
Node *sitem = (Node *) lfirst(l);
VariableSetStmt *sstmt = (VariableSetStmt *) lfirst(l);
if (IsA(sitem, VariableSetStmt))
Assert(IsA(sstmt, VariableSetStmt));
if (sstmt->kind == VAR_RESET_ALL)
a = NULL;
else
{
VariableSetStmt *sstmt = (VariableSetStmt *) sitem;
char *valuestr = ExtractSetVariableArgs(sstmt);
if (sstmt->args)
{
char *valuestr;
valuestr = flatten_set_variable_args(sstmt->name, sstmt->args);
if (valuestr)
a = GUCArrayAdd(a, sstmt->name, valuestr);
}
else /* SET TO DEFAULT */
else /* RESET */
a = GUCArrayDelete(a, sstmt->name);
}
else if (IsA(sitem, VariableResetStmt))
{
VariableResetStmt *rstmt = (VariableResetStmt *) sitem;
if (strcmp(rstmt->name, "all") == 0)
a = NULL; /* RESET ALL */
else
a = GUCArrayDelete(a, rstmt->name);
}
else
elog(ERROR, "unexpected node type: %d", nodeTag(sitem));
}
return a;

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/backend/commands/user.c,v 1.176 2007/02/01 19:10:26 momjian Exp $
* $PostgreSQL: pgsql/src/backend/commands/user.c,v 1.177 2007/09/03 18:46:30 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -721,9 +721,8 @@ AlterRoleSet(AlterRoleSetStmt *stmt)
Datum repl_val[Natts_pg_authid];
char repl_null[Natts_pg_authid];
char repl_repl[Natts_pg_authid];
int i;
valuestr = flatten_set_variable_args(stmt->variable, stmt->value);
valuestr = ExtractSetVariableArgs(stmt->setstmt);
rel = heap_open(AuthIdRelationId, RowExclusiveLock);
oldtuple = SearchSysCache(AUTHNAME,
@ -754,14 +753,14 @@ AlterRoleSet(AlterRoleSetStmt *stmt)
errmsg("permission denied")));
}
for (i = 0; i < Natts_pg_authid; i++)
repl_repl[i] = ' ';
memset(repl_repl, ' ', sizeof(repl_repl));
repl_repl[Anum_pg_authid_rolconfig - 1] = 'r';
if (strcmp(stmt->variable, "all") == 0 && valuestr == NULL)
if (stmt->setstmt->kind == VAR_RESET_ALL)
{
/* RESET ALL */
/* RESET ALL, so just set rolconfig to null */
repl_null[Anum_pg_authid_rolconfig - 1] = 'n';
repl_val[Anum_pg_authid_rolconfig - 1] = (Datum) 0;
}
else
{
@ -771,15 +770,16 @@ AlterRoleSet(AlterRoleSetStmt *stmt)
repl_null[Anum_pg_authid_rolconfig - 1] = ' ';
/* Extract old value of rolconfig */
datum = SysCacheGetAttr(AUTHNAME, oldtuple,
Anum_pg_authid_rolconfig, &isnull);
array = isnull ? NULL : DatumGetArrayTypeP(datum);
/* Update (valuestr is NULL in RESET cases) */
if (valuestr)
array = GUCArrayAdd(array, stmt->variable, valuestr);
array = GUCArrayAdd(array, stmt->setstmt->name, valuestr);
else
array = GUCArrayDelete(array, stmt->variable);
array = GUCArrayDelete(array, stmt->setstmt->name);
if (array)
repl_val[Anum_pg_authid_rolconfig - 1] = PointerGetDatum(array);