From 4ab8e69094452286a5894f1b2b237304808f4391 Mon Sep 17 00:00:00 2001
From: Tom Lane
Date: Fri, 9 Aug 2002 16:45:16 +0000
Subject: has_table_privilege spawns scions has_database_privilege,
has_function_privilege, has_language_privilege, has_schema_privilege to let
SQL queries test all the new privilege types in 7.3. Also, add functions
pg_table_is_visible, pg_type_is_visible, pg_function_is_visible,
pg_operator_is_visible, pg_opclass_is_visible to test whether objects
contained in schemas are visible in the current search path. Do some minor
cleanup to centralize accesses to pg_database, as well.
---
doc/src/sgml/func.sgml | 256 +++++++++++++++++++++++++++++++++++++++----------
1 file changed, 208 insertions(+), 48 deletions(-)
(limited to 'doc/src')
diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml
index 8d722a91853..475af474649 100644
--- a/doc/src/sgml/func.sgml
+++ b/doc/src/sgml/func.sgml
@@ -1,5 +1,5 @@
@@ -4925,57 +4925,11 @@ select current_setting('DateStyle');
false instead. It is the equivalent to the SQL
SET command. For example:
-SHOW show_query_stats;
- show_query_stats
-------------------
- on
-(1 row)
-
select set_config('show_query_stats','off','f');
set_config
------------
off
(1 row)
-
-SHOW show_query_stats;
- show_query_stats
-------------------
- off
-(1 row)
-
-select set_config('show_query_stats','on','t');
- set_config
-------------
- on
-(1 row)
-
-SHOW show_query_stats;
- show_query_stats
-------------------
- off
-(1 row)
-
-BEGIN;
-BEGIN
-select set_config('show_query_stats','on','t');
- set_config
-------------
- on
-(1 row)
-
-SHOW show_query_stats;
- show_query_stats
-------------------
- on
-(1 row)
-
-COMMIT;
-COMMIT
-SHOW show_query_stats;
- show_query_stats
-------------------
- off
-(1 row)
@@ -5002,6 +4956,66 @@ SHOW show_query_stats;
boolean
does current user have access to table
+
+ has_database_privilege(user,
+ database,
+ access)
+
+ boolean
+ does user have access to database
+
+
+ has_database_privilege(database,
+ access)
+
+ boolean
+ does current user have access to database
+
+
+ has_function_privilege(user,
+ function,
+ access)
+
+ boolean
+ does user have access to function
+
+
+ has_function_privilege(function,
+ access)
+
+ boolean
+ does current user have access to function
+
+
+ has_language_privilege(user,
+ language,
+ access)
+
+ boolean
+ does user have access to language
+
+
+ has_language_privilege(language,
+ access)
+
+ boolean
+ does current user have access to language
+
+
+ has_schema_privilege(user,
+ schema,
+ access)
+
+ boolean
+ does user have access to schema
+
+
+ has_schema_privilege(schema,
+ access)
+
+ boolean
+ does current user have access to schema
+
@@ -5009,9 +5023,21 @@ SHOW show_query_stats;
has_table_privilege
+
+ has_database_privilege
+
+
+ has_function_privilege
+
+
+ has_language_privilege
+
+
+ has_schema_privilege
+
- has_table_privilege determines whether a user
+ has_table_privilege checks whether a user
can access a table in a particular way. The user can be
specified by name or by ID
(pg_user.usesysid), or if the argument is
@@ -5032,6 +5058,140 @@ SELECT has_table_privilege('myschema.mytable', 'select');
+
+ has_database_privilege checks whether a user
+ can access a database in a particular way. The possibilities for its
+ arguments are analogous to has_table_privilege.
+ The desired access type must evaluate to
+ CREATE,
+ TEMPORARY, or
+ TEMP (which is equivalent to
+ TEMPORARY).
+
+
+
+ has_function_privilege checks whether a user
+ can access a function in a particular way. The possibilities for its
+ arguments are analogous to has_table_privilege.
+ When specifying a function by a text string rather than by OID,
+ the allowed input is the same as for the regprocedure> datatype.
+ The desired access type must currently evaluate to
+ EXECUTE.
+
+
+
+ has_language_privilege checks whether a user
+ can access a procedural language in a particular way. The possibilities
+ for its arguments are analogous to has_table_privilege.
+ The desired access type must currently evaluate to
+ USAGE.
+
+
+
+ has_schema_privilege checks whether a user
+ can access a schema in a particular way. The possibilities for its
+ arguments are analogous to has_table_privilege.
+ The desired access type must evaluate to
+ CREATE or
+ USAGE.
+
+
+
+ Schema Visibility Inquiry Functions
+
+
+ Name Return Type Description
+
+
+
+
+ pg_table_is_visible(tableOID)
+
+ boolean
+ is table visible in search path
+
+
+ pg_type_is_visible(typeOID)
+
+ boolean
+ is type visible in search path
+
+
+ pg_function_is_visible(functionOID)
+
+ boolean
+ is function visible in search path
+
+
+ pg_operator_is_visible(operatorOID)
+
+ boolean
+ is operator visible in search path
+
+
+ pg_opclass_is_visible(opclassOID)
+
+ boolean
+ is operator class visible in search path
+
+
+
+
+
+
+ pg_table_is_visible
+
+
+ pg_type_is_visible
+
+
+ pg_function_is_visible
+
+
+ pg_operator_is_visible
+
+
+ pg_opclass_is_visible
+
+
+
+ pg_table_is_visible checks whether a table
+ (or view, or any other kind of pg_class> entry) is
+ visible> in the current schema search path. A table
+ is said to be visible if its containing schema is in the search path
+ and no table of the same name appears earlier in the search path.
+ This is equivalent to the statement that the table can be referenced
+ by name without explicit schema qualification.
+ For example, to list the names of all visible tables:
+
+SELECT relname FROM pg_class WHERE pg_table_is_visible(oid);
+
+
+
+
+ pg_type_is_visible,
+ pg_function_is_visible,
+ pg_operator_is_visible, and
+ pg_opclass_is_visible perform the same sort of
+ visibility check for types, functions, operators, and operator classes,
+ respectively. For functions and operators, an object in the search path
+ is visible if there is no object of the same name and argument
+ datatype(s)> earlier in the path. For operator classes,
+ both name and associated index access method are considered.
+
+
+
+ All these functions require object OIDs to identify the object to be
+ checked. If you want to test an object by name, it is convenient to use
+ the OID alias types (regclass>, regtype>,
+ regprocedure>, or regoperator>), for example
+
+SELECT pg_type_is_visible('myschema.widget'::regtype);
+
+ Note that it would not make much sense to test an unqualified name in
+ this way --- if the name can be recognized at all, it must be visible.
+
+
Catalog Information Functions
--
cgit v1.2.3