Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e7889b8

Browse files
committed
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.
1 parent dd4594e commit e7889b8

File tree

17 files changed

+367
-345
lines changed

17 files changed

+367
-345
lines changed

doc/src/sgml/ref/alter_database.sgml

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_database.sgml,v 1.19 2006/09/16 00:30:16 momjian Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_database.sgml,v 1.20 2007/09/03 18:46:29 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -26,12 +26,14 @@ where <replaceable class="PARAMETER">option</replaceable> can be:
2626

2727
CONNECTION LIMIT <replaceable class="PARAMETER">connlimit</replaceable>
2828

29-
ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> SET <replaceable>parameter</replaceable> { TO | = } { <replaceable>value</replaceable> | DEFAULT }
30-
ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> RESET <replaceable>parameter</replaceable>
31-
3229
ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> RENAME TO <replaceable>newname</replaceable>
3330

3431
ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> OWNER TO <replaceable>new_owner</replaceable>
32+
33+
ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> SET <replaceable>configuration_parameter</replaceable> { TO | = } { <replaceable>value</replaceable> | DEFAULT }
34+
ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> SET <replaceable>configuration_parameter</replaceable> FROM CURRENT
35+
ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> RESET <replaceable>configuration_parameter</replaceable>
36+
ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> RESET ALL
3537
</synopsis>
3638
</refsynopsisdiv>
3739

@@ -49,20 +51,7 @@ ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> OWNER TO <repla
4951
</para>
5052

5153
<para>
52-
The second and third forms change the session default for a run-time
53-
configuration variable for a <productname>PostgreSQL</productname>
54-
database. Whenever a new session is subsequently started in that
55-
database, the specified value becomes the session default value.
56-
The database-specific default overrides whatever setting is present
57-
in <filename>postgresql.conf</> or has been received from the
58-
<command>postgres</command> command line. Only the database
59-
owner or a superuser can change the session defaults for a
60-
database. Certain variables cannot be set this way, or can only be
61-
set by a superuser.
62-
</para>
63-
64-
<para>
65-
The fourth form changes the name of the database. Only the database
54+
The second form changes the name of the database. Only the database
6655
owner or a superuser can rename a database; non-superuser owners must
6756
also have the
6857
<literal>CREATEDB</literal> privilege. The current database cannot
@@ -71,12 +60,25 @@ ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> OWNER TO <repla
7160
</para>
7261

7362
<para>
74-
The fifth form changes the owner of the database.
63+
The third form changes the owner of the database.
7564
To alter the owner, you must own the database and also be a direct or
7665
indirect member of the new owning role, and you must have the
7766
<literal>CREATEDB</literal> privilege.
7867
(Note that superusers have all these privileges automatically.)
7968
</para>
69+
70+
<para>
71+
The remaining forms change the session default for a run-time
72+
configuration variable for a <productname>PostgreSQL</productname>
73+
database. Whenever a new session is subsequently started in that
74+
database, the specified value becomes the session default value.
75+
The database-specific default overrides whatever setting is present
76+
in <filename>postgresql.conf</> or has been received from the
77+
<command>postgres</command> command line. Only the database
78+
owner or a superuser can change the session defaults for a
79+
database. Certain variables cannot be set this way, or can only be
80+
set by a superuser.
81+
</para>
8082
</refsect1>
8183

8284
<refsect1>
@@ -102,8 +104,26 @@ ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> OWNER TO <repla
102104
</listitem>
103105
</varlistentry>
104106

107+
<varlistentry>
108+
<term><replaceable>newname</replaceable></term>
109+
<listitem>
110+
<para>
111+
The new name of the database.
112+
</para>
113+
</listitem>
114+
</varlistentry>
115+
116+
<varlistentry>
117+
<term><replaceable class="parameter">new_owner</replaceable></term>
118+
<listitem>
119+
<para>
120+
The new owner of the database.
121+
</para>
122+
</listitem>
123+
</varlistentry>
124+
105125
<varlistentry>
106-
<term><replaceable>parameter</replaceable></term>
126+
<term><replaceable>configuration_parameter</replaceable></term>
107127
<term><replaceable>value</replaceable></term>
108128
<listitem>
109129
<para>
@@ -114,6 +134,8 @@ ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> OWNER TO <repla
114134
database-specific setting is removed, so the system-wide default
115135
setting will be inherited in new sessions. Use <literal>RESET
116136
ALL</literal> to clear all database-specific settings.
137+
<literal>SET FROM CURRENT</> saves the session's current value of
138+
the parameter as the database-specific value.
117139
</para>
118140

119141
<para>
@@ -123,35 +145,17 @@ ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> OWNER TO <repla
123145
</para>
124146
</listitem>
125147
</varlistentry>
126-
127-
<varlistentry>
128-
<term><replaceable>newname</replaceable></term>
129-
<listitem>
130-
<para>
131-
The new name of the database.
132-
</para>
133-
</listitem>
134-
</varlistentry>
135-
136-
<varlistentry>
137-
<term><replaceable class="parameter">new_owner</replaceable></term>
138-
<listitem>
139-
<para>
140-
The new owner of the database.
141-
</para>
142-
</listitem>
143-
</varlistentry>
144148
</variablelist>
145149
</refsect1>
146150

147151
<refsect1>
148152
<title>Notes</title>
149153

150154
<para>
151-
It is also possible to tie a session default to a specific user
155+
It is also possible to tie a session default to a specific role
152156
rather than to a database; see
153-
<xref linkend="sql-alteruser" endterm="sql-alteruser-title">.
154-
User-specific settings override database-specific
157+
<xref linkend="sql-alterrole" endterm="sql-alterrole-title">.
158+
Role-specific settings override database-specific
155159
ones if there is a conflict.
156160
</para>
157161
</refsect1>

doc/src/sgml/ref/alter_function.sgml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_function.sgml,v 1.14 2007/09/03 00:39:12 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_function.sgml,v 1.15 2007/09/03 18:46:29 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -21,7 +21,7 @@ PostgreSQL documentation
2121
<refsynopsisdiv>
2222
<synopsis>
2323
ALTER FUNCTION <replaceable>name</replaceable> ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] )
24-
<replaceable class="PARAMETER">action</replaceable> [, ... ] [ RESTRICT ]
24+
<replaceable class="PARAMETER">action</replaceable> [ ... ] [ RESTRICT ]
2525
ALTER FUNCTION <replaceable>name</replaceable> ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] )
2626
RENAME TO <replaceable>new_name</replaceable>
2727
ALTER FUNCTION <replaceable>name</replaceable> ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] )
@@ -36,8 +36,10 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
3636
[ EXTERNAL ] SECURITY INVOKER | [ EXTERNAL ] SECURITY DEFINER
3737
COST <replaceable class="parameter">execution_cost</replaceable>
3838
ROWS <replaceable class="parameter">result_rows</replaceable>
39-
SET <replaceable class="parameter">parameter</replaceable> { TO | = } { <replaceable class="parameter">value</replaceable> | DEFAULT }
40-
RESET <replaceable class="parameter">parameter</replaceable>
39+
SET <replaceable class="parameter">configuration_parameter</replaceable> { TO | = } { <replaceable class="parameter">value</replaceable> | DEFAULT }
40+
SET <replaceable class="parameter">configuration_parameter</replaceable> FROM CURRENT
41+
RESET <replaceable class="parameter">configuration_parameter</replaceable>
42+
RESET ALL
4143
</synopsis>
4244
</refsynopsisdiv>
4345

@@ -215,7 +217,7 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
215217
</varlistentry>
216218

217219
<varlistentry>
218-
<term><replaceable>parameter</replaceable></term>
220+
<term><replaceable>configuration_parameter</replaceable></term>
219221
<term><replaceable>value</replaceable></term>
220222
<listitem>
221223
<para>
@@ -226,6 +228,8 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
226228
setting is removed, so that the function executes with the value
227229
present in its environment. Use <literal>RESET
228230
ALL</literal> to clear all function-local settings.
231+
<literal>SET FROM CURRENT</> saves the session's current value of
232+
the parameter as the value to be applied when the function is entered.
229233
</para>
230234

231235
<para>

doc/src/sgml/ref/alter_role.sgml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_role.sgml,v 1.8 2007/05/15 19:43:51 neilc Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_role.sgml,v 1.9 2007/09/03 18:46:29 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -37,7 +37,9 @@ where <replaceable class="PARAMETER">option</replaceable> can be:
3737
ALTER ROLE <replaceable class="PARAMETER">name</replaceable> RENAME TO <replaceable>newname</replaceable>
3838

3939
ALTER ROLE <replaceable class="PARAMETER">name</replaceable> SET <replaceable>configuration_parameter</replaceable> { TO | = } { <replaceable>value</replaceable> | DEFAULT }
40+
ALTER ROLE <replaceable class="PARAMETER">name</replaceable> SET <replaceable>configuration_parameter</replaceable> FROM CURRENT
4041
ALTER ROLE <replaceable class="PARAMETER">name</replaceable> RESET <replaceable>configuration_parameter</replaceable>
42+
ALTER ROLE <replaceable class="PARAMETER">name</replaceable> RESET ALL
4143
</synopsis>
4244
</refsynopsisdiv>
4345

@@ -77,7 +79,7 @@ ALTER ROLE <replaceable class="PARAMETER">name</replaceable> RESET <replaceable>
7779
</para>
7880

7981
<para>
80-
The third and the fourth variant change a role's session default for
82+
The remaining variants change a role's session default for
8183
a specified configuration variable. Whenever the role subsequently
8284
starts a new session, the specified value becomes the session default,
8385
overriding whatever setting is present in <filename>postgresql.conf</>
@@ -155,6 +157,8 @@ ALTER ROLE <replaceable class="PARAMETER">name</replaceable> RESET <replaceable>
155157
role-specific variable setting is removed, so the role will
156158
inherit the system-wide default setting in new sessions. Use
157159
<literal>RESET ALL</literal> to clear all role-specific settings.
160+
<literal>SET FROM CURRENT</> saves the session's current value of
161+
the parameter as the role-specific value.
158162
</para>
159163

160164
<para>

doc/src/sgml/ref/alter_user.sgml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_user.sgml,v 1.43 2007/05/15 19:43:51 neilc Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_user.sgml,v 1.44 2007/09/03 18:46:29 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -37,7 +37,9 @@ where <replaceable class="PARAMETER">option</replaceable> can be:
3737
ALTER USER <replaceable class="PARAMETER">name</replaceable> RENAME TO <replaceable>newname</replaceable>
3838

3939
ALTER USER <replaceable class="PARAMETER">name</replaceable> SET <replaceable>configuration_parameter</replaceable> { TO | = } { <replaceable>value</replaceable> | DEFAULT }
40+
ALTER USER <replaceable class="PARAMETER">name</replaceable> SET <replaceable>configuration_parameter</replaceable> FROM CURRENT
4041
ALTER USER <replaceable class="PARAMETER">name</replaceable> RESET <replaceable>configuration_parameter</replaceable>
42+
ALTER USER <replaceable class="PARAMETER">name</replaceable> RESET ALL
4143
</synopsis>
4244
</refsynopsisdiv>
4345

doc/src/sgml/ref/create_function.sgml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/create_function.sgml,v 1.76 2007/09/03 00:39:13 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/create_function.sgml,v 1.77 2007/09/03 18:46:29 tgl Exp $
33
-->
44

55
<refentry id="SQL-CREATEFUNCTION">
@@ -28,7 +28,7 @@ CREATE [ OR REPLACE ] FUNCTION
2828
| [ EXTERNAL ] SECURITY INVOKER | [ EXTERNAL ] SECURITY DEFINER
2929
| COST <replaceable class="parameter">execution_cost</replaceable>
3030
| ROWS <replaceable class="parameter">result_rows</replaceable>
31-
| SET <replaceable class="parameter">parameter</replaceable> { TO | = } { <replaceable class="parameter">value</replaceable> | DEFAULT }
31+
| SET <replaceable class="parameter">configuration_parameter</replaceable> { TO <replaceable class="parameter">value</replaceable> | = <replaceable class="parameter">value</replaceable> | FROM CURRENT }
3232
| AS '<replaceable class="parameter">definition</replaceable>'
3333
| AS '<replaceable class="parameter">obj_file</replaceable>', '<replaceable class="parameter">link_symbol</replaceable>'
3434
} ...
@@ -324,13 +324,15 @@ CREATE [ OR REPLACE ] FUNCTION
324324
</varlistentry>
325325

326326
<varlistentry>
327-
<term><replaceable>parameter</replaceable></term>
327+
<term><replaceable>configuration_parameter</replaceable></term>
328328
<term><replaceable>value</replaceable></term>
329329
<listitem>
330330
<para>
331331
The <literal>SET</> clause causes the specified configuration
332332
parameter to be set to the specified value when the function is
333333
entered, and then restored to its prior value when the function exits.
334+
<literal>SET FROM CURRENT</> saves the session's current value of
335+
the parameter as the value to be applied when the function is entered.
334336
</para>
335337

336338
<para>

src/backend/commands/dbcommands.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
*
1515
* IDENTIFICATION
16-
* $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.197 2007/08/01 22:45:08 tgl Exp $
16+
* $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.198 2007/09/03 18:46:29 tgl Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -886,7 +886,7 @@ AlterDatabaseSet(AlterDatabaseSetStmt *stmt)
886886
char repl_null[Natts_pg_database];
887887
char repl_repl[Natts_pg_database];
888888

889-
valuestr = flatten_set_variable_args(stmt->variable, stmt->value);
889+
valuestr = ExtractSetVariableArgs(stmt->setstmt);
890890

891891
/*
892892
* Get the old tuple. We don't need a lock on the database per se,
@@ -910,12 +910,12 @@ AlterDatabaseSet(AlterDatabaseSetStmt *stmt)
910910
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_DATABASE,
911911
stmt->dbname);
912912

913-
MemSet(repl_repl, ' ', sizeof(repl_repl));
913+
memset(repl_repl, ' ', sizeof(repl_repl));
914914
repl_repl[Anum_pg_database_datconfig - 1] = 'r';
915915

916-
if (strcmp(stmt->variable, "all") == 0 && valuestr == NULL)
916+
if (stmt->setstmt->kind == VAR_RESET_ALL)
917917
{
918-
/* RESET ALL */
918+
/* RESET ALL, so just set datconfig to null */
919919
repl_null[Anum_pg_database_datconfig - 1] = 'n';
920920
repl_val[Anum_pg_database_datconfig - 1] = (Datum) 0;
921921
}
@@ -927,23 +927,25 @@ AlterDatabaseSet(AlterDatabaseSetStmt *stmt)
927927

928928
repl_null[Anum_pg_database_datconfig - 1] = ' ';
929929

930+
/* Extract old value of datconfig */
930931
datum = heap_getattr(tuple, Anum_pg_database_datconfig,
931932
RelationGetDescr(rel), &isnull);
932-
933933
a = isnull ? NULL : DatumGetArrayTypeP(datum);
934934

935+
/* Update (valuestr is NULL in RESET cases) */
935936
if (valuestr)
936-
a = GUCArrayAdd(a, stmt->variable, valuestr);
937+
a = GUCArrayAdd(a, stmt->setstmt->name, valuestr);
937938
else
938-
a = GUCArrayDelete(a, stmt->variable);
939+
a = GUCArrayDelete(a, stmt->setstmt->name);
939940

940941
if (a)
941942
repl_val[Anum_pg_database_datconfig - 1] = PointerGetDatum(a);
942943
else
943944
repl_null[Anum_pg_database_datconfig - 1] = 'n';
944945
}
945946

946-
newtuple = heap_modifytuple(tuple, RelationGetDescr(rel), repl_val, repl_null, repl_repl);
947+
newtuple = heap_modifytuple(tuple, RelationGetDescr(rel),
948+
repl_val, repl_null, repl_repl);
947949
simple_heap_update(rel, &tuple->t_self, newtuple);
948950

949951
/* Update indexes */

0 commit comments

Comments
 (0)