Commit 31eae602 authored by Alvaro Herrera's avatar Alvaro Herrera

Allow CURRENT/SESSION_USER to be used in certain commands

Commands such as ALTER USER, ALTER GROUP, ALTER ROLE, GRANT, and the
various ALTER OBJECT / OWNER TO, as well as ad-hoc clauses related to
roles such as the AUTHORIZATION clause of CREATE SCHEMA, the FOR clause
of CREATE USER MAPPING, and the FOR ROLE clause of ALTER DEFAULT
PRIVILEGES can now take the keywords CURRENT_USER and SESSION_USER as
user specifiers in place of an explicit user name.

This commit also fixes some quite ugly handling of special standards-
mandated syntax in CREATE USER MAPPING, which in particular would fail
to work in presence of a role named "current_user".

The special role specifiers PUBLIC and NONE also have more consistent
handling now.

Also take the opportunity to add location tracking to user specifiers.

Authors: Kyotaro Horiguchi.  Heavily reworked by Álvaro Herrera.
Reviewed by: Rushabh Lathia, Adam Brightwell, Marti Raudsepp.
parent fa83f809
...@@ -22,7 +22,8 @@ PostgreSQL documentation ...@@ -22,7 +22,8 @@ PostgreSQL documentation
<refsynopsisdiv> <refsynopsisdiv>
<synopsis> <synopsis>
ALTER AGGREGATE <replaceable>name</replaceable> ( <replaceable>aggregate_signature</replaceable> ) RENAME TO <replaceable>new_name</replaceable> ALTER AGGREGATE <replaceable>name</replaceable> ( <replaceable>aggregate_signature</replaceable> ) RENAME TO <replaceable>new_name</replaceable>
ALTER AGGREGATE <replaceable>name</replaceable> ( <replaceable>aggregate_signature</replaceable> ) OWNER TO <replaceable>new_owner</replaceable> ALTER AGGREGATE <replaceable>name</replaceable> ( <replaceable>aggregate_signature</replaceable> )
OWNER TO { <replaceable>new_owner</replaceable> | CURRENT_USER | SESSION_USER }
ALTER AGGREGATE <replaceable>name</replaceable> ( <replaceable>aggregate_signature</replaceable> ) SET SCHEMA <replaceable>new_schema</replaceable> ALTER AGGREGATE <replaceable>name</replaceable> ( <replaceable>aggregate_signature</replaceable> ) SET SCHEMA <replaceable>new_schema</replaceable>
<phrase>where <replaceable>aggregate_signature</replaceable> is:</phrase> <phrase>where <replaceable>aggregate_signature</replaceable> is:</phrase>
......
...@@ -22,7 +22,7 @@ PostgreSQL documentation ...@@ -22,7 +22,7 @@ PostgreSQL documentation
<refsynopsisdiv> <refsynopsisdiv>
<synopsis> <synopsis>
ALTER COLLATION <replaceable>name</replaceable> RENAME TO <replaceable>new_name</replaceable> ALTER COLLATION <replaceable>name</replaceable> RENAME TO <replaceable>new_name</replaceable>
ALTER COLLATION <replaceable>name</replaceable> OWNER TO <replaceable>new_owner</replaceable> ALTER COLLATION <replaceable>name</replaceable> OWNER TO { <replaceable>new_owner</replaceable> | CURRENT_USER | SESSION_USER }
ALTER COLLATION <replaceable>name</replaceable> SET SCHEMA <replaceable>new_schema</replaceable> ALTER COLLATION <replaceable>name</replaceable> SET SCHEMA <replaceable>new_schema</replaceable>
</synopsis> </synopsis>
</refsynopsisdiv> </refsynopsisdiv>
......
...@@ -22,7 +22,7 @@ PostgreSQL documentation ...@@ -22,7 +22,7 @@ PostgreSQL documentation
<refsynopsisdiv> <refsynopsisdiv>
<synopsis> <synopsis>
ALTER CONVERSION <replaceable>name</replaceable> RENAME TO <replaceable>new_name</replaceable> ALTER CONVERSION <replaceable>name</replaceable> RENAME TO <replaceable>new_name</replaceable>
ALTER CONVERSION <replaceable>name</replaceable> OWNER TO <replaceable>new_owner</replaceable> ALTER CONVERSION <replaceable>name</replaceable> OWNER TO { <replaceable>new_owner</replaceable> | CURRENT_USER | SESSION_USER }
ALTER CONVERSION <replaceable>name</replaceable> SET SCHEMA <replaceable>new_schema</replaceable> ALTER CONVERSION <replaceable>name</replaceable> SET SCHEMA <replaceable>new_schema</replaceable>
</synopsis> </synopsis>
</refsynopsisdiv> </refsynopsisdiv>
......
...@@ -31,7 +31,7 @@ ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> [ [ WITH ] <rep ...@@ -31,7 +31,7 @@ ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> [ [ WITH ] <rep
ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> RENAME TO <replaceable>new_name</replaceable> ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> RENAME TO <replaceable>new_name</replaceable>
ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> OWNER TO <replaceable>new_owner</replaceable> ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> OWNER TO { <replaceable>new_owner</replaceable> | CURRENT_USER | SESSION_USER }
ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> SET TABLESPACE <replaceable class="PARAMETER">new_tablespace</replaceable> ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> SET TABLESPACE <replaceable class="PARAMETER">new_tablespace</replaceable>
......
...@@ -36,7 +36,7 @@ ALTER DOMAIN <replaceable class="PARAMETER">name</replaceable> ...@@ -36,7 +36,7 @@ ALTER DOMAIN <replaceable class="PARAMETER">name</replaceable>
ALTER DOMAIN <replaceable class="PARAMETER">name</replaceable> ALTER DOMAIN <replaceable class="PARAMETER">name</replaceable>
VALIDATE CONSTRAINT <replaceable class="PARAMETER">constraint_name</replaceable> VALIDATE CONSTRAINT <replaceable class="PARAMETER">constraint_name</replaceable>
ALTER DOMAIN <replaceable class="PARAMETER">name</replaceable> ALTER DOMAIN <replaceable class="PARAMETER">name</replaceable>
OWNER TO <replaceable class="PARAMETER">new_owner</replaceable> OWNER TO { <replaceable class="PARAMETER">new_owner</replaceable> | CURRENT_USER | SESSION_USER }
ALTER DOMAIN <replaceable class="PARAMETER">name</replaceable> ALTER DOMAIN <replaceable class="PARAMETER">name</replaceable>
RENAME TO <replaceable class="PARAMETER">new_name</replaceable> RENAME TO <replaceable class="PARAMETER">new_name</replaceable>
ALTER DOMAIN <replaceable class="PARAMETER">name</replaceable> ALTER DOMAIN <replaceable class="PARAMETER">name</replaceable>
......
...@@ -23,7 +23,7 @@ PostgreSQL documentation ...@@ -23,7 +23,7 @@ PostgreSQL documentation
<synopsis> <synopsis>
ALTER EVENT TRIGGER <replaceable class="PARAMETER">name</replaceable> DISABLE ALTER EVENT TRIGGER <replaceable class="PARAMETER">name</replaceable> DISABLE
ALTER EVENT TRIGGER <replaceable class="PARAMETER">name</replaceable> ENABLE [ REPLICA | ALWAYS ] ALTER EVENT TRIGGER <replaceable class="PARAMETER">name</replaceable> ENABLE [ REPLICA | ALWAYS ]
ALTER EVENT TRIGGER <replaceable class="PARAMETER">name</replaceable> OWNER TO <replaceable class="PARAMETER">new_owner</replaceable> ALTER EVENT TRIGGER <replaceable class="PARAMETER">name</replaceable> OWNER TO { <replaceable class="PARAMETER">new_owner</replaceable> | CURRENT_USER | SESSION_USER }
ALTER EVENT TRIGGER <replaceable class="PARAMETER">name</replaceable> RENAME TO <replaceable class="PARAMETER">new_name</replaceable> ALTER EVENT TRIGGER <replaceable class="PARAMETER">name</replaceable> RENAME TO <replaceable class="PARAMETER">new_name</replaceable>
</synopsis> </synopsis>
</refsynopsisdiv> </refsynopsisdiv>
......
...@@ -25,7 +25,7 @@ ALTER FOREIGN DATA WRAPPER <replaceable class="parameter">name</replaceable> ...@@ -25,7 +25,7 @@ ALTER FOREIGN DATA WRAPPER <replaceable class="parameter">name</replaceable>
[ HANDLER <replaceable class="parameter">handler_function</replaceable> | NO HANDLER ] [ HANDLER <replaceable class="parameter">handler_function</replaceable> | NO HANDLER ]
[ VALIDATOR <replaceable class="parameter">validator_function</replaceable> | NO VALIDATOR ] [ VALIDATOR <replaceable class="parameter">validator_function</replaceable> | NO VALIDATOR ]
[ OPTIONS ( [ ADD | SET | DROP ] <replaceable class="PARAMETER">option</replaceable> ['<replaceable class="PARAMETER">value</replaceable>'] [, ... ]) ] [ OPTIONS ( [ ADD | SET | DROP ] <replaceable class="PARAMETER">option</replaceable> ['<replaceable class="PARAMETER">value</replaceable>'] [, ... ]) ]
ALTER FOREIGN DATA WRAPPER <replaceable class="parameter">name</replaceable> OWNER TO <replaceable>new_owner</replaceable> ALTER FOREIGN DATA WRAPPER <replaceable class="parameter">name</replaceable> OWNER TO { <replaceable>new_owner</replaceable> | CURRENT_USER | SESSION_USER }
ALTER FOREIGN DATA WRAPPER <replaceable class="parameter">name</replaceable> RENAME TO <replaceable>new_name</replaceable> ALTER FOREIGN DATA WRAPPER <replaceable class="parameter">name</replaceable> RENAME TO <replaceable>new_name</replaceable>
</synopsis> </synopsis>
</refsynopsisdiv> </refsynopsisdiv>
......
...@@ -48,7 +48,7 @@ ALTER FOREIGN TABLE [ IF EXISTS ] <replaceable class="PARAMETER">name</replaceab ...@@ -48,7 +48,7 @@ ALTER FOREIGN TABLE [ IF EXISTS ] <replaceable class="PARAMETER">name</replaceab
ENABLE TRIGGER [ <replaceable class="PARAMETER">trigger_name</replaceable> | ALL | USER ] ENABLE TRIGGER [ <replaceable class="PARAMETER">trigger_name</replaceable> | ALL | USER ]
ENABLE REPLICA TRIGGER <replaceable class="PARAMETER">trigger_name</replaceable> ENABLE REPLICA TRIGGER <replaceable class="PARAMETER">trigger_name</replaceable>
ENABLE ALWAYS TRIGGER <replaceable class="PARAMETER">trigger_name</replaceable> ENABLE ALWAYS TRIGGER <replaceable class="PARAMETER">trigger_name</replaceable>
OWNER TO <replaceable class="PARAMETER">new_owner</replaceable> OWNER TO { <replaceable class="PARAMETER">new_owner</replaceable> | CURRENT_USER | SESSION_USER }
OPTIONS ( [ ADD | SET | DROP ] <replaceable class="PARAMETER">option</replaceable> ['<replaceable class="PARAMETER">value</replaceable>'] [, ... ]) OPTIONS ( [ ADD | SET | DROP ] <replaceable class="PARAMETER">option</replaceable> ['<replaceable class="PARAMETER">value</replaceable>'] [, ... ])
</synopsis> </synopsis>
</refsynopsisdiv> </refsynopsisdiv>
......
...@@ -26,7 +26,7 @@ ALTER FUNCTION <replaceable>name</replaceable> ( [ [ <replaceable class="paramet ...@@ -26,7 +26,7 @@ ALTER FUNCTION <replaceable>name</replaceable> ( [ [ <replaceable class="paramet
ALTER FUNCTION <replaceable>name</replaceable> ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] ) ALTER FUNCTION <replaceable>name</replaceable> ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] )
RENAME TO <replaceable>new_name</replaceable> RENAME TO <replaceable>new_name</replaceable>
ALTER FUNCTION <replaceable>name</replaceable> ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] ) ALTER FUNCTION <replaceable>name</replaceable> ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] )
OWNER TO <replaceable>new_owner</replaceable> OWNER TO { <replaceable>new_owner</replaceable> | CURRENT_USER | SESSION_USER }
ALTER FUNCTION <replaceable>name</replaceable> ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] ) ALTER FUNCTION <replaceable>name</replaceable> ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] )
SET SCHEMA <replaceable>new_schema</replaceable> SET SCHEMA <replaceable>new_schema</replaceable>
......
...@@ -21,8 +21,14 @@ PostgreSQL documentation ...@@ -21,8 +21,14 @@ PostgreSQL documentation
<refsynopsisdiv> <refsynopsisdiv>
<synopsis> <synopsis>
ALTER GROUP <replaceable class="PARAMETER">group_name</replaceable> ADD USER <replaceable class="PARAMETER">user_name</replaceable> [, ... ] ALTER GROUP <replaceable class="PARAMETER">role_specification</replaceable> ADD USER <replaceable class="PARAMETER">user_name</replaceable> [, ... ]
ALTER GROUP <replaceable class="PARAMETER">group_name</replaceable> DROP USER <replaceable class="PARAMETER">user_name</replaceable> [, ... ] ALTER GROUP <replaceable class="PARAMETER">role_specification</replaceable> DROP USER <replaceable class="PARAMETER">user_name</replaceable> [, ... ]
<phrase>where <replaceable class="PARAMETER">role_specification</replaceable> can be:</phrase>
<replaceable class="PARAMETER">role_name</replaceable>
| CURRENT_USER
| SESSION_USER
ALTER GROUP <replaceable class="PARAMETER">group_name</replaceable> RENAME TO <replaceable>new_name</replaceable> ALTER GROUP <replaceable class="PARAMETER">group_name</replaceable> RENAME TO <replaceable>new_name</replaceable>
</synopsis> </synopsis>
......
...@@ -22,7 +22,7 @@ PostgreSQL documentation ...@@ -22,7 +22,7 @@ PostgreSQL documentation
<refsynopsisdiv> <refsynopsisdiv>
<synopsis> <synopsis>
ALTER [ PROCEDURAL ] LANGUAGE <replaceable>name</replaceable> RENAME TO <replaceable>new_name</replaceable> ALTER [ PROCEDURAL ] LANGUAGE <replaceable>name</replaceable> RENAME TO <replaceable>new_name</replaceable>
ALTER [ PROCEDURAL ] LANGUAGE <replaceable>name</replaceable> OWNER TO <replaceable>new_owner</replaceable> ALTER [ PROCEDURAL ] LANGUAGE <replaceable>name</replaceable> OWNER TO { <replaceable>new_owner</replaceable> | CURRENT_USER | SESSION_USER }
</synopsis> </synopsis>
</refsynopsisdiv> </refsynopsisdiv>
......
...@@ -21,7 +21,7 @@ PostgreSQL documentation ...@@ -21,7 +21,7 @@ PostgreSQL documentation
<refsynopsisdiv> <refsynopsisdiv>
<synopsis> <synopsis>
ALTER LARGE OBJECT <replaceable class="PARAMETER">large_object_oid</replaceable> OWNER TO <replaceable>new_owner</replaceable> ALTER LARGE OBJECT <replaceable class="PARAMETER">large_object_oid</replaceable> { OWNER TO <replaceable>new_owner</replaceable> | CURRENT_USER | SESSION_USER }
</synopsis> </synopsis>
</refsynopsisdiv> </refsynopsisdiv>
......
...@@ -42,7 +42,7 @@ ALTER MATERIALIZED VIEW ALL IN TABLESPACE <replaceable class="parameter">name</r ...@@ -42,7 +42,7 @@ ALTER MATERIALIZED VIEW ALL IN TABLESPACE <replaceable class="parameter">name</r
SET WITHOUT CLUSTER SET WITHOUT CLUSTER
SET ( <replaceable class="PARAMETER">storage_parameter</replaceable> = <replaceable class="PARAMETER">value</replaceable> [, ... ] ) SET ( <replaceable class="PARAMETER">storage_parameter</replaceable> = <replaceable class="PARAMETER">value</replaceable> [, ... ] )
RESET ( <replaceable class="PARAMETER">storage_parameter</replaceable> [, ... ] ) RESET ( <replaceable class="PARAMETER">storage_parameter</replaceable> [, ... ] )
OWNER TO <replaceable class="PARAMETER">new_owner</replaceable> OWNER TO { <replaceable class="PARAMETER">new_owner</replaceable> | CURRENT_USER | SESSION_USER }
SET TABLESPACE <replaceable class="PARAMETER">new_tablespace</replaceable> SET TABLESPACE <replaceable class="PARAMETER">new_tablespace</replaceable>
</synopsis> </synopsis>
</refsynopsisdiv> </refsynopsisdiv>
......
...@@ -21,9 +21,14 @@ PostgreSQL documentation ...@@ -21,9 +21,14 @@ PostgreSQL documentation
<refsynopsisdiv> <refsynopsisdiv>
<synopsis> <synopsis>
ALTER OPERATOR CLASS <replaceable>name</replaceable> USING <replaceable class="parameter">index_method</replaceable> RENAME TO <replaceable>new_name</replaceable> ALTER OPERATOR CLASS <replaceable>name</replaceable> USING <replaceable class="parameter">index_method</replaceable>
ALTER OPERATOR CLASS <replaceable>name</replaceable> USING <replaceable class="parameter">index_method</replaceable> OWNER TO <replaceable>new_owner</replaceable> RENAME TO <replaceable>new_name</replaceable>
ALTER OPERATOR CLASS <replaceable>name</replaceable> USING <replaceable class="parameter">index_method</replaceable> SET SCHEMA <replaceable>new_schema</replaceable>
ALTER OPERATOR CLASS <replaceable>name</replaceable> USING <replaceable class="parameter">index_method</replaceable>
{ OWNER TO <replaceable>new_owner</replaceable> | CURRENT_USER | SESSION_USER }
ALTER OPERATOR CLASS <replaceable>name</replaceable> USING <replaceable class="parameter">index_method</replaceable>
SET SCHEMA <replaceable>new_schema</replaceable>
</synopsis> </synopsis>
</refsynopsisdiv> </refsynopsisdiv>
......
...@@ -21,8 +21,11 @@ PostgreSQL documentation ...@@ -21,8 +21,11 @@ PostgreSQL documentation
<refsynopsisdiv> <refsynopsisdiv>
<synopsis> <synopsis>
ALTER OPERATOR <replaceable>name</replaceable> ( { <replaceable>left_type</replaceable> | NONE } , { <replaceable>right_type</replaceable> | NONE } ) OWNER TO <replaceable>new_owner</replaceable> ALTER OPERATOR <replaceable>name</replaceable> ( { <replaceable>left_type</replaceable> | NONE } , { <replaceable>right_type</replaceable> | NONE } )
ALTER OPERATOR <replaceable>name</replaceable> ( { <replaceable>left_type</replaceable> | NONE } , { <replaceable>right_type</replaceable> | NONE } ) SET SCHEMA <replaceable>new_schema</replaceable> { OWNER TO <replaceable>new_owner</replaceable> | CURRENT_USER | SESSION_USER }
ALTER OPERATOR <replaceable>name</replaceable> ( { <replaceable>left_type</replaceable> | NONE } , { <replaceable>right_type</replaceable> | NONE } )
SET SCHEMA <replaceable>new_schema</replaceable>
</synopsis> </synopsis>
</refsynopsisdiv> </refsynopsisdiv>
......
...@@ -22,16 +22,25 @@ PostgreSQL documentation ...@@ -22,16 +22,25 @@ PostgreSQL documentation
<refsynopsisdiv> <refsynopsisdiv>
<synopsis> <synopsis>
ALTER OPERATOR FAMILY <replaceable>name</replaceable> USING <replaceable class="parameter">index_method</replaceable> ADD ALTER OPERATOR FAMILY <replaceable>name</replaceable> USING <replaceable class="parameter">index_method</replaceable> ADD
{ OPERATOR <replaceable class="parameter">strategy_number</replaceable> <replaceable class="parameter">operator_name</replaceable> ( <replaceable class="parameter">op_type</replaceable>, <replaceable class="parameter">op_type</replaceable> ) [ FOR SEARCH | FOR ORDER BY <replaceable class="parameter">sort_family_name</replaceable> ] { OPERATOR <replaceable class="parameter">strategy_number</replaceable> <replaceable class="parameter">operator_name</replaceable> ( <replaceable class="parameter">op_type</replaceable>, <replaceable class="parameter">op_type</replaceable> )
| FUNCTION <replaceable class="parameter">support_number</replaceable> [ ( <replaceable class="parameter">op_type</replaceable> [ , <replaceable class="parameter">op_type</replaceable> ] ) ] <replaceable class="parameter">function_name</replaceable> ( <replaceable class="parameter">argument_type</replaceable> [, ...] ) [ FOR SEARCH | FOR ORDER BY <replaceable class="parameter">sort_family_name</replaceable> ]
| FUNCTION <replaceable class="parameter">support_number</replaceable> [ ( <replaceable class="parameter">op_type</replaceable> [ , <replaceable class="parameter">op_type</replaceable> ] ) ]
<replaceable class="parameter">function_name</replaceable> ( <replaceable class="parameter">argument_type</replaceable> [, ...] )
} [, ... ] } [, ... ]
ALTER OPERATOR FAMILY <replaceable>name</replaceable> USING <replaceable class="parameter">index_method</replaceable> DROP ALTER OPERATOR FAMILY <replaceable>name</replaceable> USING <replaceable class="parameter">index_method</replaceable> DROP
{ OPERATOR <replaceable class="parameter">strategy_number</replaceable> ( <replaceable class="parameter">op_type</replaceable> [ , <replaceable class="parameter">op_type</replaceable> ] ) { OPERATOR <replaceable class="parameter">strategy_number</replaceable> ( <replaceable class="parameter">op_type</replaceable> [ , <replaceable class="parameter">op_type</replaceable> ] )
| FUNCTION <replaceable class="parameter">support_number</replaceable> ( <replaceable class="parameter">op_type</replaceable> [ , <replaceable class="parameter">op_type</replaceable> ] ) | FUNCTION <replaceable class="parameter">support_number</replaceable> ( <replaceable class="parameter">op_type</replaceable> [ , <replaceable class="parameter">op_type</replaceable> ] )
} [, ... ] } [, ... ]
ALTER OPERATOR FAMILY <replaceable>name</replaceable> USING <replaceable class="parameter">index_method</replaceable> RENAME TO <replaceable>new_name</replaceable>
ALTER OPERATOR FAMILY <replaceable>name</replaceable> USING <replaceable class="parameter">index_method</replaceable> OWNER TO <replaceable>new_owner</replaceable> ALTER OPERATOR FAMILY <replaceable>name</replaceable> USING <replaceable class="parameter">index_method</replaceable>
ALTER OPERATOR FAMILY <replaceable>name</replaceable> USING <replaceable class="parameter">index_method</replaceable> SET SCHEMA <replaceable>new_schema</replaceable> RENAME TO <replaceable>new_name</replaceable>
ALTER OPERATOR FAMILY <replaceable>name</replaceable> USING <replaceable class="parameter">index_method</replaceable>
OWNER TO { <replaceable>new_owner</replaceable> | CURRENT_USER | SESSION_USER }
ALTER OPERATOR FAMILY <replaceable>name</replaceable> USING <replaceable class="parameter">index_method</replaceable>
SET SCHEMA <replaceable>new_schema</replaceable>
</synopsis> </synopsis>
</refsynopsisdiv> </refsynopsisdiv>
......
...@@ -21,7 +21,7 @@ PostgreSQL documentation ...@@ -21,7 +21,7 @@ PostgreSQL documentation
<refsynopsisdiv> <refsynopsisdiv>
<synopsis> <synopsis>
ALTER ROLE <replaceable class="PARAMETER">name</replaceable> [ [ WITH ] <replaceable class="PARAMETER">option</replaceable> [ ... ] ] ALTER ROLE <replaceable class="PARAMETER">role_specification</replaceable> [ WITH ] <replaceable class="PARAMETER">option</replaceable> [ ... ]
<phrase>where <replaceable class="PARAMETER">option</replaceable> can be:</phrase> <phrase>where <replaceable class="PARAMETER">option</replaceable> can be:</phrase>
...@@ -39,10 +39,16 @@ ALTER ROLE <replaceable class="PARAMETER">name</replaceable> [ [ WITH ] <replace ...@@ -39,10 +39,16 @@ ALTER ROLE <replaceable class="PARAMETER">name</replaceable> [ [ WITH ] <replace
ALTER ROLE <replaceable class="PARAMETER">name</replaceable> RENAME TO <replaceable>new_name</replaceable> ALTER ROLE <replaceable class="PARAMETER">name</replaceable> RENAME TO <replaceable>new_name</replaceable>
ALTER ROLE <replaceable class="PARAMETER">name</replaceable> [ IN DATABASE <replaceable class="PARAMETER">database_name</replaceable> ] SET <replaceable>configuration_parameter</replaceable> { TO | = } { <replaceable>value</replaceable> | DEFAULT } ALTER ROLE { <replaceable class="PARAMETER">role_specification</replaceable> | ALL } [ IN DATABASE <replaceable class="PARAMETER">database_name</replaceable> ] SET <replaceable>configuration_parameter</replaceable> { TO | = } { <replaceable>value</replaceable> | DEFAULT }
ALTER ROLE { <replaceable class="PARAMETER">name</replaceable> | ALL } [ IN DATABASE <replaceable class="PARAMETER">database_name</replaceable> ] SET <replaceable>configuration_parameter</replaceable> FROM CURRENT ALTER ROLE { <replaceable class="PARAMETER">role_specification</replaceable> | ALL } [ IN DATABASE <replaceable class="PARAMETER">database_name</replaceable> ] SET <replaceable>configuration_parameter</replaceable> FROM CURRENT
ALTER ROLE { <replaceable class="PARAMETER">name</replaceable> | ALL } [ IN DATABASE <replaceable class="PARAMETER">database_name</replaceable> ] RESET <replaceable>configuration_parameter</replaceable> ALTER ROLE { <replaceable class="PARAMETER">role_specification</replaceable> | ALL } [ IN DATABASE <replaceable class="PARAMETER">database_name</replaceable> ] RESET <replaceable>configuration_parameter</replaceable>
ALTER ROLE { <replaceable class="PARAMETER">name</replaceable> | ALL } [ IN DATABASE <replaceable class="PARAMETER">database_name</replaceable> ] RESET ALL ALTER ROLE { <replaceable class="PARAMETER">role_specification</replaceable> | ALL } [ IN DATABASE <replaceable class="PARAMETER">database_name</replaceable> ] RESET ALL
<phrase>where <replaceable class="PARAMETER">role_specification</replaceable> can be:</phrase>
[ GROUP ] <replaceable class="PARAMETER">role_name</replaceable>
| CURRENT_USER
| SESSION_USER
</synopsis> </synopsis>
</refsynopsisdiv> </refsynopsisdiv>
...@@ -128,6 +134,25 @@ ALTER ROLE { <replaceable class="PARAMETER">name</replaceable> | ALL } [ IN DATA ...@@ -128,6 +134,25 @@ ALTER ROLE { <replaceable class="PARAMETER">name</replaceable> | ALL } [ IN DATA
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term>CURRENT_USER</term>
<listitem>
<para>
Alter the current user instead of an explicitely identified role.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>SESSION_USER</term>
<listitem>
<para>
Alter the current session user instead of an explicitely identified
role.
</para>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term><literal>SUPERUSER</literal></term> <term><literal>SUPERUSER</literal></term>
<term><literal>NOSUPERUSER</literal></term> <term><literal>NOSUPERUSER</literal></term>
......
...@@ -22,7 +22,7 @@ PostgreSQL documentation ...@@ -22,7 +22,7 @@ PostgreSQL documentation
<refsynopsisdiv> <refsynopsisdiv>
<synopsis> <synopsis>
ALTER SCHEMA <replaceable>name</replaceable> RENAME TO <replaceable>new_name</replaceable> ALTER SCHEMA <replaceable>name</replaceable> RENAME TO <replaceable>new_name</replaceable>
ALTER SCHEMA <replaceable>name</replaceable> OWNER TO <replaceable>new_owner</replaceable> ALTER SCHEMA <replaceable>name</replaceable> OWNER TO { <replaceable>new_owner</replaceable> | CURRENT_USER | SESSION_USER }
</synopsis> </synopsis>
</refsynopsisdiv> </refsynopsisdiv>
......
...@@ -29,7 +29,7 @@ ALTER SEQUENCE [ IF EXISTS ] <replaceable class="parameter">name</replaceable> [ ...@@ -29,7 +29,7 @@ ALTER SEQUENCE [ IF EXISTS ] <replaceable class="parameter">name</replaceable> [
[ RESTART [ [ WITH ] <replaceable class="parameter">restart</replaceable> ] ] [ RESTART [ [ WITH ] <replaceable class="parameter">restart</replaceable> ] ]
[ CACHE <replaceable class="parameter">cache</replaceable> ] [ [ NO ] CYCLE ] [ CACHE <replaceable class="parameter">cache</replaceable> ] [ [ NO ] CYCLE ]
[ OWNED BY { <replaceable class="parameter">table_name</replaceable>.<replaceable class="parameter">column_name</replaceable> | NONE } ] [ OWNED BY { <replaceable class="parameter">table_name</replaceable>.<replaceable class="parameter">column_name</replaceable> | NONE } ]
ALTER SEQUENCE [ IF EXISTS ] <replaceable class="parameter">name</replaceable> OWNER TO <replaceable class="PARAMETER">new_owner</replaceable> ALTER SEQUENCE [ IF EXISTS ] <replaceable class="parameter">name</replaceable> OWNER TO { <replaceable class="PARAMETER">new_owner</replaceable> | CURRENT_USER | SESSION_USER }
ALTER SEQUENCE [ IF EXISTS ] <replaceable class="parameter">name</replaceable> RENAME TO <replaceable class="parameter">new_name</replaceable> ALTER SEQUENCE [ IF EXISTS ] <replaceable class="parameter">name</replaceable> RENAME TO <replaceable class="parameter">new_name</replaceable>
ALTER SEQUENCE [ IF EXISTS ] <replaceable class="parameter">name</replaceable> SET SCHEMA <replaceable class="parameter">new_schema</replaceable> ALTER SEQUENCE [ IF EXISTS ] <replaceable class="parameter">name</replaceable> SET SCHEMA <replaceable class="parameter">new_schema</replaceable>
</synopsis> </synopsis>
......
...@@ -23,7 +23,7 @@ PostgreSQL documentation ...@@ -23,7 +23,7 @@ PostgreSQL documentation
<synopsis> <synopsis>
ALTER SERVER <replaceable class="parameter">name</replaceable> [ VERSION '<replaceable class="parameter">new_version</replaceable>' ] ALTER SERVER <replaceable class="parameter">name</replaceable> [ VERSION '<replaceable class="parameter">new_version</replaceable>' ]
[ OPTIONS ( [ ADD | SET | DROP ] <replaceable class="PARAMETER">option</replaceable> ['<replaceable class="PARAMETER">value</replaceable>'] [, ... ] ) ] [ OPTIONS ( [ ADD | SET | DROP ] <replaceable class="PARAMETER">option</replaceable> ['<replaceable class="PARAMETER">value</replaceable>'] [, ... ] ) ]
ALTER SERVER <replaceable class="PARAMETER">name</replaceable> OWNER TO <replaceable>new_owner</replaceable> ALTER SERVER <replaceable class="PARAMETER">name</replaceable> OWNER TO { <replaceable>new_owner</replaceable> | CURRENT_USER | SESSION_USER }
ALTER SERVER <replaceable class="PARAMETER">name</replaceable> RENAME TO <replaceable>new_name</replaceable> ALTER SERVER <replaceable class="PARAMETER">name</replaceable> RENAME TO <replaceable>new_name</replaceable>
</synopsis> </synopsis>
</refsynopsisdiv> </refsynopsisdiv>
......
...@@ -73,7 +73,7 @@ ALTER TABLE ALL IN TABLESPACE <replaceable class="PARAMETER">name</replaceable> ...@@ -73,7 +73,7 @@ ALTER TABLE ALL IN TABLESPACE <replaceable class="PARAMETER">name</replaceable>
NO INHERIT <replaceable class="PARAMETER">parent_table</replaceable> NO INHERIT <replaceable class="PARAMETER">parent_table</replaceable>
OF <replaceable class="PARAMETER">type_name</replaceable> OF <replaceable class="PARAMETER">type_name</replaceable>
NOT OF NOT OF
OWNER TO <replaceable class="PARAMETER">new_owner</replaceable> OWNER TO { <replaceable class="PARAMETER">new_owner</replaceable> | CURRENT_USER | SESSION_USER }
REPLICA IDENTITY {DEFAULT | USING INDEX <replaceable class="PARAMETER">index_name</replaceable> | FULL | NOTHING} REPLICA IDENTITY {DEFAULT | USING INDEX <replaceable class="PARAMETER">index_name</replaceable> | FULL | NOTHING}
<phrase>and <replaceable class="PARAMETER">table_constraint_using_index</replaceable> is:</phrase> <phrase>and <replaceable class="PARAMETER">table_constraint_using_index</replaceable> is:</phrase>
......
...@@ -22,7 +22,7 @@ PostgreSQL documentation ...@@ -22,7 +22,7 @@ PostgreSQL documentation
<refsynopsisdiv> <refsynopsisdiv>
<synopsis> <synopsis>
ALTER TABLESPACE <replaceable>name</replaceable> RENAME TO <replaceable>new_name</replaceable> ALTER TABLESPACE <replaceable>name</replaceable> RENAME TO <replaceable>new_name</replaceable>
ALTER TABLESPACE <replaceable>name</replaceable> OWNER TO <replaceable>new_owner</replaceable> ALTER TABLESPACE <replaceable>name</replaceable> OWNER TO { <replaceable>new_owner</replaceable> | CURRENT_USER | SESSION_USER }
ALTER TABLESPACE <replaceable>name</replaceable> SET ( <replaceable class="PARAMETER">tablespace_option</replaceable> = <replaceable class="PARAMETER">value</replaceable> [, ... ] ) ALTER TABLESPACE <replaceable>name</replaceable> SET ( <replaceable class="PARAMETER">tablespace_option</replaceable> = <replaceable class="PARAMETER">value</replaceable> [, ... ] )
ALTER TABLESPACE <replaceable>name</replaceable> RESET ( <replaceable class="PARAMETER">tablespace_option</replaceable> [, ... ] ) ALTER TABLESPACE <replaceable>name</replaceable> RESET ( <replaceable class="PARAMETER">tablespace_option</replaceable> [, ... ] )
</synopsis> </synopsis>
......
...@@ -32,7 +32,7 @@ ALTER TEXT SEARCH CONFIGURATION <replaceable>name</replaceable> ...@@ -32,7 +32,7 @@ ALTER TEXT SEARCH CONFIGURATION <replaceable>name</replaceable>
ALTER TEXT SEARCH CONFIGURATION <replaceable>name</replaceable> ALTER TEXT SEARCH CONFIGURATION <replaceable>name</replaceable>
DROP MAPPING [ IF EXISTS ] FOR <replaceable class="parameter">token_type</replaceable> [, ... ] DROP MAPPING [ IF EXISTS ] FOR <replaceable class="parameter">token_type</replaceable> [, ... ]
ALTER TEXT SEARCH CONFIGURATION <replaceable>name</replaceable> RENAME TO <replaceable>new_name</replaceable> ALTER TEXT SEARCH CONFIGURATION <replaceable>name</replaceable> RENAME TO <replaceable>new_name</replaceable>
ALTER TEXT SEARCH CONFIGURATION <replaceable>name</replaceable> OWNER TO <replaceable>new_owner</replaceable> ALTER TEXT SEARCH CONFIGURATION <replaceable>name</replaceable> OWNER TO { <replaceable>new_owner</replaceable> | CURRENT_USER | SESSION_USER }
ALTER TEXT SEARCH CONFIGURATION <replaceable>name</replaceable> SET SCHEMA <replaceable>new_schema</replaceable> ALTER TEXT SEARCH CONFIGURATION <replaceable>name</replaceable> SET SCHEMA <replaceable>new_schema</replaceable>
</synopsis> </synopsis>
</refsynopsisdiv> </refsynopsisdiv>
......
...@@ -25,7 +25,7 @@ ALTER TEXT SEARCH DICTIONARY <replaceable>name</replaceable> ( ...@@ -25,7 +25,7 @@ ALTER TEXT SEARCH DICTIONARY <replaceable>name</replaceable> (
<replaceable class="parameter">option</replaceable> [ = <replaceable class="parameter">value</replaceable> ] [, ... ] <replaceable class="parameter">option</replaceable> [ = <replaceable class="parameter">value</replaceable> ] [, ... ]
) )
ALTER TEXT SEARCH DICTIONARY <replaceable>name</replaceable> RENAME TO <replaceable>new_name</replaceable> ALTER TEXT SEARCH DICTIONARY <replaceable>name</replaceable> RENAME TO <replaceable>new_name</replaceable>
ALTER TEXT SEARCH DICTIONARY <replaceable>name</replaceable> OWNER TO <replaceable>new_owner</replaceable> ALTER TEXT SEARCH DICTIONARY <replaceable>name</replaceable> OWNER TO { <replaceable>new_owner</replaceable> | CURRENT_USER | SESSION_USER }
ALTER TEXT SEARCH DICTIONARY <replaceable>name</replaceable> SET SCHEMA <replaceable>new_schema</replaceable> ALTER TEXT SEARCH DICTIONARY <replaceable>name</replaceable> SET SCHEMA <replaceable>new_schema</replaceable>
</synopsis> </synopsis>
</refsynopsisdiv> </refsynopsisdiv>
......
...@@ -24,7 +24,7 @@ PostgreSQL documentation ...@@ -24,7 +24,7 @@ PostgreSQL documentation
<refsynopsisdiv> <refsynopsisdiv>
<synopsis> <synopsis>
ALTER TYPE <replaceable class="PARAMETER">name</replaceable> <replaceable class="PARAMETER">action</replaceable> [, ... ] ALTER TYPE <replaceable class="PARAMETER">name</replaceable> <replaceable class="PARAMETER">action</replaceable> [, ... ]
ALTER TYPE <replaceable class="PARAMETER">name</replaceable> OWNER TO <replaceable class="PARAMETER">new_owner</replaceable> ALTER TYPE <replaceable class="PARAMETER">name</replaceable> OWNER TO { <replaceable class="PARAMETER">new_owner</replaceable> | CURRENT_USER | SESSION_USER }
ALTER TYPE <replaceable class="PARAMETER">name</replaceable> RENAME ATTRIBUTE <replaceable class="PARAMETER">attribute_name</replaceable> TO <replaceable class="PARAMETER">new_attribute_name</replaceable> [ CASCADE | RESTRICT ] ALTER TYPE <replaceable class="PARAMETER">name</replaceable> RENAME ATTRIBUTE <replaceable class="PARAMETER">attribute_name</replaceable> TO <replaceable class="PARAMETER">new_attribute_name</replaceable> [ CASCADE | RESTRICT ]
ALTER TYPE <replaceable class="PARAMETER">name</replaceable> RENAME TO <replaceable class="PARAMETER">new_name</replaceable> ALTER TYPE <replaceable class="PARAMETER">name</replaceable> RENAME TO <replaceable class="PARAMETER">new_name</replaceable>
ALTER TYPE <replaceable class="PARAMETER">name</replaceable> SET SCHEMA <replaceable class="PARAMETER">new_schema</replaceable> ALTER TYPE <replaceable class="PARAMETER">name</replaceable> SET SCHEMA <replaceable class="PARAMETER">new_schema</replaceable>
......
...@@ -21,7 +21,7 @@ PostgreSQL documentation ...@@ -21,7 +21,7 @@ PostgreSQL documentation
<refsynopsisdiv> <refsynopsisdiv>
<synopsis> <synopsis>
ALTER USER <replaceable class="PARAMETER">name</replaceable> [ [ WITH ] <replaceable class="PARAMETER">option</replaceable> [ ... ] ] ALTER USER <replaceable class="PARAMETER">role_specification</replaceable> [ WITH ] <replaceable class="PARAMETER">option</replaceable> [ ... ]
<phrase>where <replaceable class="PARAMETER">option</replaceable> can be:</phrase> <phrase>where <replaceable class="PARAMETER">option</replaceable> can be:</phrase>
...@@ -38,10 +38,16 @@ ALTER USER <replaceable class="PARAMETER">name</replaceable> [ [ WITH ] <replace ...@@ -38,10 +38,16 @@ ALTER USER <replaceable class="PARAMETER">name</replaceable> [ [ WITH ] <replace
ALTER USER <replaceable class="PARAMETER">name</replaceable> RENAME TO <replaceable>new_name</replaceable> ALTER USER <replaceable class="PARAMETER">name</replaceable> RENAME TO <replaceable>new_name</replaceable>
ALTER USER <replaceable class="PARAMETER">name</replaceable> SET <replaceable>configuration_parameter</replaceable> { TO | = } { <replaceable>value</replaceable> | DEFAULT } ALTER USER <replaceable class="PARAMETER">role_specification</replaceable> SET <replaceable>configuration_parameter</replaceable> { TO | = } { <replaceable>value</replaceable> | DEFAULT }
ALTER USER <replaceable class="PARAMETER">name</replaceable> SET <replaceable>configuration_parameter</replaceable> FROM CURRENT ALTER USER <replaceable class="PARAMETER">role_specification</replaceable> SET <replaceable>configuration_parameter</replaceable> FROM CURRENT
ALTER USER <replaceable class="PARAMETER">name</replaceable> RESET <replaceable>configuration_parameter</replaceable> ALTER USER <replaceable class="PARAMETER">role_specification</replaceable> RESET <replaceable>configuration_parameter</replaceable>
ALTER USER <replaceable class="PARAMETER">name</replaceable> RESET ALL ALTER USER <replaceable class="PARAMETER">role_specification</replaceable> RESET ALL
<phrase>where <replaceable class="PARAMETER">role_specification</replaceable> can be:</phrase>
[ GROUP ] <replaceable class="PARAMETER">role_name</replaceable>
| CURRENT_USER
| SESSION_USER
</synopsis> </synopsis>
</refsynopsisdiv> </refsynopsisdiv>
......
...@@ -21,7 +21,7 @@ PostgreSQL documentation ...@@ -21,7 +21,7 @@ PostgreSQL documentation
<refsynopsisdiv> <refsynopsisdiv>
<synopsis> <synopsis>
ALTER USER MAPPING FOR { <replaceable class="parameter">user_name</replaceable> | USER | CURRENT_USER | PUBLIC } ALTER USER MAPPING FOR { <replaceable class="parameter">user_name</replaceable> | USER | CURRENT_USER | SESSION_USER | PUBLIC }
SERVER <replaceable class="parameter">server_name</replaceable> SERVER <replaceable class="parameter">server_name</replaceable>
OPTIONS ( [ ADD | SET | DROP ] <replaceable class="PARAMETER">option</replaceable> ['<replaceable class="PARAMETER">value</replaceable>'] [, ... ] ) OPTIONS ( [ ADD | SET | DROP ] <replaceable class="PARAMETER">option</replaceable> ['<replaceable class="PARAMETER">value</replaceable>'] [, ... ] )
</synopsis> </synopsis>
......
...@@ -23,7 +23,7 @@ PostgreSQL documentation ...@@ -23,7 +23,7 @@ PostgreSQL documentation
<synopsis> <synopsis>
ALTER VIEW [ IF EXISTS ] <replaceable class="parameter">name</replaceable> ALTER [ COLUMN ] <replaceable class="PARAMETER">column_name</replaceable> SET DEFAULT <replaceable class="PARAMETER">expression</replaceable> ALTER VIEW [ IF EXISTS ] <replaceable class="parameter">name</replaceable> ALTER [ COLUMN ] <replaceable class="PARAMETER">column_name</replaceable> SET DEFAULT <replaceable class="PARAMETER">expression</replaceable>
ALTER VIEW [ IF EXISTS ] <replaceable class="parameter">name</replaceable> ALTER [ COLUMN ] <replaceable class="PARAMETER">column_name</replaceable> DROP DEFAULT ALTER VIEW [ IF EXISTS ] <replaceable class="parameter">name</replaceable> ALTER [ COLUMN ] <replaceable class="PARAMETER">column_name</replaceable> DROP DEFAULT
ALTER VIEW [ IF EXISTS ] <replaceable class="parameter">name</replaceable> OWNER TO <replaceable class="PARAMETER">new_owner</replaceable> ALTER VIEW [ IF EXISTS ] <replaceable class="parameter">name</replaceable> OWNER TO { <replaceable class="PARAMETER">new_owner</replaceable> | CURRENT_USER | SESSION_USER }
ALTER VIEW [ IF EXISTS ] <replaceable class="parameter">name</replaceable> RENAME TO <replaceable class="parameter">new_name</replaceable> ALTER VIEW [ IF EXISTS ] <replaceable class="parameter">name</replaceable> RENAME TO <replaceable class="parameter">new_name</replaceable>
ALTER VIEW [ IF EXISTS ] <replaceable class="parameter">name</replaceable> SET SCHEMA <replaceable class="parameter">new_schema</replaceable> ALTER VIEW [ IF EXISTS ] <replaceable class="parameter">name</replaceable> SET SCHEMA <replaceable class="parameter">new_schema</replaceable>
ALTER VIEW [ IF EXISTS ] <replaceable class="parameter">name</replaceable> SET ( <replaceable class="parameter">view_option_name</replaceable> [= <replaceable class="parameter">view_option_value</replaceable>] [, ... ] ) ALTER VIEW [ IF EXISTS ] <replaceable class="parameter">name</replaceable> SET ( <replaceable class="parameter">view_option_name</replaceable> [= <replaceable class="parameter">view_option_value</replaceable>] [, ... ] )
......
...@@ -21,10 +21,16 @@ PostgreSQL documentation ...@@ -21,10 +21,16 @@ PostgreSQL documentation
<refsynopsisdiv> <refsynopsisdiv>
<synopsis> <synopsis>
CREATE SCHEMA <replaceable class="parameter">schema_name</replaceable> [ AUTHORIZATION <replaceable class="parameter">user_name</replaceable> ] [ <replaceable class="parameter">schema_element</replaceable> [ ... ] ] CREATE SCHEMA <replaceable class="parameter">schema_name</replaceable> [ AUTHORIZATION <replaceable class="PARAMETER">role_specification</replaceable> ] [ <replaceable class="parameter">schema_element</replaceable> [ ... ] ]
CREATE SCHEMA AUTHORIZATION <replaceable class="parameter">user_name</replaceable> [ <replaceable class="parameter">schema_element</replaceable> [ ... ] ] CREATE SCHEMA AUTHORIZATION <replaceable class="PARAMETER">role_specification</replaceable> [ <replaceable class="parameter">schema_element</replaceable> [ ... ] ]
CREATE SCHEMA IF NOT EXISTS <replaceable class="parameter">schema_name</replaceable> [ AUTHORIZATION <replaceable class="parameter">user_name</replaceable> ] CREATE SCHEMA IF NOT EXISTS <replaceable class="parameter">schema_name</replaceable> [ AUTHORIZATION <replaceable class="PARAMETER">role_specification</replaceable> ]
CREATE SCHEMA IF NOT EXISTS AUTHORIZATION <replaceable class="parameter">user_name</replaceable> CREATE SCHEMA IF NOT EXISTS AUTHORIZATION <replaceable class="PARAMETER">role_specification</replaceable>
<phrase>where <replaceable class="PARAMETER">role_specification</replaceable> can be:</phrase>
[ GROUP ] <replaceable class="PARAMETER">user_name</replaceable>
| CURRENT_USER
| SESSION_USER
</synopsis> </synopsis>
</refsynopsisdiv> </refsynopsisdiv>
......
...@@ -25,59 +25,66 @@ GRANT { { SELECT | INSERT | UPDATE | DELETE | TRUNCATE | REFERENCES | TRIGGER } ...@@ -25,59 +25,66 @@ GRANT { { SELECT | INSERT | UPDATE | DELETE | TRUNCATE | REFERENCES | TRIGGER }
[, ...] | ALL [ PRIVILEGES ] } [, ...] | ALL [ PRIVILEGES ] }
ON { [ TABLE ] <replaceable class="PARAMETER">table_name</replaceable> [, ...] ON { [ TABLE ] <replaceable class="PARAMETER">table_name</replaceable> [, ...]
| ALL TABLES IN SCHEMA <replaceable class="PARAMETER">schema_name</replaceable> [, ...] } | ALL TABLES IN SCHEMA <replaceable class="PARAMETER">schema_name</replaceable> [, ...] }
TO { [ GROUP ] <replaceable class="PARAMETER">role_name</replaceable> | PUBLIC } [, ...] [ WITH GRANT OPTION ] TO <replaceable class="PARAMETER">role_specification</replaceable> [, ...] [ WITH GRANT OPTION ]
GRANT { { SELECT | INSERT | UPDATE | REFERENCES } ( <replaceable class="PARAMETER">column_name</replaceable> [, ...] ) GRANT { { SELECT | INSERT | UPDATE | REFERENCES } ( <replaceable class="PARAMETER">column_name</replaceable> [, ...] )
[, ...] | ALL [ PRIVILEGES ] ( <replaceable class="PARAMETER">column_name</replaceable> [, ...] ) } [, ...] | ALL [ PRIVILEGES ] ( <replaceable class="PARAMETER">column_name</replaceable> [, ...] ) }
ON [ TABLE ] <replaceable class="PARAMETER">table_name</replaceable> [, ...] ON [ TABLE ] <replaceable class="PARAMETER">table_name</replaceable> [, ...]
TO { [ GROUP ] <replaceable class="PARAMETER">role_name</replaceable> | PUBLIC } [, ...] [ WITH GRANT OPTION ] TO <replaceable class="PARAMETER">role_specification</replaceable> [, ...] [ WITH GRANT OPTION ]
GRANT { { USAGE | SELECT | UPDATE } GRANT { { USAGE | SELECT | UPDATE }
[, ...] | ALL [ PRIVILEGES ] } [, ...] | ALL [ PRIVILEGES ] }
ON { SEQUENCE <replaceable class="PARAMETER">sequence_name</replaceable> [, ...] ON { SEQUENCE <replaceable class="PARAMETER">sequence_name</replaceable> [, ...]
| ALL SEQUENCES IN SCHEMA <replaceable class="PARAMETER">schema_name</replaceable> [, ...] } | ALL SEQUENCES IN SCHEMA <replaceable class="PARAMETER">schema_name</replaceable> [, ...] }
TO { [ GROUP ] <replaceable class="PARAMETER">role_name</replaceable> | PUBLIC } [, ...] [ WITH GRANT OPTION ] TO <replaceable class="PARAMETER">role_specification</replaceable> [, ...] [ WITH GRANT OPTION ]
GRANT { { CREATE | CONNECT | TEMPORARY | TEMP } [, ...] | ALL [ PRIVILEGES ] } GRANT { { CREATE | CONNECT | TEMPORARY | TEMP } [, ...] | ALL [ PRIVILEGES ] }
ON DATABASE <replaceable>database_name</replaceable> [, ...] ON DATABASE <replaceable>database_name</replaceable> [, ...]
TO { [ GROUP ] <replaceable class="PARAMETER">role_name</replaceable> | PUBLIC } [, ...] [ WITH GRANT OPTION ] TO <replaceable class="PARAMETER">role_specification</replaceable> [, ...] [ WITH GRANT OPTION ]
GRANT { USAGE | ALL [ PRIVILEGES ] } GRANT { USAGE | ALL [ PRIVILEGES ] }
ON DOMAIN <replaceable>domain_name</replaceable> [, ...] ON DOMAIN <replaceable>domain_name</replaceable> [, ...]
TO { [ GROUP ] <replaceable class="PARAMETER">role_name</replaceable> | PUBLIC } [, ...] [ WITH GRANT OPTION ] TO <replaceable class="PARAMETER">role_specification</replaceable> [, ...] [ WITH GRANT OPTION ]
GRANT { USAGE | ALL [ PRIVILEGES ] } GRANT { USAGE | ALL [ PRIVILEGES ] }
ON FOREIGN DATA WRAPPER <replaceable>fdw_name</replaceable> [, ...] ON FOREIGN DATA WRAPPER <replaceable>fdw_name</replaceable> [, ...]
TO { [ GROUP ] <replaceable class="PARAMETER">role_name</replaceable> | PUBLIC } [, ...] [ WITH GRANT OPTION ] TO <replaceable class="PARAMETER">role_specification</replaceable> [, ...] [ WITH GRANT OPTION ]
GRANT { USAGE | ALL [ PRIVILEGES ] } GRANT { USAGE | ALL [ PRIVILEGES ] }
ON FOREIGN SERVER <replaceable>server_name</replaceable> [, ...] ON FOREIGN SERVER <replaceable>server_name</replaceable> [, ...]
TO { [ GROUP ] <replaceable class="PARAMETER">role_name</replaceable> | PUBLIC } [, ...] [ WITH GRANT OPTION ] TO <replaceable class="PARAMETER">role_specification</replaceable> [, ...] [ WITH GRANT OPTION ]
GRANT { EXECUTE | ALL [ PRIVILEGES ] } GRANT { EXECUTE | ALL [ PRIVILEGES ] }
ON { FUNCTION <replaceable>function_name</replaceable> ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">arg_name</replaceable> ] <replaceable class="parameter">arg_type</replaceable> [, ...] ] ) [, ...] ON { FUNCTION <replaceable>function_name</replaceable> ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">arg_name</replaceable> ] <replaceable class="parameter">arg_type</replaceable> [, ...] ] ) [, ...]
| ALL FUNCTIONS IN SCHEMA <replaceable class="PARAMETER">schema_name</replaceable> [, ...] } | ALL FUNCTIONS IN SCHEMA <replaceable class="PARAMETER">schema_name</replaceable> [, ...] }
TO { [ GROUP ] <replaceable class="PARAMETER">role_name</replaceable> | PUBLIC } [, ...] [ WITH GRANT OPTION ] TO <replaceable class="PARAMETER">role_specification</replaceable> [, ...] [ WITH GRANT OPTION ]
GRANT { USAGE | ALL [ PRIVILEGES ] } GRANT { USAGE | ALL [ PRIVILEGES ] }
ON LANGUAGE <replaceable>lang_name</replaceable> [, ...] ON LANGUAGE <replaceable>lang_name</replaceable> [, ...]
TO { [ GROUP ] <replaceable class="PARAMETER">role_name</replaceable> | PUBLIC } [, ...] [ WITH GRANT OPTION ] TO <replaceable class="PARAMETER">role_specification</replaceable> [, ...] [ WITH GRANT OPTION ]
GRANT { { SELECT | UPDATE } [, ...] | ALL [ PRIVILEGES ] } GRANT { { SELECT | UPDATE } [, ...] | ALL [ PRIVILEGES ] }
ON LARGE OBJECT <replaceable class="PARAMETER">loid</replaceable> [, ...] ON LARGE OBJECT <replaceable class="PARAMETER">loid</replaceable> [, ...]
TO { [ GROUP ] <replaceable class="PARAMETER">role_name</replaceable> | PUBLIC } [, ...] [ WITH GRANT OPTION ] TO <replaceable class="PARAMETER">role_specification</replaceable> [, ...] [ WITH GRANT OPTION ]
GRANT { { CREATE | USAGE } [, ...] | ALL [ PRIVILEGES ] } GRANT { { CREATE | USAGE } [, ...] | ALL [ PRIVILEGES ] }
ON SCHEMA <replaceable>schema_name</replaceable> [, ...] ON SCHEMA <replaceable>schema_name</replaceable> [, ...]
TO { [ GROUP ] <replaceable class="PARAMETER">role_name</replaceable> | PUBLIC } [, ...] [ WITH GRANT OPTION ] TO <replaceable class="PARAMETER">role_specification</replaceable> [, ...] [ WITH GRANT OPTION ]
GRANT { CREATE | ALL [ PRIVILEGES ] } GRANT { CREATE | ALL [ PRIVILEGES ] }
ON TABLESPACE <replaceable>tablespace_name</replaceable> [, ...] ON TABLESPACE <replaceable>tablespace_name</replaceable> [, ...]
TO { [ GROUP ] <replaceable class="PARAMETER">role_name</replaceable> | PUBLIC } [, ...] [ WITH GRANT OPTION ] TO <replaceable class="PARAMETER">role_specification</replaceable> [, ...] [ WITH GRANT OPTION ]
GRANT { USAGE | ALL [ PRIVILEGES ] } GRANT { USAGE | ALL [ PRIVILEGES ] }
ON TYPE <replaceable>type_name</replaceable> [, ...] ON TYPE <replaceable>type_name</replaceable> [, ...]
TO { [ GROUP ] <replaceable class="PARAMETER">role_name</replaceable> | PUBLIC } [, ...] [ WITH GRANT OPTION ] TO <replaceable class="PARAMETER">role_specification</replaceable> [, ...] [ WITH GRANT OPTION ]
<phrase>where <replaceable class="PARAMETER">role_specification</replaceable> can be:</phrase>
[ GROUP ] <replaceable class="PARAMETER">role_name</replaceable>
| PUBLIC
| CURRENT_USER
| SESSION_USER
GRANT <replaceable class="PARAMETER">role_name</replaceable> [, ...] TO <replaceable class="PARAMETER">role_name</replaceable> [, ...] [ WITH ADMIN OPTION ] GRANT <replaceable class="PARAMETER">role_name</replaceable> [, ...] TO <replaceable class="PARAMETER">role_name</replaceable> [, ...] [ WITH ADMIN OPTION ]
</synopsis> </synopsis>
......
...@@ -421,22 +421,25 @@ ExecuteGrantStmt(GrantStmt *stmt) ...@@ -421,22 +421,25 @@ ExecuteGrantStmt(GrantStmt *stmt)
istmt.behavior = stmt->behavior; istmt.behavior = stmt->behavior;
/* /*
* Convert the PrivGrantee list into an Oid list. Note that at this point * Convert the RoleSpec list into an Oid list. Note that at this point
* we insert an ACL_ID_PUBLIC into the list if an empty role name is * we insert an ACL_ID_PUBLIC into the list if appropriate, so downstream
* detected (which is what the grammar uses if PUBLIC is found), so * there shouldn't be any additional work needed to support this case.
* downstream there shouldn't be any additional work needed to support
* this case.
*/ */
foreach(cell, stmt->grantees) foreach(cell, stmt->grantees)
{ {
PrivGrantee *grantee = (PrivGrantee *) lfirst(cell); RoleSpec *grantee = (RoleSpec *) lfirst(cell);
Oid grantee_uid;
if (grantee->rolname == NULL) switch (grantee->roletype)
istmt.grantees = lappend_oid(istmt.grantees, ACL_ID_PUBLIC); {
else case ROLESPEC_PUBLIC:
istmt.grantees = grantee_uid = ACL_ID_PUBLIC;
lappend_oid(istmt.grantees, break;
get_role_oid(grantee->rolname, false)); default:
grantee_uid = get_rolespec_oid((Node *) grantee, false);
break;
}
istmt.grantees = lappend_oid(istmt.grantees, grantee_uid);
} }
/* /*
...@@ -904,22 +907,25 @@ ExecAlterDefaultPrivilegesStmt(AlterDefaultPrivilegesStmt *stmt) ...@@ -904,22 +907,25 @@ ExecAlterDefaultPrivilegesStmt(AlterDefaultPrivilegesStmt *stmt)
iacls.behavior = action->behavior; iacls.behavior = action->behavior;
/* /*
* Convert the PrivGrantee list into an Oid list. Note that at this point * Convert the RoleSpec list into an Oid list. Note that at this point
* we insert an ACL_ID_PUBLIC into the list if an empty role name is * we insert an ACL_ID_PUBLIC into the list if appropriate, so downstream
* detected (which is what the grammar uses if PUBLIC is found), so * there shouldn't be any additional work needed to support this case.
* downstream there shouldn't be any additional work needed to support
* this case.
*/ */
foreach(cell, action->grantees) foreach(cell, action->grantees)
{ {
PrivGrantee *grantee = (PrivGrantee *) lfirst(cell); RoleSpec *grantee = (RoleSpec *) lfirst(cell);
Oid grantee_uid;
if (grantee->rolname == NULL) switch (grantee->roletype)
iacls.grantees = lappend_oid(iacls.grantees, ACL_ID_PUBLIC); {
else case ROLESPEC_PUBLIC:
iacls.grantees = grantee_uid = ACL_ID_PUBLIC;
lappend_oid(iacls.grantees, break;
get_role_oid(grantee->rolname, false)); default:
grantee_uid = get_rolespec_oid((Node *) grantee, false);
break;
}
iacls.grantees = lappend_oid(iacls.grantees, grantee_uid);
} }
/* /*
......
...@@ -699,7 +699,7 @@ AlterObjectNamespace_internal(Relation rel, Oid objid, Oid nspOid) ...@@ -699,7 +699,7 @@ AlterObjectNamespace_internal(Relation rel, Oid objid, Oid nspOid)
ObjectAddress ObjectAddress
ExecAlterOwnerStmt(AlterOwnerStmt *stmt) ExecAlterOwnerStmt(AlterOwnerStmt *stmt)
{ {
Oid newowner = get_role_oid(stmt->newowner, false); Oid newowner = get_rolespec_oid(stmt->newowner, false);
switch (stmt->objectType) switch (stmt->objectType)
{ {
......
...@@ -1371,7 +1371,7 @@ CreateExtension(CreateExtensionStmt *stmt) ...@@ -1371,7 +1371,7 @@ CreateExtension(CreateExtensionStmt *stmt)
CreateSchemaStmt *csstmt = makeNode(CreateSchemaStmt); CreateSchemaStmt *csstmt = makeNode(CreateSchemaStmt);
csstmt->schemaname = schemaName; csstmt->schemaname = schemaName;
csstmt->authid = NULL; /* will be created by current user */ csstmt->authrole = NULL; /* will be created by current user */
csstmt->schemaElts = NIL; csstmt->schemaElts = NIL;
csstmt->if_not_exists = false; csstmt->if_not_exists = false;
CreateSchemaCommand(csstmt, NULL); CreateSchemaCommand(csstmt, NULL);
......
...@@ -197,24 +197,6 @@ transformGenericOptions(Oid catalogId, ...@@ -197,24 +197,6 @@ transformGenericOptions(Oid catalogId,
} }
/*
* Convert the user mapping user name to OID
*/
static Oid
GetUserOidFromMapping(const char *username, bool missing_ok)
{
if (!username)
/* PUBLIC user mapping */
return InvalidOid;
if (strcmp(username, "current_user") == 0)
/* map to the owner */
return GetUserId();
/* map to provided user */
return get_role_oid(username, missing_ok);
}
/* /*
* Internal workhorse for changing a data wrapper's owner. * Internal workhorse for changing a data wrapper's owner.
* *
...@@ -1156,10 +1138,14 @@ CreateUserMapping(CreateUserMappingStmt *stmt) ...@@ -1156,10 +1138,14 @@ CreateUserMapping(CreateUserMappingStmt *stmt)
ObjectAddress referenced; ObjectAddress referenced;
ForeignServer *srv; ForeignServer *srv;
ForeignDataWrapper *fdw; ForeignDataWrapper *fdw;
RoleSpec *role = (RoleSpec *) stmt->user;
rel = heap_open(UserMappingRelationId, RowExclusiveLock); rel = heap_open(UserMappingRelationId, RowExclusiveLock);
useId = GetUserOidFromMapping(stmt->username, false); if (role->roletype == ROLESPEC_PUBLIC)
useId = ACL_ID_PUBLIC;
else
useId = get_rolespec_oid(stmt->user, false);
/* Check that the server exists. */ /* Check that the server exists. */
srv = GetForeignServerByName(stmt->servername, false); srv = GetForeignServerByName(stmt->servername, false);
...@@ -1252,10 +1238,15 @@ AlterUserMapping(AlterUserMappingStmt *stmt) ...@@ -1252,10 +1238,15 @@ AlterUserMapping(AlterUserMappingStmt *stmt)
Oid umId; Oid umId;
ForeignServer *srv; ForeignServer *srv;
ObjectAddress address; ObjectAddress address;
RoleSpec *role = (RoleSpec *) stmt->user;
rel = heap_open(UserMappingRelationId, RowExclusiveLock); rel = heap_open(UserMappingRelationId, RowExclusiveLock);
useId = GetUserOidFromMapping(stmt->username, false); if (role->roletype == ROLESPEC_PUBLIC)
useId = ACL_ID_PUBLIC;
else
useId = get_rolespec_oid(stmt->user, false);
srv = GetForeignServerByName(stmt->servername, false); srv = GetForeignServerByName(stmt->servername, false);
umId = GetSysCacheOid2(USERMAPPINGUSERSERVER, umId = GetSysCacheOid2(USERMAPPINGUSERSERVER,
...@@ -1338,20 +1329,27 @@ RemoveUserMapping(DropUserMappingStmt *stmt) ...@@ -1338,20 +1329,27 @@ RemoveUserMapping(DropUserMappingStmt *stmt)
Oid useId; Oid useId;
Oid umId; Oid umId;
ForeignServer *srv; ForeignServer *srv;
RoleSpec *role = (RoleSpec *) stmt->user;
useId = GetUserOidFromMapping(stmt->username, stmt->missing_ok); if (role->roletype == ROLESPEC_PUBLIC)
srv = GetForeignServerByName(stmt->servername, true); useId = ACL_ID_PUBLIC;
else
if (stmt->username && !OidIsValid(useId))
{ {
/* useId = get_rolespec_oid(stmt->user, stmt->missing_ok);
* IF EXISTS specified, role not found and not public. Notice this and if (!OidIsValid(useId))
* leave. {
*/ /*
elog(NOTICE, "role \"%s\" does not exist, skipping", stmt->username); * IF EXISTS specified, role not found and not public. Notice this
return InvalidOid; * and leave.
*/
elog(NOTICE, "role \"%s\" does not exist, skipping",
role->rolename);
return InvalidOid;
}
} }
srv = GetForeignServerByName(stmt->servername, true);
if (!srv) if (!srv)
{ {
if (!stmt->missing_ok) if (!stmt->missing_ok)
......
...@@ -129,13 +129,7 @@ parse_policy_command(const char *cmd_name) ...@@ -129,13 +129,7 @@ parse_policy_command(const char *cmd_name)
/* /*
* policy_role_list_to_array * policy_role_list_to_array
* helper function to convert a list of role names in to an array of * helper function to convert a list of RoleSpecs to an array of role ids.
* role ids.
*
* Note: If PUBLIC is provided as a role name, then ACL_ID_PUBLIC is
* used as the role id.
*
* roles - the list of role names to convert.
*/ */
static ArrayType * static ArrayType *
policy_role_list_to_array(List *roles) policy_role_list_to_array(List *roles)
...@@ -162,25 +156,25 @@ policy_role_list_to_array(List *roles) ...@@ -162,25 +156,25 @@ policy_role_list_to_array(List *roles)
foreach(cell, roles) foreach(cell, roles)
{ {
Oid roleid = get_role_oid_or_public(strVal(lfirst(cell))); RoleSpec *spec = lfirst(cell);
/* /*
* PUBLIC covers all roles, so it only makes sense alone. * PUBLIC covers all roles, so it only makes sense alone.
*/ */
if (roleid == ACL_ID_PUBLIC) if (spec->roletype == ROLESPEC_PUBLIC)
{ {
if (num_roles != 1) if (num_roles != 1)
ereport(WARNING, ereport(WARNING,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE), (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("ignoring roles specified other than public"), errmsg("ignoring roles specified other than public"),
errhint("All roles are members of the public role."))); errhint("All roles are members of the public role.")));
temp_array[0] = ObjectIdGetDatum(ACL_ID_PUBLIC);
temp_array[0] = ObjectIdGetDatum(roleid);
num_roles = 1; num_roles = 1;
break; break;
} }
else else
temp_array[i++] = ObjectIdGetDatum(roleid); temp_array[i++] =
ObjectIdGetDatum(get_rolespec_oid((Node *) spec, false));
} }
role_ids = construct_array(temp_array, num_roles, OIDOID, sizeof(Oid), true, role_ids = construct_array(temp_array, num_roles, OIDOID, sizeof(Oid), true,
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "catalog/dependency.h" #include "catalog/dependency.h"
#include "catalog/indexing.h" #include "catalog/indexing.h"
#include "catalog/namespace.h" #include "catalog/namespace.h"
#include "catalog/pg_authid.h"
#include "catalog/objectaccess.h" #include "catalog/objectaccess.h"
#include "catalog/pg_namespace.h" #include "catalog/pg_namespace.h"
#include "commands/dbcommands.h" #include "commands/dbcommands.h"
...@@ -42,8 +43,7 @@ static void AlterSchemaOwner_internal(HeapTuple tup, Relation rel, Oid newOwnerI ...@@ -42,8 +43,7 @@ static void AlterSchemaOwner_internal(HeapTuple tup, Relation rel, Oid newOwnerI
Oid Oid
CreateSchemaCommand(CreateSchemaStmt *stmt, const char *queryString) CreateSchemaCommand(CreateSchemaStmt *stmt, const char *queryString)
{ {
const char *schemaName = stmt->schemaname; const char *schemaName = stmt->schemaname;
const char *authId = stmt->authid;
Oid namespaceId; Oid namespaceId;
OverrideSearchPath *overridePath; OverrideSearchPath *overridePath;
List *parsetree_list; List *parsetree_list;
...@@ -58,11 +58,24 @@ CreateSchemaCommand(CreateSchemaStmt *stmt, const char *queryString) ...@@ -58,11 +58,24 @@ CreateSchemaCommand(CreateSchemaStmt *stmt, const char *queryString)
/* /*
* Who is supposed to own the new schema? * Who is supposed to own the new schema?
*/ */
if (authId) if (stmt->authrole)
owner_uid = get_role_oid(authId, false); owner_uid = get_rolespec_oid(stmt->authrole, false);
else else
owner_uid = saved_uid; owner_uid = saved_uid;
/* fill schema name with the user name if not specified */
if (!schemaName)
{
HeapTuple tuple;
tuple = SearchSysCache1(AUTHOID, ObjectIdGetDatum(owner_uid));
if (!HeapTupleIsValid(tuple))
elog(ERROR, "cache lookup failed for role %u", owner_uid);
schemaName =
pstrdup(NameStr(((Form_pg_authid) GETSTRUCT(tuple))->rolname));
ReleaseSysCache(tuple);
}
/* /*
* To create a schema, must have schema-create privilege on the current * To create a schema, must have schema-create privilege on the current
* database and must be able to become the target role (this does not * database and must be able to become the target role (this does not
......
...@@ -3507,7 +3507,7 @@ ATExecCmd(List **wqueue, AlteredTableInfo *tab, Relation rel, ...@@ -3507,7 +3507,7 @@ ATExecCmd(List **wqueue, AlteredTableInfo *tab, Relation rel,
break; break;
case AT_ChangeOwner: /* ALTER OWNER */ case AT_ChangeOwner: /* ALTER OWNER */
ATExecChangeOwner(RelationGetRelid(rel), ATExecChangeOwner(RelationGetRelid(rel),
get_role_oid(cmd->name, false), get_rolespec_oid(cmd->newowner, false),
false, lockmode); false, lockmode);
break; break;
case AT_ClusterOn: /* CLUSTER ON */ case AT_ClusterOn: /* CLUSTER ON */
...@@ -9388,7 +9388,7 @@ AlterTableMoveAll(AlterTableMoveAllStmt *stmt) ...@@ -9388,7 +9388,7 @@ AlterTableMoveAll(AlterTableMoveAllStmt *stmt)
HeapTuple tuple; HeapTuple tuple;
Oid orig_tablespaceoid; Oid orig_tablespaceoid;
Oid new_tablespaceoid; Oid new_tablespaceoid;
List *role_oids = roleNamesToIds(stmt->roles); List *role_oids = roleSpecsToIds(stmt->roles);
/* Ensure we were not asked to move something we can't */ /* Ensure we were not asked to move something we can't */
if (stmt->objtype != OBJECT_TABLE && stmt->objtype != OBJECT_INDEX && if (stmt->objtype != OBJECT_TABLE && stmt->objtype != OBJECT_INDEX &&
......
...@@ -252,7 +252,7 @@ CreateTableSpace(CreateTableSpaceStmt *stmt) ...@@ -252,7 +252,7 @@ CreateTableSpace(CreateTableSpaceStmt *stmt)
/* However, the eventual owner of the tablespace need not be */ /* However, the eventual owner of the tablespace need not be */
if (stmt->owner) if (stmt->owner)
ownerId = get_role_oid(stmt->owner, false); ownerId = get_rolespec_oid(stmt->owner, false);
else else
ownerId = GetUserId(); ownerId = GetUserId();
......
This diff is collapsed.
...@@ -2504,6 +2504,18 @@ _copyXmlSerialize(const XmlSerialize *from) ...@@ -2504,6 +2504,18 @@ _copyXmlSerialize(const XmlSerialize *from)
return newnode; return newnode;
} }
static RoleSpec *
_copyRoleSpec(const RoleSpec *from)
{
RoleSpec *newnode = makeNode(RoleSpec);
COPY_SCALAR_FIELD(roletype);
COPY_STRING_FIELD(rolename);
COPY_LOCATION_FIELD(location);
return newnode;
}
static Query * static Query *
_copyQuery(const Query *from) _copyQuery(const Query *from)
{ {
...@@ -2650,6 +2662,7 @@ _copyAlterTableCmd(const AlterTableCmd *from) ...@@ -2650,6 +2662,7 @@ _copyAlterTableCmd(const AlterTableCmd *from)
COPY_SCALAR_FIELD(subtype); COPY_SCALAR_FIELD(subtype);
COPY_STRING_FIELD(name); COPY_STRING_FIELD(name);
COPY_NODE_FIELD(newowner);
COPY_NODE_FIELD(def); COPY_NODE_FIELD(def);
COPY_SCALAR_FIELD(behavior); COPY_SCALAR_FIELD(behavior);
COPY_SCALAR_FIELD(missing_ok); COPY_SCALAR_FIELD(missing_ok);
...@@ -2689,16 +2702,6 @@ _copyGrantStmt(const GrantStmt *from) ...@@ -2689,16 +2702,6 @@ _copyGrantStmt(const GrantStmt *from)
return newnode; return newnode;
} }
static PrivGrantee *
_copyPrivGrantee(const PrivGrantee *from)
{
PrivGrantee *newnode = makeNode(PrivGrantee);
COPY_STRING_FIELD(rolname);
return newnode;
}
static FuncWithArgs * static FuncWithArgs *
_copyFuncWithArgs(const FuncWithArgs *from) _copyFuncWithArgs(const FuncWithArgs *from)
{ {
...@@ -2730,7 +2733,7 @@ _copyGrantRoleStmt(const GrantRoleStmt *from) ...@@ -2730,7 +2733,7 @@ _copyGrantRoleStmt(const GrantRoleStmt *from)
COPY_NODE_FIELD(grantee_roles); COPY_NODE_FIELD(grantee_roles);
COPY_SCALAR_FIELD(is_grant); COPY_SCALAR_FIELD(is_grant);
COPY_SCALAR_FIELD(admin_opt); COPY_SCALAR_FIELD(admin_opt);
COPY_STRING_FIELD(grantor); COPY_NODE_FIELD(grantor);
COPY_SCALAR_FIELD(behavior); COPY_SCALAR_FIELD(behavior);
return newnode; return newnode;
...@@ -3038,7 +3041,7 @@ _copyAlterOwnerStmt(const AlterOwnerStmt *from) ...@@ -3038,7 +3041,7 @@ _copyAlterOwnerStmt(const AlterOwnerStmt *from)
COPY_NODE_FIELD(relation); COPY_NODE_FIELD(relation);
COPY_NODE_FIELD(object); COPY_NODE_FIELD(object);
COPY_NODE_FIELD(objarg); COPY_NODE_FIELD(objarg);
COPY_STRING_FIELD(newowner); COPY_NODE_FIELD(newowner);
return newnode; return newnode;
} }
...@@ -3424,7 +3427,7 @@ _copyCreateTableSpaceStmt(const CreateTableSpaceStmt *from) ...@@ -3424,7 +3427,7 @@ _copyCreateTableSpaceStmt(const CreateTableSpaceStmt *from)
CreateTableSpaceStmt *newnode = makeNode(CreateTableSpaceStmt); CreateTableSpaceStmt *newnode = makeNode(CreateTableSpaceStmt);
COPY_STRING_FIELD(tablespacename); COPY_STRING_FIELD(tablespacename);
COPY_STRING_FIELD(owner); COPY_NODE_FIELD(owner);
COPY_STRING_FIELD(location); COPY_STRING_FIELD(location);
COPY_NODE_FIELD(options); COPY_NODE_FIELD(options);
...@@ -3561,7 +3564,7 @@ _copyCreateUserMappingStmt(const CreateUserMappingStmt *from) ...@@ -3561,7 +3564,7 @@ _copyCreateUserMappingStmt(const CreateUserMappingStmt *from)
{ {
CreateUserMappingStmt *newnode = makeNode(CreateUserMappingStmt); CreateUserMappingStmt *newnode = makeNode(CreateUserMappingStmt);
COPY_STRING_FIELD(username); COPY_NODE_FIELD(user);
COPY_STRING_FIELD(servername); COPY_STRING_FIELD(servername);
COPY_NODE_FIELD(options); COPY_NODE_FIELD(options);
...@@ -3573,7 +3576,7 @@ _copyAlterUserMappingStmt(const AlterUserMappingStmt *from) ...@@ -3573,7 +3576,7 @@ _copyAlterUserMappingStmt(const AlterUserMappingStmt *from)
{ {
AlterUserMappingStmt *newnode = makeNode(AlterUserMappingStmt); AlterUserMappingStmt *newnode = makeNode(AlterUserMappingStmt);
COPY_STRING_FIELD(username); COPY_NODE_FIELD(user);
COPY_STRING_FIELD(servername); COPY_STRING_FIELD(servername);
COPY_NODE_FIELD(options); COPY_NODE_FIELD(options);
...@@ -3585,7 +3588,7 @@ _copyDropUserMappingStmt(const DropUserMappingStmt *from) ...@@ -3585,7 +3588,7 @@ _copyDropUserMappingStmt(const DropUserMappingStmt *from)
{ {
DropUserMappingStmt *newnode = makeNode(DropUserMappingStmt); DropUserMappingStmt *newnode = makeNode(DropUserMappingStmt);
COPY_STRING_FIELD(username); COPY_NODE_FIELD(user);
COPY_STRING_FIELD(servername); COPY_STRING_FIELD(servername);
COPY_SCALAR_FIELD(missing_ok); COPY_SCALAR_FIELD(missing_ok);
...@@ -3698,7 +3701,7 @@ _copyAlterRoleStmt(const AlterRoleStmt *from) ...@@ -3698,7 +3701,7 @@ _copyAlterRoleStmt(const AlterRoleStmt *from)
{ {
AlterRoleStmt *newnode = makeNode(AlterRoleStmt); AlterRoleStmt *newnode = makeNode(AlterRoleStmt);
COPY_STRING_FIELD(role); COPY_NODE_FIELD(role);
COPY_NODE_FIELD(options); COPY_NODE_FIELD(options);
COPY_SCALAR_FIELD(action); COPY_SCALAR_FIELD(action);
...@@ -3710,7 +3713,7 @@ _copyAlterRoleSetStmt(const AlterRoleSetStmt *from) ...@@ -3710,7 +3713,7 @@ _copyAlterRoleSetStmt(const AlterRoleSetStmt *from)
{ {
AlterRoleSetStmt *newnode = makeNode(AlterRoleSetStmt); AlterRoleSetStmt *newnode = makeNode(AlterRoleSetStmt);
COPY_STRING_FIELD(role); COPY_NODE_FIELD(role);
COPY_STRING_FIELD(database); COPY_STRING_FIELD(database);
COPY_NODE_FIELD(setstmt); COPY_NODE_FIELD(setstmt);
...@@ -3769,7 +3772,7 @@ _copyCreateSchemaStmt(const CreateSchemaStmt *from) ...@@ -3769,7 +3772,7 @@ _copyCreateSchemaStmt(const CreateSchemaStmt *from)
CreateSchemaStmt *newnode = makeNode(CreateSchemaStmt); CreateSchemaStmt *newnode = makeNode(CreateSchemaStmt);
COPY_STRING_FIELD(schemaname); COPY_STRING_FIELD(schemaname);
COPY_STRING_FIELD(authid); COPY_NODE_FIELD(authrole);
COPY_NODE_FIELD(schemaElts); COPY_NODE_FIELD(schemaElts);
COPY_SCALAR_FIELD(if_not_exists); COPY_SCALAR_FIELD(if_not_exists);
...@@ -3854,7 +3857,7 @@ _copyReassignOwnedStmt(const ReassignOwnedStmt *from) ...@@ -3854,7 +3857,7 @@ _copyReassignOwnedStmt(const ReassignOwnedStmt *from)
ReassignOwnedStmt *newnode = makeNode(ReassignOwnedStmt); ReassignOwnedStmt *newnode = makeNode(ReassignOwnedStmt);
COPY_NODE_FIELD(roles); COPY_NODE_FIELD(roles);
COPY_STRING_FIELD(newrole); COPY_NODE_FIELD(newrole);
return newnode; return newnode;
} }
...@@ -4728,9 +4731,6 @@ copyObject(const void *from) ...@@ -4728,9 +4731,6 @@ copyObject(const void *from)
case T_CommonTableExpr: case T_CommonTableExpr:
retval = _copyCommonTableExpr(from); retval = _copyCommonTableExpr(from);
break; break;
case T_PrivGrantee:
retval = _copyPrivGrantee(from);
break;
case T_FuncWithArgs: case T_FuncWithArgs:
retval = _copyFuncWithArgs(from); retval = _copyFuncWithArgs(from);
break; break;
...@@ -4740,6 +4740,9 @@ copyObject(const void *from) ...@@ -4740,6 +4740,9 @@ copyObject(const void *from)
case T_XmlSerialize: case T_XmlSerialize:
retval = _copyXmlSerialize(from); retval = _copyXmlSerialize(from);
break; break;
case T_RoleSpec:
retval = _copyRoleSpec(from);
break;
default: default:
elog(ERROR, "unrecognized node type: %d", (int) nodeTag(from)); elog(ERROR, "unrecognized node type: %d", (int) nodeTag(from));
......
...@@ -973,6 +973,7 @@ _equalAlterTableCmd(const AlterTableCmd *a, const AlterTableCmd *b) ...@@ -973,6 +973,7 @@ _equalAlterTableCmd(const AlterTableCmd *a, const AlterTableCmd *b)
{ {
COMPARE_SCALAR_FIELD(subtype); COMPARE_SCALAR_FIELD(subtype);
COMPARE_STRING_FIELD(name); COMPARE_STRING_FIELD(name);
COMPARE_NODE_FIELD(newowner);
COMPARE_NODE_FIELD(def); COMPARE_NODE_FIELD(def);
COMPARE_SCALAR_FIELD(behavior); COMPARE_SCALAR_FIELD(behavior);
COMPARE_SCALAR_FIELD(missing_ok); COMPARE_SCALAR_FIELD(missing_ok);
...@@ -1008,14 +1009,6 @@ _equalGrantStmt(const GrantStmt *a, const GrantStmt *b) ...@@ -1008,14 +1009,6 @@ _equalGrantStmt(const GrantStmt *a, const GrantStmt *b)
return true; return true;
} }
static bool
_equalPrivGrantee(const PrivGrantee *a, const PrivGrantee *b)
{
COMPARE_STRING_FIELD(rolname);
return true;
}
static bool static bool
_equalFuncWithArgs(const FuncWithArgs *a, const FuncWithArgs *b) _equalFuncWithArgs(const FuncWithArgs *a, const FuncWithArgs *b)
{ {
...@@ -1041,7 +1034,7 @@ _equalGrantRoleStmt(const GrantRoleStmt *a, const GrantRoleStmt *b) ...@@ -1041,7 +1034,7 @@ _equalGrantRoleStmt(const GrantRoleStmt *a, const GrantRoleStmt *b)
COMPARE_NODE_FIELD(grantee_roles); COMPARE_NODE_FIELD(grantee_roles);
COMPARE_SCALAR_FIELD(is_grant); COMPARE_SCALAR_FIELD(is_grant);
COMPARE_SCALAR_FIELD(admin_opt); COMPARE_SCALAR_FIELD(admin_opt);
COMPARE_STRING_FIELD(grantor); COMPARE_NODE_FIELD(grantor);
COMPARE_SCALAR_FIELD(behavior); COMPARE_SCALAR_FIELD(behavior);
return true; return true;
...@@ -1295,7 +1288,7 @@ _equalAlterOwnerStmt(const AlterOwnerStmt *a, const AlterOwnerStmt *b) ...@@ -1295,7 +1288,7 @@ _equalAlterOwnerStmt(const AlterOwnerStmt *a, const AlterOwnerStmt *b)
COMPARE_NODE_FIELD(relation); COMPARE_NODE_FIELD(relation);
COMPARE_NODE_FIELD(object); COMPARE_NODE_FIELD(object);
COMPARE_NODE_FIELD(objarg); COMPARE_NODE_FIELD(objarg);
COMPARE_STRING_FIELD(newowner); COMPARE_NODE_FIELD(newowner);
return true; return true;
} }
...@@ -1618,7 +1611,7 @@ static bool ...@@ -1618,7 +1611,7 @@ static bool
_equalCreateTableSpaceStmt(const CreateTableSpaceStmt *a, const CreateTableSpaceStmt *b) _equalCreateTableSpaceStmt(const CreateTableSpaceStmt *a, const CreateTableSpaceStmt *b)
{ {
COMPARE_STRING_FIELD(tablespacename); COMPARE_STRING_FIELD(tablespacename);
COMPARE_STRING_FIELD(owner); COMPARE_NODE_FIELD(owner);
COMPARE_STRING_FIELD(location); COMPARE_STRING_FIELD(location);
COMPARE_NODE_FIELD(options); COMPARE_NODE_FIELD(options);
...@@ -1735,7 +1728,7 @@ _equalAlterForeignServerStmt(const AlterForeignServerStmt *a, const AlterForeign ...@@ -1735,7 +1728,7 @@ _equalAlterForeignServerStmt(const AlterForeignServerStmt *a, const AlterForeign
static bool static bool
_equalCreateUserMappingStmt(const CreateUserMappingStmt *a, const CreateUserMappingStmt *b) _equalCreateUserMappingStmt(const CreateUserMappingStmt *a, const CreateUserMappingStmt *b)
{ {
COMPARE_STRING_FIELD(username); COMPARE_NODE_FIELD(user);
COMPARE_STRING_FIELD(servername); COMPARE_STRING_FIELD(servername);
COMPARE_NODE_FIELD(options); COMPARE_NODE_FIELD(options);
...@@ -1745,7 +1738,7 @@ _equalCreateUserMappingStmt(const CreateUserMappingStmt *a, const CreateUserMapp ...@@ -1745,7 +1738,7 @@ _equalCreateUserMappingStmt(const CreateUserMappingStmt *a, const CreateUserMapp
static bool static bool
_equalAlterUserMappingStmt(const AlterUserMappingStmt *a, const AlterUserMappingStmt *b) _equalAlterUserMappingStmt(const AlterUserMappingStmt *a, const AlterUserMappingStmt *b)
{ {
COMPARE_STRING_FIELD(username); COMPARE_NODE_FIELD(user);
COMPARE_STRING_FIELD(servername); COMPARE_STRING_FIELD(servername);
COMPARE_NODE_FIELD(options); COMPARE_NODE_FIELD(options);
...@@ -1755,7 +1748,7 @@ _equalAlterUserMappingStmt(const AlterUserMappingStmt *a, const AlterUserMapping ...@@ -1755,7 +1748,7 @@ _equalAlterUserMappingStmt(const AlterUserMappingStmt *a, const AlterUserMapping
static bool static bool
_equalDropUserMappingStmt(const DropUserMappingStmt *a, const DropUserMappingStmt *b) _equalDropUserMappingStmt(const DropUserMappingStmt *a, const DropUserMappingStmt *b)
{ {
COMPARE_STRING_FIELD(username); COMPARE_NODE_FIELD(user);
COMPARE_STRING_FIELD(servername); COMPARE_STRING_FIELD(servername);
COMPARE_SCALAR_FIELD(missing_ok); COMPARE_SCALAR_FIELD(missing_ok);
...@@ -1853,7 +1846,7 @@ _equalCreateRoleStmt(const CreateRoleStmt *a, const CreateRoleStmt *b) ...@@ -1853,7 +1846,7 @@ _equalCreateRoleStmt(const CreateRoleStmt *a, const CreateRoleStmt *b)
static bool static bool
_equalAlterRoleStmt(const AlterRoleStmt *a, const AlterRoleStmt *b) _equalAlterRoleStmt(const AlterRoleStmt *a, const AlterRoleStmt *b)
{ {
COMPARE_STRING_FIELD(role); COMPARE_NODE_FIELD(role);
COMPARE_NODE_FIELD(options); COMPARE_NODE_FIELD(options);
COMPARE_SCALAR_FIELD(action); COMPARE_SCALAR_FIELD(action);
...@@ -1863,7 +1856,7 @@ _equalAlterRoleStmt(const AlterRoleStmt *a, const AlterRoleStmt *b) ...@@ -1863,7 +1856,7 @@ _equalAlterRoleStmt(const AlterRoleStmt *a, const AlterRoleStmt *b)
static bool static bool
_equalAlterRoleSetStmt(const AlterRoleSetStmt *a, const AlterRoleSetStmt *b) _equalAlterRoleSetStmt(const AlterRoleSetStmt *a, const AlterRoleSetStmt *b)
{ {
COMPARE_STRING_FIELD(role); COMPARE_NODE_FIELD(role);
COMPARE_STRING_FIELD(database); COMPARE_STRING_FIELD(database);
COMPARE_NODE_FIELD(setstmt); COMPARE_NODE_FIELD(setstmt);
...@@ -1912,7 +1905,7 @@ static bool ...@@ -1912,7 +1905,7 @@ static bool
_equalCreateSchemaStmt(const CreateSchemaStmt *a, const CreateSchemaStmt *b) _equalCreateSchemaStmt(const CreateSchemaStmt *a, const CreateSchemaStmt *b)
{ {
COMPARE_STRING_FIELD(schemaname); COMPARE_STRING_FIELD(schemaname);
COMPARE_STRING_FIELD(authid); COMPARE_NODE_FIELD(authrole);
COMPARE_NODE_FIELD(schemaElts); COMPARE_NODE_FIELD(schemaElts);
COMPARE_SCALAR_FIELD(if_not_exists); COMPARE_SCALAR_FIELD(if_not_exists);
...@@ -1983,7 +1976,7 @@ static bool ...@@ -1983,7 +1976,7 @@ static bool
_equalReassignOwnedStmt(const ReassignOwnedStmt *a, const ReassignOwnedStmt *b) _equalReassignOwnedStmt(const ReassignOwnedStmt *a, const ReassignOwnedStmt *b)
{ {
COMPARE_NODE_FIELD(roles); COMPARE_NODE_FIELD(roles);
COMPARE_STRING_FIELD(newrole); COMPARE_NODE_FIELD(newrole);
return true; return true;
} }
...@@ -2455,6 +2448,16 @@ _equalXmlSerialize(const XmlSerialize *a, const XmlSerialize *b) ...@@ -2455,6 +2448,16 @@ _equalXmlSerialize(const XmlSerialize *a, const XmlSerialize *b)
return true; return true;
} }
static bool
_equalRoleSpec(const RoleSpec *a, const RoleSpec *b)
{
COMPARE_SCALAR_FIELD(roletype);
COMPARE_STRING_FIELD(rolename);
COMPARE_LOCATION_FIELD(location);
return true;
}
/* /*
* Stuff from pg_list.h * Stuff from pg_list.h
*/ */
...@@ -3153,9 +3156,6 @@ equal(const void *a, const void *b) ...@@ -3153,9 +3156,6 @@ equal(const void *a, const void *b)
case T_CommonTableExpr: case T_CommonTableExpr:
retval = _equalCommonTableExpr(a, b); retval = _equalCommonTableExpr(a, b);
break; break;
case T_PrivGrantee:
retval = _equalPrivGrantee(a, b);
break;
case T_FuncWithArgs: case T_FuncWithArgs:
retval = _equalFuncWithArgs(a, b); retval = _equalFuncWithArgs(a, b);
break; break;
...@@ -3165,6 +3165,9 @@ equal(const void *a, const void *b) ...@@ -3165,6 +3165,9 @@ equal(const void *a, const void *b)
case T_XmlSerialize: case T_XmlSerialize:
retval = _equalXmlSerialize(a, b); retval = _equalXmlSerialize(a, b);
break; break;
case T_RoleSpec:
retval = _equalRoleSpec(a, b);
break;
default: default:
elog(ERROR, "unrecognized node type: %d", elog(ERROR, "unrecognized node type: %d",
......
This diff is collapsed.
...@@ -90,7 +90,7 @@ typedef struct ...@@ -90,7 +90,7 @@ typedef struct
{ {
const char *stmtType; /* "CREATE SCHEMA" or "ALTER SCHEMA" */ const char *stmtType; /* "CREATE SCHEMA" or "ALTER SCHEMA" */
char *schemaname; /* name of schema */ char *schemaname; /* name of schema */
char *authid; /* owner of schema */ RoleSpec *authrole; /* owner of schema */
List *sequences; /* CREATE SEQUENCE items */ List *sequences; /* CREATE SEQUENCE items */
List *tables; /* CREATE TABLE items */ List *tables; /* CREATE TABLE items */
List *views; /* CREATE VIEW items */ List *views; /* CREATE VIEW items */
...@@ -2723,7 +2723,7 @@ transformCreateSchemaStmt(CreateSchemaStmt *stmt) ...@@ -2723,7 +2723,7 @@ transformCreateSchemaStmt(CreateSchemaStmt *stmt)
cxt.stmtType = "CREATE SCHEMA"; cxt.stmtType = "CREATE SCHEMA";
cxt.schemaname = stmt->schemaname; cxt.schemaname = stmt->schemaname;
cxt.authid = stmt->authid; cxt.authrole = (RoleSpec *) stmt->authrole;
cxt.sequences = NIL; cxt.sequences = NIL;
cxt.tables = NIL; cxt.tables = NIL;
cxt.views = NIL; cxt.views = NIL;
......
...@@ -5105,7 +5105,7 @@ select_best_grantor(Oid roleId, AclMode privileges, ...@@ -5105,7 +5105,7 @@ select_best_grantor(Oid roleId, AclMode privileges,
/* /*
* get_role_oid - Given a role name, look up the role's OID. * get_role_oid - Given a role name, look up the role's OID.
* *
* If missing_ok is false, throw an error if tablespace name not found. If * If missing_ok is false, throw an error if role name not found. If
* true, just return InvalidOid. * true, just return InvalidOid.
*/ */
Oid Oid
...@@ -5133,3 +5133,117 @@ get_role_oid_or_public(const char *rolname) ...@@ -5133,3 +5133,117 @@ get_role_oid_or_public(const char *rolname)
return get_role_oid(rolname, false); return get_role_oid(rolname, false);
} }
/*
* Given a RoleSpec node, return the OID it corresponds to. If missing_ok is
* true, return InvalidOid if the role does not exist.
*
* PUBLIC is always disallowed here. Routines wanting to handle the PUBLIC
* case must check the case separately.
*/
Oid
get_rolespec_oid(const Node *node, bool missing_ok)
{
RoleSpec *role;
Oid oid;
if (!IsA(node, RoleSpec))
elog(ERROR, "invalid node type %d", node->type);
role = (RoleSpec *) node;
switch (role->roletype)
{
case ROLESPEC_CSTRING:
Assert(role->rolename);
oid = get_role_oid(role->rolename, missing_ok);
break;
case ROLESPEC_CURRENT_USER:
oid = GetUserId();
break;
case ROLESPEC_SESSION_USER:
oid = GetSessionUserId();
break;
case ROLESPEC_PUBLIC:
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("role \"%s\" does not exist", "public")));
oid = InvalidOid; /* make compiler happy */
break;
default:
elog(ERROR, "unexpected role type %d", role->roletype);
}
return oid;
}
/*
* Given a RoleSpec node, return the pg_authid HeapTuple it corresponds to.
* Caller must ReleaseSysCache when done with the result tuple.
*/
HeapTuple
get_rolespec_tuple(const Node *node)
{
RoleSpec *role;
HeapTuple tuple;
role = (RoleSpec *) node;
if (!IsA(node, RoleSpec))
elog(ERROR, "invalid node type %d", node->type);
switch (role->roletype)
{
case ROLESPEC_CSTRING:
Assert(role->rolename);
tuple = SearchSysCache1(AUTHNAME, CStringGetDatum(role->rolename));
if (!HeapTupleIsValid(tuple))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("role \"%s\" does not exist", role->rolename)));
break;
case ROLESPEC_CURRENT_USER:
tuple = SearchSysCache1(AUTHOID, GetUserId());
if (!HeapTupleIsValid(tuple))
elog(ERROR, "cache lookup failed for role %u", GetUserId());
break;
case ROLESPEC_SESSION_USER:
tuple = SearchSysCache1(AUTHOID, GetSessionUserId());
if (!HeapTupleIsValid(tuple))
elog(ERROR, "cache lookup failed for role %u", GetSessionUserId());
break;
case ROLESPEC_PUBLIC:
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("role \"%s\" does not exist", "public")));
tuple = NULL; /* make compiler happy */
default:
elog(ERROR, "unexpected role type %d", role->roletype);
}
return tuple;
}
/*
* Given a RoleSpec, returns a palloc'ed copy of the corresponding role's name.
*/
char *
get_rolespec_name(const Node *node)
{
HeapTuple tp;
Form_pg_authid authForm;
char *rolename;
tp = get_rolespec_tuple(node);
authForm = (Form_pg_authid) GETSTRUCT(tp);
rolename = pstrdup(NameStr(authForm->rolname));
ReleaseSysCache(tp);
return rolename;
}
...@@ -31,6 +31,6 @@ extern void GrantRole(GrantRoleStmt *stmt); ...@@ -31,6 +31,6 @@ extern void GrantRole(GrantRoleStmt *stmt);
extern ObjectAddress RenameRole(const char *oldname, const char *newname); extern ObjectAddress RenameRole(const char *oldname, const char *newname);
extern void DropOwnedObjects(DropOwnedStmt *stmt); extern void DropOwnedObjects(DropOwnedStmt *stmt);
extern void ReassignOwnedObjects(ReassignOwnedStmt *stmt); extern void ReassignOwnedObjects(ReassignOwnedStmt *stmt);
extern List *roleNamesToIds(List *memberNames); extern List *roleSpecsToIds(List *memberNames);
#endif /* USER_H */ #endif /* USER_H */
...@@ -413,6 +413,7 @@ typedef enum NodeTag ...@@ -413,6 +413,7 @@ typedef enum NodeTag
T_XmlSerialize, T_XmlSerialize,
T_WithClause, T_WithClause,
T_CommonTableExpr, T_CommonTableExpr,
T_RoleSpec,
/* /*
* TAGS FOR REPLICATION GRAMMAR PARSE NODES (replnodes.h) * TAGS FOR REPLICATION GRAMMAR PARSE NODES (replnodes.h)
......
...@@ -284,6 +284,25 @@ typedef struct CollateClause ...@@ -284,6 +284,25 @@ typedef struct CollateClause
int location; /* token location, or -1 if unknown */ int location; /* token location, or -1 if unknown */
} CollateClause; } CollateClause;
/*
* RoleSpec - a role name or one of a few special values.
*/
typedef enum RoleSpecType
{
ROLESPEC_CSTRING, /* role name is stored as a C string */
ROLESPEC_CURRENT_USER, /* role spec is CURRENT_USER */
ROLESPEC_SESSION_USER, /* role spec is SESSION_USER */
ROLESPEC_PUBLIC /* role name is "public" */
} RoleSpecType;
typedef struct RoleSpec
{
NodeTag type;
RoleSpecType roletype; /* Type of this rolespec */
char *rolename; /* filled only for ROLESPEC_CSTRING */
int location; /* token location, or -1 if unknown */
} RoleSpec;
/* /*
* FuncCall - a function or aggregate invocation * FuncCall - a function or aggregate invocation
* *
...@@ -1263,7 +1282,7 @@ typedef struct CreateSchemaStmt ...@@ -1263,7 +1282,7 @@ typedef struct CreateSchemaStmt
{ {
NodeTag type; NodeTag type;
char *schemaname; /* the name of the schema to create */ char *schemaname; /* the name of the schema to create */
char *authid; /* the owner of the created schema */ Node *authrole; /* the owner of the created schema */
List *schemaElts; /* schema components (list of parsenodes) */ List *schemaElts; /* schema components (list of parsenodes) */
bool if_not_exists; /* just do nothing if schema already exists? */ bool if_not_exists; /* just do nothing if schema already exists? */
} CreateSchemaStmt; } CreateSchemaStmt;
...@@ -1362,7 +1381,8 @@ typedef struct AlterTableCmd /* one subcommand of an ALTER TABLE */ ...@@ -1362,7 +1381,8 @@ typedef struct AlterTableCmd /* one subcommand of an ALTER TABLE */
NodeTag type; NodeTag type;
AlterTableType subtype; /* Type of table alteration to apply */ AlterTableType subtype; /* Type of table alteration to apply */
char *name; /* column, constraint, or trigger to act on, char *name; /* column, constraint, or trigger to act on,
* or new owner or tablespace */ * or tablespace */
Node *newowner; /* RoleSpec */
Node *def; /* definition of new column, index, Node *def; /* definition of new column, index,
* constraint, or parent table */ * constraint, or parent table */
DropBehavior behavior; /* RESTRICT or CASCADE for DROP cases */ DropBehavior behavior; /* RESTRICT or CASCADE for DROP cases */
...@@ -1434,17 +1454,11 @@ typedef struct GrantStmt ...@@ -1434,17 +1454,11 @@ typedef struct GrantStmt
* or plain names (as Value strings) */ * or plain names (as Value strings) */
List *privileges; /* list of AccessPriv nodes */ List *privileges; /* list of AccessPriv nodes */
/* privileges == NIL denotes ALL PRIVILEGES */ /* privileges == NIL denotes ALL PRIVILEGES */
List *grantees; /* list of PrivGrantee nodes */ List *grantees; /* list of RoleSpec nodes */
bool grant_option; /* grant or revoke grant option */ bool grant_option; /* grant or revoke grant option */
DropBehavior behavior; /* drop behavior (for REVOKE) */ DropBehavior behavior; /* drop behavior (for REVOKE) */
} GrantStmt; } GrantStmt;
typedef struct PrivGrantee
{
NodeTag type;
char *rolname; /* if NULL then PUBLIC */
} PrivGrantee;
/* /*
* Note: FuncWithArgs carries only the types of the input parameters of the * Note: FuncWithArgs carries only the types of the input parameters of the
* function. So it is sufficient to identify an existing function, but it * function. So it is sufficient to identify an existing function, but it
...@@ -1487,7 +1501,7 @@ typedef struct GrantRoleStmt ...@@ -1487,7 +1501,7 @@ typedef struct GrantRoleStmt
List *grantee_roles; /* list of member roles to add/delete */ List *grantee_roles; /* list of member roles to add/delete */
bool is_grant; /* true = GRANT, false = REVOKE */ bool is_grant; /* true = GRANT, false = REVOKE */
bool admin_opt; /* with admin option */ bool admin_opt; /* with admin option */
char *grantor; /* set grantor to other than current role */ Node *grantor; /* set grantor to other than current role */
DropBehavior behavior; /* drop behavior (for REVOKE) */ DropBehavior behavior; /* drop behavior (for REVOKE) */
} GrantRoleStmt; } GrantRoleStmt;
...@@ -1699,7 +1713,7 @@ typedef struct CreateTableSpaceStmt ...@@ -1699,7 +1713,7 @@ typedef struct CreateTableSpaceStmt
{ {
NodeTag type; NodeTag type;
char *tablespacename; char *tablespacename;
char *owner; Node *owner;
char *location; char *location;
List *options; List *options;
} CreateTableSpaceStmt; } CreateTableSpaceStmt;
...@@ -1825,7 +1839,7 @@ typedef struct CreateForeignTableStmt ...@@ -1825,7 +1839,7 @@ typedef struct CreateForeignTableStmt
typedef struct CreateUserMappingStmt typedef struct CreateUserMappingStmt
{ {
NodeTag type; NodeTag type;
char *username; /* username or PUBLIC/CURRENT_USER */ Node *user; /* user role */
char *servername; /* server name */ char *servername; /* server name */
List *options; /* generic options to server */ List *options; /* generic options to server */
} CreateUserMappingStmt; } CreateUserMappingStmt;
...@@ -1833,7 +1847,7 @@ typedef struct CreateUserMappingStmt ...@@ -1833,7 +1847,7 @@ typedef struct CreateUserMappingStmt
typedef struct AlterUserMappingStmt typedef struct AlterUserMappingStmt
{ {
NodeTag type; NodeTag type;
char *username; /* username or PUBLIC/CURRENT_USER */ Node *user; /* user role */
char *servername; /* server name */ char *servername; /* server name */
List *options; /* generic options to server */ List *options; /* generic options to server */
} AlterUserMappingStmt; } AlterUserMappingStmt;
...@@ -1841,7 +1855,7 @@ typedef struct AlterUserMappingStmt ...@@ -1841,7 +1855,7 @@ typedef struct AlterUserMappingStmt
typedef struct DropUserMappingStmt typedef struct DropUserMappingStmt
{ {
NodeTag type; NodeTag type;
char *username; /* username or PUBLIC/CURRENT_USER */ Node *user; /* user role */
char *servername; /* server name */ char *servername; /* server name */
bool missing_ok; /* ignore missing mappings */ bool missing_ok; /* ignore missing mappings */
} DropUserMappingStmt; } DropUserMappingStmt;
...@@ -1991,7 +2005,7 @@ typedef struct CreateRoleStmt ...@@ -1991,7 +2005,7 @@ typedef struct CreateRoleStmt
typedef struct AlterRoleStmt typedef struct AlterRoleStmt
{ {
NodeTag type; NodeTag type;
char *role; /* role name */ Node *role; /* role */
List *options; /* List of DefElem nodes */ List *options; /* List of DefElem nodes */
int action; /* +1 = add members, -1 = drop members */ int action; /* +1 = add members, -1 = drop members */
} AlterRoleStmt; } AlterRoleStmt;
...@@ -1999,7 +2013,7 @@ typedef struct AlterRoleStmt ...@@ -1999,7 +2013,7 @@ typedef struct AlterRoleStmt
typedef struct AlterRoleSetStmt typedef struct AlterRoleSetStmt
{ {
NodeTag type; NodeTag type;
char *role; /* role name */ Node *role; /* role */
char *database; /* database name, or NULL */ char *database; /* database name, or NULL */
VariableSetStmt *setstmt; /* SET or RESET subcommand */ VariableSetStmt *setstmt; /* SET or RESET subcommand */
} AlterRoleSetStmt; } AlterRoleSetStmt;
...@@ -2375,7 +2389,7 @@ typedef struct AlterOwnerStmt ...@@ -2375,7 +2389,7 @@ typedef struct AlterOwnerStmt
RangeVar *relation; /* in case it's a table */ RangeVar *relation; /* in case it's a table */
List *object; /* in case it's some other object */ List *object; /* in case it's some other object */
List *objarg; /* argument types, if applicable */ List *objarg; /* argument types, if applicable */
char *newowner; /* the new owner */ Node *newowner; /* the new owner */
} AlterOwnerStmt; } AlterOwnerStmt;
...@@ -2831,7 +2845,7 @@ typedef struct ReassignOwnedStmt ...@@ -2831,7 +2845,7 @@ typedef struct ReassignOwnedStmt
{ {
NodeTag type; NodeTag type;
List *roles; List *roles;
char *newrole; Node *newrole;
} ReassignOwnedStmt; } ReassignOwnedStmt;
/* /*
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#ifndef ACL_H #ifndef ACL_H
#define ACL_H #define ACL_H
#include "access/htup.h"
#include "nodes/parsenodes.h" #include "nodes/parsenodes.h"
#include "utils/array.h" #include "utils/array.h"
#include "utils/snapshot.h" #include "utils/snapshot.h"
...@@ -227,8 +228,11 @@ extern bool is_member_of_role(Oid member, Oid role); ...@@ -227,8 +228,11 @@ extern bool is_member_of_role(Oid member, Oid role);
extern bool is_member_of_role_nosuper(Oid member, Oid role); extern bool is_member_of_role_nosuper(Oid member, Oid role);
extern bool is_admin_of_role(Oid member, Oid role); extern bool is_admin_of_role(Oid member, Oid role);
extern void check_is_member_of_role(Oid member, Oid role); extern void check_is_member_of_role(Oid member, Oid role);
extern Oid get_role_oid(const char *rolname, bool missing_ok); extern Oid get_role_oid(const char *rolename, bool missing_ok);
extern Oid get_role_oid_or_public(const char *rolname); extern Oid get_role_oid_or_public(const char *rolename);
extern Oid get_rolespec_oid(const Node *node, bool missing_ok);
extern HeapTuple get_rolespec_tuple(const Node *node);
extern char *get_rolespec_name(const Node *node);
extern void select_best_grantor(Oid roleId, AclMode privileges, extern void select_best_grantor(Oid roleId, AclMode privileges,
const Acl *acl, Oid ownerId, const Acl *acl, Oid ownerId,
......
This diff is collapsed.
...@@ -59,7 +59,7 @@ test: create_index create_view ...@@ -59,7 +59,7 @@ test: create_index create_view
# ---------- # ----------
# Another group of parallel tests # Another group of parallel tests
# ---------- # ----------
test: create_aggregate create_function_3 create_cast constraints triggers inherit create_table_like typed_table vacuum drop_if_exists updatable_views test: create_aggregate create_function_3 create_cast constraints triggers inherit create_table_like typed_table vacuum drop_if_exists updatable_views rolenames
# ---------- # ----------
# sanity_check does a vacuum, affecting the sort order of SELECT * # sanity_check does a vacuum, affecting the sort order of SELECT *
......
...@@ -71,6 +71,7 @@ test: typed_table ...@@ -71,6 +71,7 @@ test: typed_table
test: vacuum test: vacuum
test: drop_if_exists test: drop_if_exists
test: updatable_views test: updatable_views
test: rolenames
test: sanity_check test: sanity_check
test: errors test: errors
test: select test: select
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment