11<!--
2- $PostgreSQL: pgsql/doc/src/sgml/ref/grant.sgml,v 1.73 2008/12/19 16:25:16 petere Exp $
2+ $PostgreSQL: pgsql/doc/src/sgml/ref/grant.sgml,v 1.74 2009/01/22 20:15:59 tgl Exp $
33PostgreSQL documentation
44-->
55
@@ -26,6 +26,11 @@ GRANT { { SELECT | INSERT | UPDATE | DELETE | TRUNCATE | REFERENCES | TRIGGER }
2626 ON [ TABLE ] <replaceable class="PARAMETER">tablename</replaceable> [, ...]
2727 TO { [ GROUP ] <replaceable class="PARAMETER">rolename</replaceable> | PUBLIC } [, ...] [ WITH GRANT OPTION ]
2828
29+ GRANT { { SELECT | INSERT | UPDATE | REFERENCES } ( <replaceable class="PARAMETER">column</replaceable> [, ...] )
30+ [,...] | ALL [ PRIVILEGES ] ( <replaceable class="PARAMETER">column</replaceable> [, ...] ) }
31+ ON [ TABLE ] <replaceable class="PARAMETER">tablename</replaceable> [, ...]
32+ TO { [ GROUP ] <replaceable class="PARAMETER">rolename</replaceable> | PUBLIC } [, ...] [ WITH GRANT OPTION ]
33+
2934GRANT { { USAGE | SELECT | UPDATE }
3035 [,...] | ALL [ PRIVILEGES ] }
3136 ON SEQUENCE <replaceable class="PARAMETER">sequencename</replaceable> [, ...]
@@ -68,7 +73,7 @@ GRANT <replaceable class="PARAMETER">role</replaceable> [, ...] TO <replaceable
6873
6974 <para>
7075 The <command>GRANT</command> command has two basic variants: one
71- that grants privileges on a database object (table, view, sequence,
76+ that grants privileges on a database object (table,column, view, sequence,
7277 database, foreign-data wrapper, foreign server, function,
7378 procedural language, schema, or tablespace), and one that grants
7479 membership in a role. These variants are similar in many ways, but
@@ -125,7 +130,8 @@ GRANT <replaceable class="PARAMETER">role</replaceable> [, ...] TO <replaceable
125130 <para>
126131 Depending on the type of object, the initial default privileges might
127132 include granting some privileges to <literal>PUBLIC</literal>.
128- The default is no public access for tables, schemas, and tablespaces;
133+ The default is no public access for tables, columns, schemas, and
134+ tablespaces;
129135 <literal>CONNECT</> privilege and <literal>TEMP</> table creation privilege
130136 for databases;
131137 <literal>EXECUTE</> privilege for functions; and
@@ -145,7 +151,8 @@ GRANT <replaceable class="PARAMETER">role</replaceable> [, ...] TO <replaceable
145151 <listitem>
146152 <para>
147153 Allows <xref linkend="sql-select" endterm="sql-select-title"> from
148- any column of the specified table, view, or sequence.
154+ any column, or the specific columns listed, of the specified table,
155+ view, or sequence.
149156 Also allows the use of
150157 <xref linkend="sql-copy" endterm="sql-copy-title"> TO.
151158 This privilege is also needed to reference existing column values in
@@ -162,7 +169,9 @@ GRANT <replaceable class="PARAMETER">role</replaceable> [, ...] TO <replaceable
162169 <listitem>
163170 <para>
164171 Allows <xref linkend="sql-insert" endterm="sql-insert-title"> of a new
165- row into the specified table.
172+ row into the specified table. If specific columns are listed,
173+ only those columns may be assigned to in the <command>INSERT</>
174+ command (other columns will therefore receive default values).
166175 Also allows <xref linkend="sql-copy" endterm="sql-copy-title"> FROM.
167176 </para>
168177 </listitem>
@@ -173,14 +182,14 @@ GRANT <replaceable class="PARAMETER">role</replaceable> [, ...] TO <replaceable
173182 <listitem>
174183 <para>
175184 Allows <xref linkend="sql-update" endterm="sql-update-title"> of any
176- column of the specified table.
185+ column, or the specific columns listed, of the specified table.
177186 (In practice, any nontrivial <command>UPDATE</> command will require
178187 <literal>SELECT</> privilege as well, since it must reference table
179188 columns to determine which rows to update, and/or to compute new
180189 values for columns.)
181190 <literal>SELECT ... FOR UPDATE</literal>
182191 and <literal>SELECT ... FOR SHARE</literal>
183- also require this privilege, in addition to the
192+ also require this privilege on at least one column , in addition to the
184193 <literal>SELECT</literal> privilege. For sequences, this
185194 privilege allows the use of the <function>nextval</function> and
186195 <function>setval</function> functions.
@@ -217,7 +226,8 @@ GRANT <replaceable class="PARAMETER">role</replaceable> [, ...] TO <replaceable
217226 <para>
218227 To create a foreign key constraint, it is
219228 necessary to have this privilege on both the referencing and
220- referenced tables.
229+ referenced columns. The privilege may be granted for all columns
230+ of a table, or just specific columns.
221231 </para>
222232 </listitem>
223233 </varlistentry>
@@ -373,6 +383,14 @@ GRANT <replaceable class="PARAMETER">role</replaceable> [, ...] TO <replaceable
373383 to revoke access privileges.
374384 </para>
375385
386+ <para>
387+ A user may perform <command>SELECT</>, <command>INSERT</>, etc. on a
388+ column if he holds that privilege for either the specific column or
389+ its whole table. Granting the privilege at the table level and then
390+ revoking it for one column will not do what you might wish: the
391+ table-level grant is unaffected by a column-level operation.
392+ </para>
393+
376394 <para>
377395 When a non-owner of an object attempts to <command>GRANT</> privileges
378396 on the object, the command will fail outright if the user has no
@@ -428,33 +446,27 @@ GRANT <replaceable class="PARAMETER">role</replaceable> [, ...] TO <replaceable
428446 </para>
429447
430448 <para>
431- Granting permission on a table does not automatically extend
432- permissions to any sequences used by the table, including
433- sequences tied to <type>SERIAL</> columns. Permissions on
434- sequence must be set separately.
449+ Granting permission on a table does not automatically extend
450+ permissions to any sequences used by the table, including
451+ sequences tied to <type>SERIAL</> columns. Permissions on
452+ sequences must be set separately.
435453 </para>
436454
437455 <para>
438- Currently, <productname>PostgreSQL</productname> does not support
439- granting or revoking privileges for individual columns of a table.
440- One possible workaround is to create a view having just the desired
441- columns and then grant privileges to that view.
442- </para>
443-
444- <para>
445- Use <xref linkend="app-psql">'s <command>\z</command> command
446- to obtain information about existing privileges, for example:
456+ Use <xref linkend="app-psql">'s <command>\dp</command> command
457+ to obtain information about existing privileges for tables and
458+ columns. For example:
447459<programlisting>
448- => \z mytable
449- Access privileges
450- Schema | Name | Type | Access privileges
451- --------+---------+-------+-----------------------
452- public | mytable | table | miriam=arwdDxt/miriam
453- : =r/miriam
454- : admin=arw/miriam
460+ => \dp mytable
461+ Access privileges
462+ Schema | Name | Type | Access privileges | Column access privileges
463+ --------+---------+-------+-----------------------+--------------------------
464+ public | mytable | table | miriam=arwdDxt/miriam | col1:
465+ : =r/miriam : miriam_rw=rw/miriam
466+ : admin=arw/miriam
455467(1 row)
456468</programlisting>
457- The entries shown by <command>\z </command> are interpreted thus:
469+ The entries shown by <command>\dp </command> are interpreted thus:
458470<programlisting>
459471 rolename=xxxx -- privileges granted to a role
460472 =xxxx -- privileges granted to PUBLIC
@@ -471,7 +483,7 @@ GRANT <replaceable class="PARAMETER">role</replaceable> [, ...] TO <replaceable
471483 C -- CREATE
472484 c -- CONNECT
473485 T -- TEMPORARY
474- arwdDxt -- ALL PRIVILEGES (for tables)
486+ arwdDxt -- ALL PRIVILEGES (for tables, varies for other objects )
475487 * -- grant option for preceding privilege
476488
477489 /yyyy -- role that granted this privilege
@@ -483,9 +495,15 @@ GRANT <replaceable class="PARAMETER">role</replaceable> [, ...] TO <replaceable
483495<programlisting>
484496GRANT SELECT ON mytable TO PUBLIC;
485497GRANT SELECT, UPDATE, INSERT ON mytable TO admin;
498+ GRANT SELECT (col1), UPDATE (col1) ON mytable TO miriam_rw;
486499</programlisting>
487500 </para>
488501
502+ <para>
503+ For non-table objects there are other <command>\d</> commands
504+ that can display their privileges.
505+ </para>
506+
489507 <para>
490508 If the <quote>Access privileges</> column is empty for a given object,
491509 it means the object has default privileges (that is, its privileges column
@@ -495,7 +513,8 @@ GRANT SELECT, UPDATE, INSERT ON mytable TO admin;
495513 <command>REVOKE</> on an object
496514 will instantiate the default privileges (producing, for example,
497515 <literal>{miriam=arwdDxt/miriam}</>) and then modify them per the
498- specified request.
516+ specified request. Entries are shown in <quote>Column access
517+ privileges</> only for columns with nondefault privileges.
499518 </para>
500519
501520 <para>
@@ -562,11 +581,6 @@ GRANT admins TO joe;
562581 <quote>_SYSTEM</>, the owner cannot revoke these rights.
563582 </para>
564583
565- <para>
566- <productname>PostgreSQL</productname> does not support the SQL-standard
567- functionality of setting privileges for individual columns.
568- </para>
569-
570584 <para>
571585 The SQL standard provides for a <literal>USAGE</literal> privilege
572586 on other kinds of objects: character sets, collations,