Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita309032

Browse files
committed
Add current_schema() and current_schemas() inquiry functions.
Update has_table_privilege functions to cope with schema-qualifiednames in the same way as nextval() and others.
1 parentd9375ad commita309032

File tree

10 files changed

+259
-180
lines changed

10 files changed

+259
-180
lines changed

‎doc/src/sgml/func.sgml

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/func.sgml,v 1.95 2002/04/18 20:01:08 tgl Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/func.sgml,v 1.96 2002/04/26 01:24:08 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -3928,6 +3928,12 @@ SELECT TIMESTAMP 'now';
39283928
nextval('foo') <lineannotation>operates on sequence </><literal>foo</>
39293929
nextval('FOO') <lineannotation>operates on sequence </><literal>foo</>
39303930
nextval('"Foo"') <lineannotation>operates on sequence </><literal>Foo</>
3931+
</programlisting>
3932+
The sequence name can be schema-qualified if necessary:
3933+
<programlisting>
3934+
nextval('myschema.foo') <lineannotation>operates on </><literal>myschema.foo</>
3935+
nextval('"myschema".foo') <lineannotation>same as above</>
3936+
nextval('foo') <lineannotation>searches search path for </><literal>foo</>
39313937
</programlisting>
39323938
Of course, the text argument can be the result of an expression,
39333939
not only a simple literal, which is occasionally useful.
@@ -4212,17 +4218,27 @@ SELECT NULLIF(value, '(none)') ...
42124218
<row>
42134219
<entry><function>current_user</></entry>
42144220
<entry><type>name</></entry>
4215-
<entry>user name of current execution context</>
4221+
<entry>user name of current execution context</entry>
42164222
</row>
42174223
<row>
42184224
<entry><function>session_user</></entry>
42194225
<entry><type>name</></entry>
4220-
<entry>session user name</>
4226+
<entry>session user name</entry>
42214227
</row>
42224228
<row>
42234229
<entry><function>user</></entry>
42244230
<entry><type>name</></entry>
4225-
<entry>equivalent to <function>current_user</></>
4231+
<entry>equivalent to <function>current_user</></entry>
4232+
</row>
4233+
<row>
4234+
<entry><function>current_schema()</></entry>
4235+
<entry><type>name</></entry>
4236+
<entry>name of current schema</entry>
4237+
</row>
4238+
<row>
4239+
<entry><function>current_schemas()</></entry>
4240+
<entry><type>name[]</></entry>
4241+
<entry>names of schemas in search path</entry>
42264242
</row>
42274243
</tbody>
42284244
</tgroup>
@@ -4233,6 +4249,16 @@ SELECT NULLIF(value, '(none)') ...
42334249
<secondary>current</secondary>
42344250
</indexterm>
42354251

4252+
<indexterm zone="functions-misc">
4253+
<primary>schema</primary>
4254+
<secondary>current</secondary>
4255+
</indexterm>
4256+
4257+
<indexterm zone="functions-misc">
4258+
<primary>search path</primary>
4259+
<secondary>current</secondary>
4260+
</indexterm>
4261+
42364262
<para>
42374263
The <function>session_user</> is the user that initiated a database
42384264
connection; it is fixed for the duration of that connection. The
@@ -4244,10 +4270,13 @@ SELECT NULLIF(value, '(none)') ...
42444270
and the current user is the <quote>effective user</>.
42454271
</para>
42464272

4247-
<para>
4248-
Note that these functions have special syntactic status in <acronym>SQL</>:
4249-
they must be called without trailing parentheses.
4250-
</para>
4273+
<note>
4274+
<para>
4275+
<function>current_user</>, <function>session_user</>, and
4276+
<function>user</> have special syntactic status in <acronym>SQL</>:
4277+
they must be called without trailing parentheses.
4278+
</para>
4279+
</note>
42514280

42524281
<note>
42534282
<title>Deprecated</>
@@ -4257,6 +4286,17 @@ SELECT NULLIF(value, '(none)') ...
42574286
</para>
42584287
</note>
42594288

4289+
<para>
4290+
<function>current_schema</> returns the name of the schema that is
4291+
at the front of the search path (or NULL if the search path is
4292+
empty). This is the schema that will be used for any tables or
4293+
other named objects that are created without specifying a target schema.
4294+
<function>current_schemas</> returns an array of the names of all
4295+
schemas presently in the search path. Note that these functions show
4296+
only schemas that are explicitly part of the path; when a system schema
4297+
is being searched implicitly, it is not listed.
4298+
</para>
4299+
42604300
<table>
42614301
<title>System Information Functions</>
42624302
<tgroup cols="3">
@@ -4323,11 +4363,17 @@ SELECT NULLIF(value, '(none)') ...
43234363
<function>current_user</> is assumed. The table can be specified
43244364
by name or by OID. (Thus, there are actually six variants of
43254365
<function>has_table_privilege</>, which can be distinguished by
4326-
the number and types of their arguments.) The desired access type
4366+
the number and types of their arguments.) When specifying by name,
4367+
the name can be schema-qualified if necessary.
4368+
The desired access type
43274369
is specified by a text string, which must evaluate to one of the
43284370
values <literal>SELECT</>, <literal>INSERT</>, <literal>UPDATE</>,
43294371
<literal>DELETE</>, <literal>RULE</>, <literal>REFERENCES</>, or
43304372
<literal>TRIGGER</>. (Case of the string is not significant, however.)
4373+
An example is:
4374+
<programlisting>
4375+
SELECT has_table_privilege('myschema.mytable', 'select');
4376+
</programlisting>
43314377
</para>
43324378

43334379
<table>

‎doc/src/sgml/runtime.sgml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/runtime.sgml,v 1.113 2002/04/15 22:33:20 tgl Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/runtime.sgml,v 1.114 2002/04/26 01:24:08 tgl Exp $
33
-->
44

55
<Chapter Id="runtime">
@@ -1252,6 +1252,15 @@ dynamic_library_path = '/usr/local/lib/postgresql:/home/my_project/lib:$libdir'
12521252
The administrator may choose to restrict permissions on
12531253
<literal>public</> or even remove it, if that suits his purposes.
12541254
</para>
1255+
1256+
<para>
1257+
The current effective value of the search path can be examined
1258+
via the SQL function <function>current_schemas()</>. This is not
1259+
quite the same as examining the value of
1260+
<varname>search_path</varname>, since <function>current_schemas()</>
1261+
shows how the requests appearing in <varname>search_path</varname>
1262+
were resolved.
1263+
</para>
12551264
</listitem>
12561265
</varlistentry>
12571266

‎src/backend/catalog/namespace.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Portions Copyright (c) 1994, Regents of the University of California
1414
*
1515
* IDENTIFICATION
16-
* $Header: /cvsroot/pgsql/src/backend/catalog/namespace.c,v 1.12 2002/04/25 02:56:55 tgl Exp $
16+
* $Header: /cvsroot/pgsql/src/backend/catalog/namespace.c,v 1.13 2002/04/26 01:24:08 tgl Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -1470,3 +1470,14 @@ InitializeSearchPath(void)
14701470
assign_search_path(namespace_search_path);
14711471
}
14721472
}
1473+
1474+
/*
1475+
* Fetch the active search path, expressed as a List of OIDs.
1476+
*
1477+
* NB: caller must treat the list as read-only!
1478+
*/
1479+
List*
1480+
fetch_search_path(void)
1481+
{
1482+
returnnamespaceSearchPath;
1483+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp