From a309032d2fbb02ce43c42b5d4da2dc8328f4bc9e Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 26 Apr 2002 01:24:08 +0000 Subject: Add current_schema() and current_schemas() inquiry functions. Update has_table_privilege functions to cope with schema-qualified names in the same way as nextval() and others. --- doc/src/sgml/func.sgml | 64 ++++++++++++++++++++++++++++++++++++++++------- doc/src/sgml/runtime.sgml | 11 +++++++- 2 files changed, 65 insertions(+), 10 deletions(-) (limited to 'doc/src/sgml') diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 3ada43a7983..06af0db5fd6 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -1,5 +1,5 @@ @@ -3928,6 +3928,12 @@ SELECT TIMESTAMP 'now'; nextval('foo') operates on sequence foo nextval('FOO') operates on sequence foo nextval('"Foo"') operates on sequence Foo + + The sequence name can be schema-qualified if necessary: + +nextval('myschema.foo') operates on myschema.foo +nextval('"myschema".foo') same as above +nextval('foo') searches search path for foo Of course, the text argument can be the result of an expression, not only a simple literal, which is occasionally useful. @@ -4212,17 +4218,27 @@ SELECT NULLIF(value, '(none)') ... current_user name - user name of current execution context + user name of current execution context session_user name - session user name + session user name user name - equivalent to current_user + equivalent to current_user + + + current_schema() + name + name of current schema + + + current_schemas() + name[] + names of schemas in search path @@ -4233,6 +4249,16 @@ SELECT NULLIF(value, '(none)') ... current + + schema + current + + + + search path + current + + The session_user is the user that initiated a database connection; it is fixed for the duration of that connection. The @@ -4244,10 +4270,13 @@ SELECT NULLIF(value, '(none)') ... and the current user is the effective user. - - Note that these functions have special syntactic status in SQL: - they must be called without trailing parentheses. - + + + current_user, session_user, and + user have special syntactic status in SQL: + they must be called without trailing parentheses. + + Deprecated</> @@ -4257,6 +4286,17 @@ SELECT NULLIF(value, '(none)') ... </para> </note> + <para> + <function>current_schema</> returns the name of the schema that is + at the front of the search path (or NULL if the search path is + empty). This is the schema that will be used for any tables or + other named objects that are created without specifying a target schema. + <function>current_schemas</> returns an array of the names of all + schemas presently in the search path. Note that these functions show + only schemas that are explicitly part of the path; when a system schema + is being searched implicitly, it is not listed. + </para> + <table> <title>System Information Functions</> <tgroup cols="3"> @@ -4323,11 +4363,17 @@ SELECT NULLIF(value, '(none)') ... <function>current_user</> is assumed. The table can be specified by name or by OID. (Thus, there are actually six variants of <function>has_table_privilege</>, which can be distinguished by - the number and types of their arguments.) The desired access type + the number and types of their arguments.) When specifying by name, + the name can be schema-qualified if necessary. + The desired access type is specified by a text string, which must evaluate to one of the values <literal>SELECT</>, <literal>INSERT</>, <literal>UPDATE</>, <literal>DELETE</>, <literal>RULE</>, <literal>REFERENCES</>, or <literal>TRIGGER</>. (Case of the string is not significant, however.) + An example is: +<programlisting> +SELECT has_table_privilege('myschema.mytable', 'select'); +</programlisting> </para> <table> diff --git a/doc/src/sgml/runtime.sgml b/doc/src/sgml/runtime.sgml index babb95a4cd9..5332808fe77 100644 --- a/doc/src/sgml/runtime.sgml +++ b/doc/src/sgml/runtime.sgml @@ -1,5 +1,5 @@ <!-- -$Header: /cvsroot/pgsql/doc/src/sgml/runtime.sgml,v 1.113 2002/04/15 22:33:20 tgl Exp $ +$Header: /cvsroot/pgsql/doc/src/sgml/runtime.sgml,v 1.114 2002/04/26 01:24:08 tgl Exp $ --> <Chapter Id="runtime"> @@ -1252,6 +1252,15 @@ dynamic_library_path = '/usr/local/lib/postgresql:/home/my_project/lib:$libdir' The administrator may choose to restrict permissions on <literal>public</> or even remove it, if that suits his purposes. </para> + + <para> + The current effective value of the search path can be examined + via the SQL function <function>current_schemas()</>. This is not + quite the same as examining the value of + <varname>search_path</varname>, since <function>current_schemas()</> + shows how the requests appearing in <varname>search_path</varname> + were resolved. + </para> </listitem> </varlistentry> -- cgit v1.2.3