1
- <!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.470 2009/01/15 18:19:58 heikki Exp $ -->
1
+ <!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.471 2009/02/06 21:15:11 tgl Exp $ -->
2
2
3
3
<chapter id="functions">
4
4
<title>Functions and Operators</title>
@@ -11599,6 +11599,38 @@ SET search_path TO <replaceable>schema</> <optional>, <replaceable>schema</>, ..
11599
11599
</thead>
11600
11600
11601
11601
<tbody>
11602
+ <row>
11603
+ <entry><literal><function>has_any_column_privilege</function>(<parameter>user</parameter>,
11604
+ <parameter>table</parameter>,
11605
+ <parameter>privilege</parameter>)</literal>
11606
+ </entry>
11607
+ <entry><type>boolean</type></entry>
11608
+ <entry>does user have privilege for any column of table</entry>
11609
+ </row>
11610
+ <row>
11611
+ <entry><literal><function>has_any_column_privilege</function>(<parameter>table</parameter>,
11612
+ <parameter>privilege</parameter>)</literal>
11613
+ </entry>
11614
+ <entry><type>boolean</type></entry>
11615
+ <entry>does current user have privilege for any column of table</entry>
11616
+ </row>
11617
+ <row>
11618
+ <entry><literal><function>has_column_privilege</function>(<parameter>user</parameter>,
11619
+ <parameter>table</parameter>,
11620
+ <parameter>column</parameter>,
11621
+ <parameter>privilege</parameter>)</literal>
11622
+ </entry>
11623
+ <entry><type>boolean</type></entry>
11624
+ <entry>does user have privilege for column</entry>
11625
+ </row>
11626
+ <row>
11627
+ <entry><literal><function>has_column_privilege</function>(<parameter>table</parameter>,
11628
+ <parameter>column</parameter>,
11629
+ <parameter>privilege</parameter>)</literal>
11630
+ </entry>
11631
+ <entry><type>boolean</type></entry>
11632
+ <entry>does current user have privilege for column</entry>
11633
+ </row>
11602
11634
<row>
11603
11635
<entry><literal><function>has_database_privilege</function>(<parameter>user</parameter>,
11604
11636
<parameter>database</parameter>,
@@ -11738,6 +11770,12 @@ SET search_path TO <replaceable>schema</> <optional>, <replaceable>schema</>, ..
11738
11770
</tgroup>
11739
11771
</table>
11740
11772
11773
+ <indexterm>
11774
+ <primary>has_any_column_privilege</primary>
11775
+ </indexterm>
11776
+ <indexterm>
11777
+ <primary>has_column_privilege</primary>
11778
+ </indexterm>
11741
11779
<indexterm>
11742
11780
<primary>has_database_privilege</primary>
11743
11781
</indexterm>
@@ -11766,11 +11804,71 @@ SET search_path TO <replaceable>schema</> <optional>, <replaceable>schema</>, ..
11766
11804
<primary>pg_has_role</primary>
11767
11805
</indexterm>
11768
11806
11807
+ <para>
11808
+ <function>has_table_privilege</function> checks whether a user
11809
+ can access a table in a particular way. The user can be
11810
+ specified by name or by OID
11811
+ (<literal>pg_authid.oid</literal>), or if the argument is
11812
+ omitted
11813
+ <function>current_user</function> is assumed. The table can be specified
11814
+ by name or by OID. (Thus, there are actually six variants of
11815
+ <function>has_table_privilege</function>, which can be distinguished by
11816
+ the number and types of their arguments.) When specifying by name,
11817
+ the name can be schema-qualified if necessary.
11818
+ The desired access privilege type
11819
+ is specified by a text string, which must evaluate to one of the
11820
+ values <literal>SELECT</literal>, <literal>INSERT</literal>,
11821
+ <literal>UPDATE</literal>, <literal>DELETE</literal>, <literal>TRUNCATE</>,
11822
+ <literal>REFERENCES</literal>, or <literal>TRIGGER</literal>. Optionally,
11823
+ <literal>WITH GRANT OPTION</> can be added to a privilege type to test
11824
+ whether the privilege is held with grant option. Also, multiple privilege
11825
+ types can be listed separated by commas, in which case the result will
11826
+ be <literal>true</> if any of the listed privileges is held.
11827
+ (Case of the privilege string is not significant, and extra whitespace
11828
+ is allowed between but not within privilege names.)
11829
+ Some examples:
11830
+ <programlisting>
11831
+ SELECT has_table_privilege('myschema.mytable', 'select');
11832
+ SELECT has_table_privilege('joe', 'mytable', 'INSERT, SELECT WITH GRANT OPTION');
11833
+ </programlisting>
11834
+ </para>
11835
+
11836
+ <para>
11837
+ <function>has_any_column_privilege</function> checks whether a user can
11838
+ access any column of a table in a particular way. The possibilities for
11839
+ its arguments are the same as for <function>has_table_privilege</>,
11840
+ except that the desired access privilege type must evaluate to some
11841
+ combination of
11842
+ <literal>SELECT</literal>,
11843
+ <literal>INSERT</literal>,
11844
+ <literal>UPDATE</literal>, or
11845
+ <literal>REFERENCES</literal>. Note that having any of these privileges
11846
+ at the table level implicitly grants it for each column of the table,
11847
+ so <function>has_any_column_privilege</function> will always return
11848
+ <literal>true</> if <function>has_table_privilege</> does for the same
11849
+ arguments. But <function>has_any_column_privilege</> also succeeds if
11850
+ there is a column-level grant of the privilege for at least one column.
11851
+ </para>
11852
+
11853
+ <para>
11854
+ <function>has_column_privilege</function> checks whether a user
11855
+ can access a column in a particular way. The possibilities for its
11856
+ arguments are analogous to <function>has_table_privilege</function>,
11857
+ with the addition that the column can be specified either by name
11858
+ or attribute number.
11859
+ The desired access privilege type must evaluate to some combination of
11860
+ <literal>SELECT</literal>,
11861
+ <literal>INSERT</literal>,
11862
+ <literal>UPDATE</literal>, or
11863
+ <literal>REFERENCES</literal>. Note that having any of these privileges
11864
+ at the table level implicitly grants it for each column of the table.
11865
+ </para>
11866
+
11769
11867
<para>
11770
11868
<function>has_database_privilege</function> checks whether a user
11771
11869
can access a database in a particular way. The possibilities for its
11772
11870
arguments are analogous to <function>has_table_privilege</function>.
11773
- The desired access privilege type must evaluate to
11871
+ The desired access privilege type must evaluate to some combination of
11774
11872
<literal>CREATE</literal>,
11775
11873
<literal>CONNECT</literal>,
11776
11874
<literal>TEMPORARY</literal>, or
@@ -11813,7 +11911,7 @@ SELECT has_function_privilege('joeuser', 'myfunc(int, text)', 'execute');
11813
11911
<function>has_schema_privilege</function> checks whether a user
11814
11912
can access a schema in a particular way. The possibilities for its
11815
11913
arguments are analogous to <function>has_table_privilege</function>.
11816
- The desired access privilege type must evaluate to
11914
+ The desired access privilege type must evaluate to some combination of
11817
11915
<literal>CREATE</literal> or
11818
11916
<literal>USAGE</literal>.
11819
11917
</para>
@@ -11826,29 +11924,6 @@ SELECT has_function_privilege('joeuser', 'myfunc(int, text)', 'execute');
11826
11924
<literal>USAGE</literal>.
11827
11925
</para>
11828
11926
11829
- <para>
11830
- <function>has_table_privilege</function> checks whether a user
11831
- can access a table in a particular way. The user can be
11832
- specified by name or by OID
11833
- (<literal>pg_authid.oid</literal>), or if the argument is
11834
- omitted
11835
- <function>current_user</function> is assumed. The table can be specified
11836
- by name or by OID. (Thus, there are actually six variants of
11837
- <function>has_table_privilege</function>, which can be distinguished by
11838
- the number and types of their arguments.) When specifying by name,
11839
- the name can be schema-qualified if necessary.
11840
- The desired access privilege type
11841
- is specified by a text string, which must evaluate to one of the
11842
- values <literal>SELECT</literal>, <literal>INSERT</literal>,
11843
- <literal>UPDATE</literal>, <literal>DELETE</literal>, <literal>TRUNCATE</>,
11844
- <literal>REFERENCES</literal>, or <literal>TRIGGER</literal>.
11845
- (Case of the string is not significant, however.)
11846
- An example is:
11847
- <programlisting>
11848
- SELECT has_table_privilege('myschema.mytable', 'select');
11849
- </programlisting>
11850
- </para>
11851
-
11852
11927
<para>
11853
11928
<function>has_tablespace_privilege</function> checks whether a user
11854
11929
can access a tablespace in a particular way. The possibilities for its
@@ -11861,7 +11936,7 @@ SELECT has_table_privilege('myschema.mytable', 'select');
11861
11936
<function>pg_has_role</function> checks whether a user
11862
11937
can access a role in a particular way. The possibilities for its
11863
11938
arguments are analogous to <function>has_table_privilege</function>.
11864
- The desired access privilege type must evaluate to
11939
+ The desired access privilege type must evaluate to some combination of
11865
11940
<literal>MEMBER</literal> or
11866
11941
<literal>USAGE</literal>.
11867
11942
<literal>MEMBER</literal> denotes direct or indirect membership in
@@ -11870,12 +11945,6 @@ SELECT has_table_privilege('myschema.mytable', 'select');
11870
11945
are immediately available without doing <command>SET ROLE</>.
11871
11946
</para>
11872
11947
11873
- <para>
11874
- To test whether a user holds a grant option on the privilege,
11875
- append <literal>WITH GRANT OPTION</literal> to the privilege key
11876
- word; for example <literal>'UPDATE WITH GRANT OPTION'</literal>.
11877
- </para>
11878
-
11879
11948
<para>
11880
11949
<xref linkend="functions-info-schema-table"> shows functions that
11881
11950
determine whether a certain object is <firstterm>visible</> in the
0 commit comments