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

Commit65ab9f4

Browse files
committed
Add a couple of information functions to support direct checks on whether
a schema is our own temp schema or another backend's temp schema, and usethese in place of some former kluges in information_schema. Per myproposal of yesterday.
1 parent2a20412 commit65ab9f4

File tree

5 files changed

+67
-16
lines changed

5 files changed

+67
-16
lines changed

‎doc/src/sgml/func.sgml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.336 2006/09/10 19:03:57 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.337 2006/09/14 22:05:05 tgl Exp $ -->
22

33
<chapter id="functions">
44
<title>Functions and Operators</title>
@@ -9232,6 +9232,18 @@ select current_date + s.a as dates from generate_series(0,14,7) as s(a);
92329232
<entry>port of the local connection</entry>
92339233
</row>
92349234

9235+
<row>
9236+
<entry><literal><function>pg_my_temp_schema</function>()</literal></entry>
9237+
<entry><type>oid</type></entry>
9238+
<entry>OID of session's temporary schema, or 0 if none</entry>
9239+
</row>
9240+
9241+
<row>
9242+
<entry><literal><function>pg_is_other_temp_schema</function>(<type>oid</type>)</literal></entry>
9243+
<entry><type>boolean</type></entry>
9244+
<entry>is schema another session's temporary schema?</entry>
9245+
</row>
9246+
92359247
<row>
92369248
<entry><literal><function>pg_postmaster_start_time</function>()</literal></entry>
92379249
<entry><type>timestamp with time zone</type></entry>
@@ -9343,6 +9355,24 @@ SET search_path TO <replaceable>schema</> <optional>, <replaceable>schema</>, ..
93439355
Unix-domain socket.
93449356
</para>
93459357

9358+
<indexterm zone="functions-info">
9359+
<primary>pg_my_temp_schema</primary>
9360+
</indexterm>
9361+
9362+
<indexterm zone="functions-info">
9363+
<primary>pg_is_other_temp_schema</primary>
9364+
</indexterm>
9365+
9366+
<para>
9367+
<function>pg_my_temp_schema</function> returns the OID of the current
9368+
session's temporary schema, or 0 if it has none (because it has not
9369+
created any temporary tables).
9370+
<function>pg_is_other_temp_schema</function> returns true if the
9371+
given OID is the OID of any other session's temporary schema.
9372+
(This can be useful, for example, to exclude other sessions' temporary
9373+
tables from a catalog display.)
9374+
</para>
9375+
93469376
<indexterm zone="functions-info">
93479377
<primary>pg_postmaster_start_time</primary>
93489378
</indexterm>

‎src/backend/catalog/information_schema.sql

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* Copyright (c) 2003-2006, PostgreSQL Global Development Group
66
*
7-
* $PostgreSQL: pgsql/src/backend/catalog/information_schema.sql,v 1.36 2006/09/05 21:08:35 tgl Exp $
7+
* $PostgreSQL: pgsql/src/backend/catalog/information_schema.sql,v 1.37 2006/09/14 22:05:06 tgl Exp $
88
*/
99

1010
/*
@@ -644,7 +644,8 @@ CREATE VIEW columns AS
644644
WHEREa.attrelid=c.oid
645645
ANDa.atttypid=t.oid
646646
ANDnc.oid=c.relnamespace
647-
AND (nc.nspname NOTLIKE'pg!_temp!_%' ESCAPE'!'ORpg_catalog.pg_table_is_visible(c.oid))
647+
AND (NOT pg_is_other_temp_schema(nc.oid))
648+
648649
ANDa.attnum>0AND NOTa.attisdroppedANDc.relkindin ('r','v')
649650

650651
AND (pg_has_role(c.relowner,'USAGE')
@@ -940,7 +941,7 @@ CREATE VIEW key_column_usage AS
940941
ANDnc.oid=c.connamespace
941942
ANDc.contypeIN ('p','u','f')
942943
ANDr.relkind='r'
943-
AND (nr.nspnameNOTLIKE'pg!_temp!_%' ESCAPE'!'ORpg_catalog.pg_table_is_visible(r.oid))
944+
AND (NOTpg_is_other_temp_schema(nr.oid))
944945
AND (pg_has_role(r.relowner,'USAGE')
945946
OR has_table_privilege(c.oid,'SELECT')
946947
OR has_table_privilege(c.oid,'INSERT')
@@ -1467,7 +1468,7 @@ CREATE VIEW sequences AS
14671468
FROM pg_namespace nc, pg_class c
14681469
WHEREc.relnamespace=nc.oid
14691470
ANDc.relkind='S'
1470-
AND (nc.nspnameNOTLIKE'pg!_temp!_%' ESCAPE'!'ORpg_catalog.pg_table_is_visible(c.oid))
1471+
AND (NOTpg_is_other_temp_schema(nc.oid))
14711472
AND (pg_has_role(c.relowner,'USAGE')
14721473
OR has_table_privilege(c.oid,'SELECT')
14731474
OR has_table_privilege(c.oid,'UPDATE') );
@@ -1698,7 +1699,7 @@ CREATE VIEW table_constraints AS
16981699
WHEREnc.oid=c.connamespaceANDnr.oid=r.relnamespace
16991700
ANDc.conrelid=r.oid
17001701
ANDr.relkind='r'
1701-
AND (nr.nspnameNOTLIKE'pg!_temp!_%' ESCAPE'!'ORpg_catalog.pg_table_is_visible(r.oid))
1702+
AND (NOTpg_is_other_temp_schema(nr.oid))
17021703
AND (pg_has_role(r.relowner,'USAGE')
17031704
-- SELECT privilege omitted, per SQL standard
17041705
OR has_table_privilege(r.oid,'INSERT')
@@ -1731,7 +1732,7 @@ CREATE VIEW table_constraints AS
17311732
ANDa.attnum>0
17321733
AND NOTa.attisdropped
17331734
ANDr.relkind='r'
1734-
AND (nr.nspnameNOTLIKE'pg!_temp!_%' ESCAPE'!'ORpg_catalog.pg_table_is_visible(r.oid))
1735+
AND (NOTpg_is_other_temp_schema(nr.oid))
17351736
AND (pg_has_role(r.relowner,'USAGE')
17361737
OR has_table_privilege(r.oid,'SELECT')
17371738
OR has_table_privilege(r.oid,'INSERT')
@@ -1806,7 +1807,7 @@ CREATE VIEW tables AS
18061807
CAST(c.relnameAS sql_identifier)AS table_name,
18071808

18081809
CAST(
1809-
CASE WHENnc.nspnameLIKE'pg!_temp!_%' ESCAPE'!' THEN'LOCAL TEMPORARY'
1810+
CASE WHENnc.oid= pg_my_temp_schema() THEN'LOCAL TEMPORARY'
18101811
WHENc.relkind='r' THEN'BASE TABLE'
18111812
WHENc.relkind='v' THEN'VIEW'
18121813
ELSEnull END
@@ -1823,15 +1824,15 @@ CREATE VIEW tables AS
18231824
THEN'YES' ELSE'NO' ENDAS character_data)AS is_insertable_into,
18241825
CAST('NO'AS character_data)AS is_typed,
18251826
CAST(
1826-
CASE WHENnc.nspnameLIKE'pg!_temp!_%' ESCAPE'!'THEN'PRESERVE'
1827+
CASE WHENnc.oid= pg_my_temp_schema()THEN'PRESERVE'-- FIXME
18271828
ELSEnull END
18281829
AS character_data)AS commit_action
18291830

18301831
FROM pg_namespace nc, pg_class c
18311832

18321833
WHEREc.relnamespace=nc.oid
18331834
ANDc.relkindIN ('r','v')
1834-
AND (nc.nspnameNOTLIKE'pg!_temp!_%' ESCAPE'!'ORpg_catalog.pg_table_is_visible(c.oid))
1835+
AND (NOTpg_is_other_temp_schema(nc.oid))
18351836
AND (pg_has_role(c.relowner,'USAGE')
18361837
OR has_table_privilege(c.oid,'SELECT')
18371838
OR has_table_privilege(c.oid,'INSERT')
@@ -1952,7 +1953,7 @@ CREATE VIEW triggers AS
19521953
ANDc.oid=t.tgrelid
19531954
ANDt.tgtype &em.num<>0
19541955
AND NOTt.tgisconstraint
1955-
AND (n.nspnameNOTLIKE'pg!_temp!_%' ESCAPE'!'ORpg_catalog.pg_table_is_visible(c.oid))
1956+
AND (NOTpg_is_other_temp_schema(n.oid))
19561957
AND (pg_has_role(c.relowner,'USAGE')
19571958
-- SELECT privilege omitted, per SQL standard
19581959
OR has_table_privilege(c.oid,'INSERT')
@@ -2150,7 +2151,7 @@ CREATE VIEW views AS
21502151

21512152
WHEREc.relnamespace=nc.oid
21522153
ANDc.relkind='v'
2153-
AND (nc.nspnameNOTLIKE'pg!_temp!_%' ESCAPE'!'ORpg_catalog.pg_table_is_visible(c.oid))
2154+
AND (NOTpg_is_other_temp_schema(nc.oid))
21542155
AND (pg_has_role(c.relowner,'USAGE')
21552156
OR has_table_privilege(c.oid,'SELECT')
21562157
OR has_table_privilege(c.oid,'INSERT')

‎src/backend/catalog/namespace.c

Lines changed: 17 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-
* $PostgreSQL: pgsql/src/backend/catalog/namespace.c,v 1.86 2006/07/1414:52:17 momjian Exp $
16+
* $PostgreSQL: pgsql/src/backend/catalog/namespace.c,v 1.87 2006/09/1422:05:06 tgl Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -143,6 +143,8 @@ Datumpg_function_is_visible(PG_FUNCTION_ARGS);
143143
Datumpg_operator_is_visible(PG_FUNCTION_ARGS);
144144
Datumpg_opclass_is_visible(PG_FUNCTION_ARGS);
145145
Datumpg_conversion_is_visible(PG_FUNCTION_ARGS);
146+
Datumpg_my_temp_schema(PG_FUNCTION_ARGS);
147+
Datumpg_is_other_temp_schema(PG_FUNCTION_ARGS);
146148

147149

148150
/*
@@ -2035,3 +2037,17 @@ pg_conversion_is_visible(PG_FUNCTION_ARGS)
20352037

20362038
PG_RETURN_BOOL(ConversionIsVisible(oid));
20372039
}
2040+
2041+
Datum
2042+
pg_my_temp_schema(PG_FUNCTION_ARGS)
2043+
{
2044+
PG_RETURN_OID(myTempNamespace);
2045+
}
2046+
2047+
Datum
2048+
pg_is_other_temp_schema(PG_FUNCTION_ARGS)
2049+
{
2050+
Oidoid=PG_GETARG_OID(0);
2051+
2052+
PG_RETURN_BOOL(isOtherTempNamespace(oid));
2053+
}

‎src/include/catalog/catversion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
3838
* Portions Copyright (c) 1994, Regents of the University of California
3939
*
40-
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.355 2006/09/10 00:29:34 tgl Exp $
40+
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.356 2006/09/14 22:05:06 tgl Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO200609091
56+
#defineCATALOG_VERSION_NO200609141
5757

5858
#endif

‎src/include/catalog/pg_proc.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.423 2006/09/10 00:29:34 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.424 2006/09/14 22:05:06 tgl Exp $
1111
*
1212
* NOTES
1313
* The script catalog/genbki.sh reads this file and generates .bki
@@ -3096,6 +3096,10 @@ DATA(insert OID = 2083 ( pg_opclass_is_visiblePGNSP PGUID 12 f f t f s 1 16 "
30963096
DESCR("is opclass visible in search path?");
30973097
DATA(insertOID=2093 (pg_conversion_is_visiblePGNSPPGUID12fftfs116"26"_null__null__null_pg_conversion_is_visible-_null_ ));
30983098
DESCR("is conversion visible in search path?");
3099+
DATA(insertOID=2854 (pg_my_temp_schemaPGNSPPGUID12fftfs026""_null__null__null_pg_my_temp_schema-_null_ ));
3100+
DESCR("get OID of current session's temp schema, if any");
3101+
DATA(insertOID=2855 (pg_is_other_temp_schemaPGNSPPGUID12fftfs116"26"_null__null__null_pg_is_other_temp_schema-_null_ ));
3102+
DESCR("is schema another session's temp schema?");
30993103

31003104
DATA(insertOID=2171 (pg_cancel_backendPGNSPPGUID12fftfv116"23"_null__null__null_pg_cancel_backend-_null_ ));
31013105
DESCR("Cancel a server process' current query");

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp