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 use these in place of some former kluges in information_schema. Per my proposal of yesterday.
This commit is contained in:
parent
2a20412c45
commit
65ab9f4f24
|
@ -1,4 +1,4 @@
|
|||
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.336 2006/09/10 19:03:57 tgl Exp $ -->
|
||||
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.337 2006/09/14 22:05:05 tgl Exp $ -->
|
||||
|
||||
<chapter id="functions">
|
||||
<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);
|
|||
<entry>port of the local connection</entry>
|
||||
</row>
|
||||
|
||||
<row>
|
||||
<entry><literal><function>pg_my_temp_schema</function>()</literal></entry>
|
||||
<entry><type>oid</type></entry>
|
||||
<entry>OID of session's temporary schema, or 0 if none</entry>
|
||||
</row>
|
||||
|
||||
<row>
|
||||
<entry><literal><function>pg_is_other_temp_schema</function>(<type>oid</type>)</literal></entry>
|
||||
<entry><type>boolean</type></entry>
|
||||
<entry>is schema another session's temporary schema?</entry>
|
||||
</row>
|
||||
|
||||
<row>
|
||||
<entry><literal><function>pg_postmaster_start_time</function>()</literal></entry>
|
||||
<entry><type>timestamp with time zone</type></entry>
|
||||
|
@ -9343,6 +9355,24 @@ SET search_path TO <replaceable>schema</> <optional>, <replaceable>schema</>, ..
|
|||
Unix-domain socket.
|
||||
</para>
|
||||
|
||||
<indexterm zone="functions-info">
|
||||
<primary>pg_my_temp_schema</primary>
|
||||
</indexterm>
|
||||
|
||||
<indexterm zone="functions-info">
|
||||
<primary>pg_is_other_temp_schema</primary>
|
||||
</indexterm>
|
||||
|
||||
<para>
|
||||
<function>pg_my_temp_schema</function> returns the OID of the current
|
||||
session's temporary schema, or 0 if it has none (because it has not
|
||||
created any temporary tables).
|
||||
<function>pg_is_other_temp_schema</function> returns true if the
|
||||
given OID is the OID of any other session's temporary schema.
|
||||
(This can be useful, for example, to exclude other sessions' temporary
|
||||
tables from a catalog display.)
|
||||
</para>
|
||||
|
||||
<indexterm zone="functions-info">
|
||||
<primary>pg_postmaster_start_time</primary>
|
||||
</indexterm>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* Copyright (c) 2003-2006, PostgreSQL Global Development Group
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/backend/catalog/information_schema.sql,v 1.36 2006/09/05 21:08:35 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/catalog/information_schema.sql,v 1.37 2006/09/14 22:05:06 tgl Exp $
|
||||
*/
|
||||
|
||||
/*
|
||||
|
@ -644,7 +644,8 @@ CREATE VIEW columns AS
|
|||
WHERE a.attrelid = c.oid
|
||||
AND a.atttypid = t.oid
|
||||
AND nc.oid = c.relnamespace
|
||||
AND (nc.nspname NOT LIKE 'pg!_temp!_%' ESCAPE '!' OR pg_catalog.pg_table_is_visible(c.oid))
|
||||
AND (NOT pg_is_other_temp_schema(nc.oid))
|
||||
|
||||
AND a.attnum > 0 AND NOT a.attisdropped AND c.relkind in ('r', 'v')
|
||||
|
||||
AND (pg_has_role(c.relowner, 'USAGE')
|
||||
|
@ -940,7 +941,7 @@ CREATE VIEW key_column_usage AS
|
|||
AND nc.oid = c.connamespace
|
||||
AND c.contype IN ('p', 'u', 'f')
|
||||
AND r.relkind = 'r'
|
||||
AND (nr.nspname NOT LIKE 'pg!_temp!_%' ESCAPE '!' OR pg_catalog.pg_table_is_visible(r.oid))
|
||||
AND (NOT pg_is_other_temp_schema(nr.oid))
|
||||
AND (pg_has_role(r.relowner, 'USAGE')
|
||||
OR has_table_privilege(c.oid, 'SELECT')
|
||||
OR has_table_privilege(c.oid, 'INSERT')
|
||||
|
@ -1467,7 +1468,7 @@ CREATE VIEW sequences AS
|
|||
FROM pg_namespace nc, pg_class c
|
||||
WHERE c.relnamespace = nc.oid
|
||||
AND c.relkind = 'S'
|
||||
AND (nc.nspname NOT LIKE 'pg!_temp!_%' ESCAPE '!' OR pg_catalog.pg_table_is_visible(c.oid))
|
||||
AND (NOT pg_is_other_temp_schema(nc.oid))
|
||||
AND (pg_has_role(c.relowner, 'USAGE')
|
||||
OR has_table_privilege(c.oid, 'SELECT')
|
||||
OR has_table_privilege(c.oid, 'UPDATE') );
|
||||
|
@ -1698,7 +1699,7 @@ CREATE VIEW table_constraints AS
|
|||
WHERE nc.oid = c.connamespace AND nr.oid = r.relnamespace
|
||||
AND c.conrelid = r.oid
|
||||
AND r.relkind = 'r'
|
||||
AND (nr.nspname NOT LIKE 'pg!_temp!_%' ESCAPE '!' OR pg_catalog.pg_table_is_visible(r.oid))
|
||||
AND (NOT pg_is_other_temp_schema(nr.oid))
|
||||
AND (pg_has_role(r.relowner, 'USAGE')
|
||||
-- SELECT privilege omitted, per SQL standard
|
||||
OR has_table_privilege(r.oid, 'INSERT')
|
||||
|
@ -1731,7 +1732,7 @@ CREATE VIEW table_constraints AS
|
|||
AND a.attnum > 0
|
||||
AND NOT a.attisdropped
|
||||
AND r.relkind = 'r'
|
||||
AND (nr.nspname NOT LIKE 'pg!_temp!_%' ESCAPE '!' OR pg_catalog.pg_table_is_visible(r.oid))
|
||||
AND (NOT pg_is_other_temp_schema(nr.oid))
|
||||
AND (pg_has_role(r.relowner, 'USAGE')
|
||||
OR has_table_privilege(r.oid, 'SELECT')
|
||||
OR has_table_privilege(r.oid, 'INSERT')
|
||||
|
@ -1806,7 +1807,7 @@ CREATE VIEW tables AS
|
|||
CAST(c.relname AS sql_identifier) AS table_name,
|
||||
|
||||
CAST(
|
||||
CASE WHEN nc.nspname LIKE 'pg!_temp!_%' ESCAPE '!' THEN 'LOCAL TEMPORARY'
|
||||
CASE WHEN nc.oid = pg_my_temp_schema() THEN 'LOCAL TEMPORARY'
|
||||
WHEN c.relkind = 'r' THEN 'BASE TABLE'
|
||||
WHEN c.relkind = 'v' THEN 'VIEW'
|
||||
ELSE null END
|
||||
|
@ -1823,7 +1824,7 @@ CREATE VIEW tables AS
|
|||
THEN 'YES' ELSE 'NO' END AS character_data) AS is_insertable_into,
|
||||
CAST('NO' AS character_data) AS is_typed,
|
||||
CAST(
|
||||
CASE WHEN nc.nspname LIKE 'pg!_temp!_%' ESCAPE '!' THEN 'PRESERVE'
|
||||
CASE WHEN nc.oid = pg_my_temp_schema() THEN 'PRESERVE' -- FIXME
|
||||
ELSE null END
|
||||
AS character_data) AS commit_action
|
||||
|
||||
|
@ -1831,7 +1832,7 @@ CREATE VIEW tables AS
|
|||
|
||||
WHERE c.relnamespace = nc.oid
|
||||
AND c.relkind IN ('r', 'v')
|
||||
AND (nc.nspname NOT LIKE 'pg!_temp!_%' ESCAPE '!' OR pg_catalog.pg_table_is_visible(c.oid))
|
||||
AND (NOT pg_is_other_temp_schema(nc.oid))
|
||||
AND (pg_has_role(c.relowner, 'USAGE')
|
||||
OR has_table_privilege(c.oid, 'SELECT')
|
||||
OR has_table_privilege(c.oid, 'INSERT')
|
||||
|
@ -1952,7 +1953,7 @@ CREATE VIEW triggers AS
|
|||
AND c.oid = t.tgrelid
|
||||
AND t.tgtype & em.num <> 0
|
||||
AND NOT t.tgisconstraint
|
||||
AND (n.nspname NOT LIKE 'pg!_temp!_%' ESCAPE '!' OR pg_catalog.pg_table_is_visible(c.oid))
|
||||
AND (NOT pg_is_other_temp_schema(n.oid))
|
||||
AND (pg_has_role(c.relowner, 'USAGE')
|
||||
-- SELECT privilege omitted, per SQL standard
|
||||
OR has_table_privilege(c.oid, 'INSERT')
|
||||
|
@ -2150,7 +2151,7 @@ CREATE VIEW views AS
|
|||
|
||||
WHERE c.relnamespace = nc.oid
|
||||
AND c.relkind = 'v'
|
||||
AND (nc.nspname NOT LIKE 'pg!_temp!_%' ESCAPE '!' OR pg_catalog.pg_table_is_visible(c.oid))
|
||||
AND (NOT pg_is_other_temp_schema(nc.oid))
|
||||
AND (pg_has_role(c.relowner, 'USAGE')
|
||||
OR has_table_privilege(c.oid, 'SELECT')
|
||||
OR has_table_privilege(c.oid, 'INSERT')
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/catalog/namespace.c,v 1.86 2006/07/14 14:52:17 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/catalog/namespace.c,v 1.87 2006/09/14 22:05:06 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
@ -143,6 +143,8 @@ Datum pg_function_is_visible(PG_FUNCTION_ARGS);
|
|||
Datum pg_operator_is_visible(PG_FUNCTION_ARGS);
|
||||
Datum pg_opclass_is_visible(PG_FUNCTION_ARGS);
|
||||
Datum pg_conversion_is_visible(PG_FUNCTION_ARGS);
|
||||
Datum pg_my_temp_schema(PG_FUNCTION_ARGS);
|
||||
Datum pg_is_other_temp_schema(PG_FUNCTION_ARGS);
|
||||
|
||||
|
||||
/*
|
||||
|
@ -2035,3 +2037,17 @@ pg_conversion_is_visible(PG_FUNCTION_ARGS)
|
|||
|
||||
PG_RETURN_BOOL(ConversionIsVisible(oid));
|
||||
}
|
||||
|
||||
Datum
|
||||
pg_my_temp_schema(PG_FUNCTION_ARGS)
|
||||
{
|
||||
PG_RETURN_OID(myTempNamespace);
|
||||
}
|
||||
|
||||
Datum
|
||||
pg_is_other_temp_schema(PG_FUNCTION_ARGS)
|
||||
{
|
||||
Oid oid = PG_GETARG_OID(0);
|
||||
|
||||
PG_RETURN_BOOL(isOtherTempNamespace(oid));
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.355 2006/09/10 00:29:34 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.356 2006/09/14 22:05:06 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
@ -53,6 +53,6 @@
|
|||
*/
|
||||
|
||||
/* yyyymmddN */
|
||||
#define CATALOG_VERSION_NO 200609091
|
||||
#define CATALOG_VERSION_NO 200609141
|
||||
|
||||
#endif
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.423 2006/09/10 00:29:34 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.424 2006/09/14 22:05:06 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* The script catalog/genbki.sh reads this file and generates .bki
|
||||
|
@ -3096,6 +3096,10 @@ DATA(insert OID = 2083 ( pg_opclass_is_visible PGNSP PGUID 12 f f t f s 1 16 "
|
|||
DESCR("is opclass visible in search path?");
|
||||
DATA(insert OID = 2093 ( pg_conversion_is_visible PGNSP PGUID 12 f f t f s 1 16 "26" _null_ _null_ _null_ pg_conversion_is_visible - _null_ ));
|
||||
DESCR("is conversion visible in search path?");
|
||||
DATA(insert OID = 2854 ( pg_my_temp_schema PGNSP PGUID 12 f f t f s 0 26 "" _null_ _null_ _null_ pg_my_temp_schema - _null_ ));
|
||||
DESCR("get OID of current session's temp schema, if any");
|
||||
DATA(insert OID = 2855 ( pg_is_other_temp_schema PGNSP PGUID 12 f f t f s 1 16 "26" _null_ _null_ _null_ pg_is_other_temp_schema - _null_ ));
|
||||
DESCR("is schema another session's temp schema?");
|
||||
|
||||
DATA(insert OID = 2171 ( pg_cancel_backend PGNSP PGUID 12 f f t f v 1 16 "23" _null_ _null_ _null_ pg_cancel_backend - _null_ ));
|
||||
DESCR("Cancel a server process' current query");
|
||||
|
|
Loading…
Reference in New Issue