2002-12-13 19:24:35 -05:00
|
|
|
/*
|
|
|
|
|
* SQL Information Schema
|
2019-05-14 09:15:05 -04:00
|
|
|
* as defined in ISO/IEC 9075-11:2016
|
2002-12-13 19:24:35 -05:00
|
|
|
*
|
2021-01-02 13:06:25 -05:00
|
|
|
* Copyright (c) 2003-2021, PostgreSQL Global Development Group
|
2002-12-13 19:24:35 -05:00
|
|
|
*
|
2010-09-20 16:08:53 -04:00
|
|
|
* src/backend/catalog/information_schema.sql
|
Adjust behavior of single-user -j mode for better initdb error reporting.
Previously, -j caused the entire input file to be read in and executed as
a single command string. That's undesirable, not least because any error
causes the entire file to be regurgitated as the "failing query". Some
experimentation suggests a better rule: end the command string when we see
a semicolon immediately followed by two newlines, ie, an empty line after
a query. This serves nicely to break up the existing examples such as
information_schema.sql and system_views.sql. A limitation is that it's
no longer possible to write such a sequence within a string literal or
multiline comment in a file meant to be read with -j; but there are no
instances of such a problem within the data currently used by initdb.
(If someone does make such a mistake in future, it'll be obvious because
they'll get an unterminated-literal or unterminated-comment syntax error.)
Other than that, there shouldn't be any negative consequences; you're not
forced to end statements that way, it's just a better idea in most cases.
In passing, remove src/include/tcop/tcopdebug.h, which is dead code
because it's not included anywhere, and hasn't been for more than
ten years. One of the debug-support symbols it purported to describe
has been unreferenced for at least the same amount of time, and the
other is removed by this commit on the grounds that it was useless:
forcing -j mode all the time would have broken initdb. The lack of
complaints about that, or about the missing inclusion, shows that
no one has tried to use TCOP_DONTUSENEWLINE in many years.
2015-12-17 19:34:15 -05:00
|
|
|
*
|
|
|
|
|
* Note: this file is read in single-user -j mode, which means that the
|
|
|
|
|
* command terminator is semicolon-newline-newline; whenever the backend
|
|
|
|
|
* sees that, it stops and executes what it's got. If you write a lot of
|
|
|
|
|
* statements without empty lines between, they'll all get quoted to you
|
|
|
|
|
* in any error message about one of them, so don't do that. Also, you
|
|
|
|
|
* cannot write a semicolon immediately followed by an empty line in a
|
|
|
|
|
* string literal (including a function body!) or a multiline comment.
|
2003-06-28 16:50:08 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Note: Generally, the definitions in this file should be ordered
|
|
|
|
|
* according to the clause numbers in the SQL standard, which is also the
|
|
|
|
|
* alphabetical order. In some cases it is convenient or necessary to
|
|
|
|
|
* define one information schema view by using another one; in that case,
|
|
|
|
|
* put the referencing view at the very end and leave a note where it
|
|
|
|
|
* should have been put.
|
2002-12-13 19:24:35 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2006-04-02 13:38:13 -04:00
|
|
|
* 5.1
|
2002-12-13 19:24:35 -05:00
|
|
|
* INFORMATION_SCHEMA schema
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CREATE SCHEMA information_schema;
|
|
|
|
|
GRANT USAGE ON SCHEMA information_schema TO PUBLIC;
|
2010-04-28 17:18:07 -04:00
|
|
|
SET search_path TO information_schema;
|
2002-12-13 19:24:35 -05:00
|
|
|
|
2006-04-02 13:38:13 -04:00
|
|
|
|
2004-06-22 18:30:32 -04:00
|
|
|
/*
|
|
|
|
|
* A few supporting functions first ...
|
|
|
|
|
*/
|
|
|
|
|
|
2005-05-30 23:36:24 -04:00
|
|
|
/* Expand any 1-D array into a set with integers 1..N */
|
|
|
|
|
CREATE FUNCTION _pg_expandarray(IN anyarray, OUT x anyelement, OUT n int)
|
|
|
|
|
RETURNS SETOF RECORD
|
2017-04-05 12:17:03 -04:00
|
|
|
LANGUAGE sql STRICT IMMUTABLE PARALLEL SAFE
|
2021-04-16 18:36:45 -04:00
|
|
|
AS 'select $1[s],
|
|
|
|
|
s operator(pg_catalog.-) pg_catalog.array_lower($1,1) operator(pg_catalog.+) 1
|
2005-05-30 23:36:24 -04:00
|
|
|
from pg_catalog.generate_series(pg_catalog.array_lower($1,1),
|
|
|
|
|
pg_catalog.array_upper($1,1),
|
|
|
|
|
1) as g(s)';
|
2004-06-22 18:30:32 -04:00
|
|
|
|
2006-11-10 13:10:10 -05:00
|
|
|
/* Given an index's OID and an underlying-table column number, return the
|
|
|
|
|
* column's position in the index (NULL if not there) */
|
|
|
|
|
CREATE FUNCTION _pg_index_position(oid, smallint) RETURNS int
|
|
|
|
|
LANGUAGE sql STRICT STABLE
|
2021-04-16 18:36:45 -04:00
|
|
|
BEGIN ATOMIC
|
2006-11-10 13:10:10 -05:00
|
|
|
SELECT (ss.a).n FROM
|
|
|
|
|
(SELECT information_schema._pg_expandarray(indkey) AS a
|
|
|
|
|
FROM pg_catalog.pg_index WHERE indexrelid = $1) ss
|
|
|
|
|
WHERE (ss.a).x = $2;
|
2021-04-16 18:36:45 -04:00
|
|
|
END;
|
2006-11-10 13:10:10 -05:00
|
|
|
|
2004-06-22 18:30:32 -04:00
|
|
|
CREATE FUNCTION _pg_truetypid(pg_attribute, pg_type) RETURNS oid
|
|
|
|
|
LANGUAGE sql
|
|
|
|
|
IMMUTABLE
|
2017-04-05 12:17:03 -04:00
|
|
|
PARALLEL SAFE
|
2004-06-22 18:30:32 -04:00
|
|
|
RETURNS NULL ON NULL INPUT
|
2021-04-16 18:36:45 -04:00
|
|
|
RETURN CASE WHEN $2.typtype = 'd' THEN $2.typbasetype ELSE $1.atttypid END;
|
2004-06-22 18:30:32 -04:00
|
|
|
|
|
|
|
|
CREATE FUNCTION _pg_truetypmod(pg_attribute, pg_type) RETURNS int4
|
|
|
|
|
LANGUAGE sql
|
|
|
|
|
IMMUTABLE
|
2017-04-05 12:17:03 -04:00
|
|
|
PARALLEL SAFE
|
2004-06-22 18:30:32 -04:00
|
|
|
RETURNS NULL ON NULL INPUT
|
2021-04-16 18:36:45 -04:00
|
|
|
RETURN CASE WHEN $2.typtype = 'd' THEN $2.typtypmod ELSE $1.atttypmod END;
|
2004-06-22 18:30:32 -04:00
|
|
|
|
|
|
|
|
-- these functions encapsulate knowledge about the encoding of typmod:
|
|
|
|
|
|
|
|
|
|
CREATE FUNCTION _pg_char_max_length(typid oid, typmod int4) RETURNS integer
|
|
|
|
|
LANGUAGE sql
|
|
|
|
|
IMMUTABLE
|
2017-04-05 12:17:03 -04:00
|
|
|
PARALLEL SAFE
|
2004-06-22 18:30:32 -04:00
|
|
|
RETURNS NULL ON NULL INPUT
|
2021-04-16 18:36:45 -04:00
|
|
|
RETURN
|
2004-06-22 18:30:32 -04:00
|
|
|
CASE WHEN $2 = -1 /* default typmod */
|
|
|
|
|
THEN null
|
|
|
|
|
WHEN $1 IN (1042, 1043) /* char, varchar */
|
|
|
|
|
THEN $2 - 4
|
|
|
|
|
WHEN $1 IN (1560, 1562) /* bit, varbit */
|
|
|
|
|
THEN $2
|
|
|
|
|
ELSE null
|
2021-04-16 18:36:45 -04:00
|
|
|
END;
|
2004-06-22 18:30:32 -04:00
|
|
|
|
|
|
|
|
CREATE FUNCTION _pg_char_octet_length(typid oid, typmod int4) RETURNS integer
|
|
|
|
|
LANGUAGE sql
|
|
|
|
|
IMMUTABLE
|
2017-04-05 12:17:03 -04:00
|
|
|
PARALLEL SAFE
|
2004-06-22 18:30:32 -04:00
|
|
|
RETURNS NULL ON NULL INPUT
|
2021-04-16 18:36:45 -04:00
|
|
|
RETURN
|
2004-06-22 18:30:32 -04:00
|
|
|
CASE WHEN $1 IN (25, 1042, 1043) /* text, char, varchar */
|
2009-07-07 14:23:15 -04:00
|
|
|
THEN CASE WHEN $2 = -1 /* default typmod */
|
|
|
|
|
THEN CAST(2^30 AS integer)
|
2009-07-07 15:28:00 -04:00
|
|
|
ELSE information_schema._pg_char_max_length($1, $2) *
|
|
|
|
|
pg_catalog.pg_encoding_max_length((SELECT encoding FROM pg_catalog.pg_database WHERE datname = pg_catalog.current_database()))
|
2009-07-07 14:23:15 -04:00
|
|
|
END
|
2004-06-22 18:30:32 -04:00
|
|
|
ELSE null
|
2021-04-16 18:36:45 -04:00
|
|
|
END;
|
2004-06-22 18:30:32 -04:00
|
|
|
|
|
|
|
|
CREATE FUNCTION _pg_numeric_precision(typid oid, typmod int4) RETURNS integer
|
|
|
|
|
LANGUAGE sql
|
|
|
|
|
IMMUTABLE
|
2017-04-05 12:17:03 -04:00
|
|
|
PARALLEL SAFE
|
2004-06-22 18:30:32 -04:00
|
|
|
RETURNS NULL ON NULL INPUT
|
2021-04-16 18:36:45 -04:00
|
|
|
RETURN
|
2004-06-22 18:30:32 -04:00
|
|
|
CASE $1
|
|
|
|
|
WHEN 21 /*int2*/ THEN 16
|
|
|
|
|
WHEN 23 /*int4*/ THEN 32
|
|
|
|
|
WHEN 20 /*int8*/ THEN 64
|
|
|
|
|
WHEN 1700 /*numeric*/ THEN
|
|
|
|
|
CASE WHEN $2 = -1
|
|
|
|
|
THEN null
|
|
|
|
|
ELSE (($2 - 4) >> 16) & 65535
|
|
|
|
|
END
|
|
|
|
|
WHEN 700 /*float4*/ THEN 24 /*FLT_MANT_DIG*/
|
|
|
|
|
WHEN 701 /*float8*/ THEN 53 /*DBL_MANT_DIG*/
|
|
|
|
|
ELSE null
|
2021-04-16 18:36:45 -04:00
|
|
|
END;
|
2004-06-22 18:30:32 -04:00
|
|
|
|
|
|
|
|
CREATE FUNCTION _pg_numeric_precision_radix(typid oid, typmod int4) RETURNS integer
|
|
|
|
|
LANGUAGE sql
|
|
|
|
|
IMMUTABLE
|
2017-04-05 12:17:03 -04:00
|
|
|
PARALLEL SAFE
|
2004-06-22 18:30:32 -04:00
|
|
|
RETURNS NULL ON NULL INPUT
|
2021-04-16 18:36:45 -04:00
|
|
|
RETURN
|
2004-06-22 18:30:32 -04:00
|
|
|
CASE WHEN $1 IN (21, 23, 20, 700, 701) THEN 2
|
|
|
|
|
WHEN $1 IN (1700) THEN 10
|
|
|
|
|
ELSE null
|
2021-04-16 18:36:45 -04:00
|
|
|
END;
|
2004-06-22 18:30:32 -04:00
|
|
|
|
|
|
|
|
CREATE FUNCTION _pg_numeric_scale(typid oid, typmod int4) RETURNS integer
|
|
|
|
|
LANGUAGE sql
|
|
|
|
|
IMMUTABLE
|
2017-04-05 12:17:03 -04:00
|
|
|
PARALLEL SAFE
|
2004-06-22 18:30:32 -04:00
|
|
|
RETURNS NULL ON NULL INPUT
|
2021-04-16 18:36:45 -04:00
|
|
|
RETURN
|
2004-06-22 18:30:32 -04:00
|
|
|
CASE WHEN $1 IN (21, 23, 20) THEN 0
|
|
|
|
|
WHEN $1 IN (1700) THEN
|
|
|
|
|
CASE WHEN $2 = -1
|
|
|
|
|
THEN null
|
|
|
|
|
ELSE ($2 - 4) & 65535
|
|
|
|
|
END
|
|
|
|
|
ELSE null
|
2021-04-16 18:36:45 -04:00
|
|
|
END;
|
2004-06-22 18:30:32 -04:00
|
|
|
|
|
|
|
|
CREATE FUNCTION _pg_datetime_precision(typid oid, typmod int4) RETURNS integer
|
|
|
|
|
LANGUAGE sql
|
|
|
|
|
IMMUTABLE
|
2017-04-05 12:17:03 -04:00
|
|
|
PARALLEL SAFE
|
2004-06-22 18:30:32 -04:00
|
|
|
RETURNS NULL ON NULL INPUT
|
2021-04-16 18:36:45 -04:00
|
|
|
RETURN
|
2009-06-10 03:03:34 -04:00
|
|
|
CASE WHEN $1 IN (1082) /* date */
|
|
|
|
|
THEN 0
|
2004-06-22 18:30:32 -04:00
|
|
|
WHEN $1 IN (1083, 1114, 1184, 1266) /* time, timestamp, same + tz */
|
2009-06-10 03:03:34 -04:00
|
|
|
THEN CASE WHEN $2 < 0 THEN 6 ELSE $2 END
|
2004-06-22 18:30:32 -04:00
|
|
|
WHEN $1 IN (1186) /* interval */
|
2011-07-13 13:30:40 -04:00
|
|
|
THEN CASE WHEN $2 < 0 OR $2 & 65535 = 65535 THEN 6 ELSE $2 & 65535 END
|
|
|
|
|
ELSE null
|
2021-04-16 18:36:45 -04:00
|
|
|
END;
|
2011-07-13 13:30:40 -04:00
|
|
|
|
|
|
|
|
CREATE FUNCTION _pg_interval_type(typid oid, mod int4) RETURNS text
|
|
|
|
|
LANGUAGE sql
|
|
|
|
|
IMMUTABLE
|
2017-04-05 12:17:03 -04:00
|
|
|
PARALLEL SAFE
|
2011-07-13 13:30:40 -04:00
|
|
|
RETURNS NULL ON NULL INPUT
|
2021-04-16 18:36:45 -04:00
|
|
|
RETURN
|
2011-07-13 13:30:40 -04:00
|
|
|
CASE WHEN $1 IN (1186) /* interval */
|
2020-06-29 05:04:42 -04:00
|
|
|
THEN pg_catalog.upper(substring(pg_catalog.format_type($1, $2) similar 'interval[()0-9]* #"%#"' escape '#'))
|
2004-06-22 18:30:32 -04:00
|
|
|
ELSE null
|
2021-04-16 18:36:45 -04:00
|
|
|
END;
|
2004-06-22 18:30:32 -04:00
|
|
|
|
2002-12-13 19:24:35 -05:00
|
|
|
|
2006-04-02 13:38:13 -04:00
|
|
|
-- 5.2 INFORMATION_SCHEMA_CATALOG_NAME view appears later.
|
2002-12-13 19:24:35 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2006-04-02 13:38:13 -04:00
|
|
|
* 5.3
|
2002-12-13 19:24:35 -05:00
|
|
|
* CARDINAL_NUMBER domain
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CREATE DOMAIN cardinal_number AS integer
|
|
|
|
|
CONSTRAINT cardinal_number_domain_check CHECK (value >= 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2006-04-02 13:38:13 -04:00
|
|
|
* 5.4
|
2002-12-13 19:24:35 -05:00
|
|
|
* CHARACTER_DATA domain
|
|
|
|
|
*/
|
|
|
|
|
|
Make collation-aware system catalog columns use "C" collation.
Up to now we allowed text columns in system catalogs to use collation
"default", but that isn't really safe because it might mean something
different in template0 than it means in a database cloned from template0.
In particular, this could mean that cloned pg_statistic entries for such
columns weren't entirely valid, possibly leading to bogus planner
estimates, though (probably) not any outright failures.
In the wake of commit 5e0928005, a better solution is available: if we
label such columns with "C" collation, then their pg_statistic entries
will also use that collation and hence will be valid independently of
the database collation.
This also provides a cleaner solution for indexes on such columns than
the hack added by commit 0b28ea79c: the indexes will naturally inherit
"C" collation and don't have to be forced to use text_pattern_ops.
Also, with the planned improvement of type "name" to be collation-aware,
this policy will apply cleanly to both text and name columns.
Because of the pg_statistic angle, we should also apply this policy
to the tables in information_schema. This patch does that by adjusting
information_schema's textual domain types to specify "C" collation.
That has the user-visible effect that order-sensitive comparisons to
textual information_schema view columns will now use "C" collation
by default. The SQL standard says that the collation of those view
columns is implementation-defined, so I think this is legal per spec.
At some point this might allow for translation of such comparisons
into indexable conditions on the underlying "name" columns, although
additional work will be needed before that can happen.
Discussion: https://postgr.es/m/19346.1544895309@sss.pgh.pa.us
2018-12-18 12:48:15 -05:00
|
|
|
CREATE DOMAIN character_data AS character varying COLLATE "C";
|
2002-12-13 19:24:35 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2006-04-02 13:38:13 -04:00
|
|
|
* 5.5
|
2002-12-13 19:24:35 -05:00
|
|
|
* SQL_IDENTIFIER domain
|
|
|
|
|
*/
|
|
|
|
|
|
Base information_schema.sql_identifier domain on name, not varchar.
The SQL spec says that sql_identifier is a domain over varchar,
but it also says that that domain is supposed to represent the set
of valid identifiers for the implementation, in particular applying
a length limit matching the implementation's identifier length limit.
We were declaring sql_identifier as just "character varying", thus
duplicating what the spec says about base type, but entirely failing
at the rest of it.
Instead, let's declare sql_identifier as a domain over type "name".
(We can drop the COLLATE "C" added by commit 6b0faf723, since that's
now implicit in "name".) With the recent improvements to name's
comparison support, there's not a lot of functional difference between
name and varchar. So although in principle this is a spec deviation,
it's a pretty minor one. And correctly enforcing PG's name length limit
is a good thing; on balance this seems closer to the intent of the spec
than what we had.
But that's all just language-lawyering. The *real* reason to do this is
that it makes sql_identifier columns exposed by information_schema views
be just direct representations of the underlying "name" catalog columns,
eliminating a semantic mismatch that was disastrous for performance of
typical queries on the information_schema. In combination with the
recent change to allow dropping no-op CoerceToDomain nodes, this allows
(for example) queries such as
select ... from information_schema.tables where table_name = 'foo';
to produce an indexscan rather than a seqscan on pg_class.
Discussion: https://postgr.es/m/CAFj8pRBUCX4LZ2rA2BbEkdD6NN59mgx+BLo1gO08Wod4RLtcTg@mail.gmail.com
2018-12-20 16:21:51 -05:00
|
|
|
CREATE DOMAIN sql_identifier AS name;
|
2002-12-13 19:24:35 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2006-04-02 13:38:13 -04:00
|
|
|
* 5.2
|
2002-12-13 19:24:35 -05:00
|
|
|
* INFORMATION_SCHEMA_CATALOG_NAME view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CREATE VIEW information_schema_catalog_name AS
|
|
|
|
|
SELECT CAST(current_database() AS sql_identifier) AS catalog_name;
|
|
|
|
|
|
|
|
|
|
GRANT SELECT ON information_schema_catalog_name TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2006-04-02 13:38:13 -04:00
|
|
|
* 5.6
|
2002-12-13 19:24:35 -05:00
|
|
|
* TIME_STAMP domain
|
|
|
|
|
*/
|
|
|
|
|
|
2006-04-02 13:38:13 -04:00
|
|
|
CREATE DOMAIN time_stamp AS timestamp(2) with time zone
|
2002-12-13 19:24:35 -05:00
|
|
|
DEFAULT current_timestamp(2);
|
|
|
|
|
|
2009-07-13 16:25:57 -04:00
|
|
|
/*
|
|
|
|
|
* 5.7
|
|
|
|
|
* YES_OR_NO domain
|
|
|
|
|
*/
|
|
|
|
|
|
Make collation-aware system catalog columns use "C" collation.
Up to now we allowed text columns in system catalogs to use collation
"default", but that isn't really safe because it might mean something
different in template0 than it means in a database cloned from template0.
In particular, this could mean that cloned pg_statistic entries for such
columns weren't entirely valid, possibly leading to bogus planner
estimates, though (probably) not any outright failures.
In the wake of commit 5e0928005, a better solution is available: if we
label such columns with "C" collation, then their pg_statistic entries
will also use that collation and hence will be valid independently of
the database collation.
This also provides a cleaner solution for indexes on such columns than
the hack added by commit 0b28ea79c: the indexes will naturally inherit
"C" collation and don't have to be forced to use text_pattern_ops.
Also, with the planned improvement of type "name" to be collation-aware,
this policy will apply cleanly to both text and name columns.
Because of the pg_statistic angle, we should also apply this policy
to the tables in information_schema. This patch does that by adjusting
information_schema's textual domain types to specify "C" collation.
That has the user-visible effect that order-sensitive comparisons to
textual information_schema view columns will now use "C" collation
by default. The SQL standard says that the collation of those view
columns is implementation-defined, so I think this is legal per spec.
At some point this might allow for translation of such comparisons
into indexable conditions on the underlying "name" columns, although
additional work will be needed before that can happen.
Discussion: https://postgr.es/m/19346.1544895309@sss.pgh.pa.us
2018-12-18 12:48:15 -05:00
|
|
|
CREATE DOMAIN yes_or_no AS character varying(3) COLLATE "C"
|
2009-07-13 16:25:57 -04:00
|
|
|
CONSTRAINT yes_or_no_check CHECK (value IN ('YES', 'NO'));
|
2002-12-13 19:24:35 -05:00
|
|
|
|
2009-07-13 16:25:57 -04:00
|
|
|
|
|
|
|
|
-- 5.8 ADMINISTRABLE_ROLE_AUTHORIZATIONS view appears later.
|
2006-04-02 13:38:13 -04:00
|
|
|
|
|
|
|
|
|
2003-06-29 11:14:41 -04:00
|
|
|
/*
|
2009-07-13 16:25:57 -04:00
|
|
|
* 5.9
|
2003-06-29 11:14:41 -04:00
|
|
|
* APPLICABLE_ROLES view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CREATE VIEW applicable_roles AS
|
2005-07-25 20:04:19 -04:00
|
|
|
SELECT CAST(a.rolname AS sql_identifier) AS grantee,
|
|
|
|
|
CAST(b.rolname AS sql_identifier) AS role_name,
|
2009-07-13 16:25:57 -04:00
|
|
|
CAST(CASE WHEN m.admin_option THEN 'YES' ELSE 'NO' END AS yes_or_no) AS is_grantable
|
2021-03-26 13:42:17 -04:00
|
|
|
FROM (SELECT member, roleid, admin_option FROM pg_auth_members
|
|
|
|
|
-- This UNION could be UNION ALL, but UNION works even if we start
|
|
|
|
|
-- to allow explicit pg_database_owner membership.
|
|
|
|
|
UNION
|
|
|
|
|
SELECT datdba, pg_authid.oid, false
|
|
|
|
|
FROM pg_database, pg_authid
|
|
|
|
|
WHERE datname = current_database() AND rolname = 'pg_database_owner'
|
|
|
|
|
) m
|
2005-07-25 20:04:19 -04:00
|
|
|
JOIN pg_authid a ON (m.member = a.oid)
|
|
|
|
|
JOIN pg_authid b ON (m.roleid = b.oid)
|
2006-04-02 13:38:13 -04:00
|
|
|
WHERE pg_has_role(a.oid, 'USAGE');
|
2003-06-29 11:14:41 -04:00
|
|
|
|
|
|
|
|
GRANT SELECT ON applicable_roles TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
2002-12-13 19:24:35 -05:00
|
|
|
/*
|
2009-07-13 16:25:57 -04:00
|
|
|
* 5.8
|
2006-04-02 13:38:13 -04:00
|
|
|
* ADMINISTRABLE_ROLE_AUTHORIZATIONS view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CREATE VIEW administrable_role_authorizations AS
|
|
|
|
|
SELECT *
|
|
|
|
|
FROM applicable_roles
|
|
|
|
|
WHERE is_grantable = 'YES';
|
|
|
|
|
|
|
|
|
|
GRANT SELECT ON administrable_role_authorizations TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2009-07-13 16:25:57 -04:00
|
|
|
* 5.10
|
2006-04-02 13:38:13 -04:00
|
|
|
* ASSERTIONS view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
-- feature not supported
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2009-07-13 16:25:57 -04:00
|
|
|
* 5.11
|
2006-04-02 13:38:13 -04:00
|
|
|
* ATTRIBUTES view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CREATE VIEW attributes AS
|
|
|
|
|
SELECT CAST(current_database() AS sql_identifier) AS udt_catalog,
|
|
|
|
|
CAST(nc.nspname AS sql_identifier) AS udt_schema,
|
|
|
|
|
CAST(c.relname AS sql_identifier) AS udt_name,
|
|
|
|
|
CAST(a.attname AS sql_identifier) AS attribute_name,
|
|
|
|
|
CAST(a.attnum AS cardinal_number) AS ordinal_position,
|
|
|
|
|
CAST(pg_get_expr(ad.adbin, ad.adrelid) AS character_data) AS attribute_default,
|
|
|
|
|
CAST(CASE WHEN a.attnotnull OR (t.typtype = 'd' AND t.typnotnull) THEN 'NO' ELSE 'YES' END
|
2009-07-13 16:25:57 -04:00
|
|
|
AS yes_or_no)
|
2011-06-14 15:53:02 -04:00
|
|
|
AS is_nullable, -- This column was apparently removed between SQL:2003 and SQL:2008.
|
2006-04-02 13:38:13 -04:00
|
|
|
|
|
|
|
|
CAST(
|
|
|
|
|
CASE WHEN t.typelem <> 0 AND t.typlen = -1 THEN 'ARRAY'
|
|
|
|
|
WHEN nt.nspname = 'pg_catalog' THEN format_type(a.atttypid, null)
|
|
|
|
|
ELSE 'USER-DEFINED' END
|
|
|
|
|
AS character_data)
|
|
|
|
|
AS data_type,
|
|
|
|
|
|
|
|
|
|
CAST(
|
|
|
|
|
_pg_char_max_length(_pg_truetypid(a, t), _pg_truetypmod(a, t))
|
|
|
|
|
AS cardinal_number)
|
|
|
|
|
AS character_maximum_length,
|
|
|
|
|
|
|
|
|
|
CAST(
|
|
|
|
|
_pg_char_octet_length(_pg_truetypid(a, t), _pg_truetypmod(a, t))
|
|
|
|
|
AS cardinal_number)
|
|
|
|
|
AS character_octet_length,
|
|
|
|
|
|
|
|
|
|
CAST(null AS sql_identifier) AS character_set_catalog,
|
|
|
|
|
CAST(null AS sql_identifier) AS character_set_schema,
|
|
|
|
|
CAST(null AS sql_identifier) AS character_set_name,
|
|
|
|
|
|
2011-06-28 10:49:28 -04:00
|
|
|
CAST(CASE WHEN nco.nspname IS NOT NULL THEN current_database() END AS sql_identifier) AS collation_catalog,
|
|
|
|
|
CAST(nco.nspname AS sql_identifier) AS collation_schema,
|
|
|
|
|
CAST(co.collname AS sql_identifier) AS collation_name,
|
2006-04-02 13:38:13 -04:00
|
|
|
|
|
|
|
|
CAST(
|
|
|
|
|
_pg_numeric_precision(_pg_truetypid(a, t), _pg_truetypmod(a, t))
|
|
|
|
|
AS cardinal_number)
|
|
|
|
|
AS numeric_precision,
|
|
|
|
|
|
|
|
|
|
CAST(
|
|
|
|
|
_pg_numeric_precision_radix(_pg_truetypid(a, t), _pg_truetypmod(a, t))
|
|
|
|
|
AS cardinal_number)
|
|
|
|
|
AS numeric_precision_radix,
|
|
|
|
|
|
|
|
|
|
CAST(
|
|
|
|
|
_pg_numeric_scale(_pg_truetypid(a, t), _pg_truetypmod(a, t))
|
|
|
|
|
AS cardinal_number)
|
|
|
|
|
AS numeric_scale,
|
|
|
|
|
|
|
|
|
|
CAST(
|
|
|
|
|
_pg_datetime_precision(_pg_truetypid(a, t), _pg_truetypmod(a, t))
|
|
|
|
|
AS cardinal_number)
|
|
|
|
|
AS datetime_precision,
|
|
|
|
|
|
2011-07-13 13:30:40 -04:00
|
|
|
CAST(
|
|
|
|
|
_pg_interval_type(_pg_truetypid(a, t), _pg_truetypmod(a, t))
|
|
|
|
|
AS character_data)
|
|
|
|
|
AS interval_type,
|
2011-07-11 11:49:44 -04:00
|
|
|
CAST(null AS cardinal_number) AS interval_precision,
|
2006-04-02 13:38:13 -04:00
|
|
|
|
|
|
|
|
CAST(current_database() AS sql_identifier) AS attribute_udt_catalog,
|
|
|
|
|
CAST(nt.nspname AS sql_identifier) AS attribute_udt_schema,
|
|
|
|
|
CAST(t.typname AS sql_identifier) AS attribute_udt_name,
|
|
|
|
|
|
|
|
|
|
CAST(null AS sql_identifier) AS scope_catalog,
|
|
|
|
|
CAST(null AS sql_identifier) AS scope_schema,
|
|
|
|
|
CAST(null AS sql_identifier) AS scope_name,
|
|
|
|
|
|
|
|
|
|
CAST(null AS cardinal_number) AS maximum_cardinality,
|
|
|
|
|
CAST(a.attnum AS sql_identifier) AS dtd_identifier,
|
2009-07-13 16:25:57 -04:00
|
|
|
CAST('NO' AS yes_or_no) AS is_derived_reference_attribute
|
2006-04-02 13:38:13 -04:00
|
|
|
|
2011-06-28 10:49:28 -04:00
|
|
|
FROM (pg_attribute a LEFT JOIN pg_attrdef ad ON attrelid = adrelid AND attnum = adnum)
|
|
|
|
|
JOIN (pg_class c JOIN pg_namespace nc ON (c.relnamespace = nc.oid)) ON a.attrelid = c.oid
|
|
|
|
|
JOIN (pg_type t JOIN pg_namespace nt ON (t.typnamespace = nt.oid)) ON a.atttypid = t.oid
|
|
|
|
|
LEFT JOIN (pg_collation co JOIN pg_namespace nco ON (co.collnamespace = nco.oid))
|
|
|
|
|
ON a.attcollation = co.oid AND (nco.nspname, co.collname) <> ('pg_catalog', 'default')
|
2006-04-02 13:38:13 -04:00
|
|
|
|
2011-06-28 10:49:28 -04:00
|
|
|
WHERE a.attnum > 0 AND NOT a.attisdropped
|
2017-03-10 13:15:47 -05:00
|
|
|
AND c.relkind IN ('c')
|
2011-12-19 17:05:19 -05:00
|
|
|
AND (pg_has_role(c.relowner, 'USAGE')
|
|
|
|
|
OR has_type_privilege(c.reltype, 'USAGE'));
|
2006-04-02 13:38:13 -04:00
|
|
|
|
|
|
|
|
GRANT SELECT ON attributes TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2009-07-13 16:25:57 -04:00
|
|
|
* 5.12
|
2006-04-02 13:38:13 -04:00
|
|
|
* CHARACTER_SETS view
|
|
|
|
|
*/
|
|
|
|
|
|
2011-02-09 16:26:48 -05:00
|
|
|
CREATE VIEW character_sets AS
|
|
|
|
|
SELECT CAST(null AS sql_identifier) AS character_set_catalog,
|
|
|
|
|
CAST(null AS sql_identifier) AS character_set_schema,
|
|
|
|
|
CAST(getdatabaseencoding() AS sql_identifier) AS character_set_name,
|
|
|
|
|
CAST(CASE WHEN getdatabaseencoding() = 'UTF8' THEN 'UCS' ELSE getdatabaseencoding() END AS sql_identifier) AS character_repertoire,
|
|
|
|
|
CAST(getdatabaseencoding() AS sql_identifier) AS form_of_use,
|
|
|
|
|
CAST(current_database() AS sql_identifier) AS default_collate_catalog,
|
|
|
|
|
CAST(nc.nspname AS sql_identifier) AS default_collate_schema,
|
|
|
|
|
CAST(c.collname AS sql_identifier) AS default_collate_name
|
|
|
|
|
FROM pg_database d
|
|
|
|
|
LEFT JOIN (pg_collation c JOIN pg_namespace nc ON (c.collnamespace = nc.oid))
|
|
|
|
|
ON (datcollate = collcollate AND datctype = collctype)
|
|
|
|
|
WHERE d.datname = current_database()
|
|
|
|
|
ORDER BY char_length(c.collname) DESC, c.collname ASC -- prefer full/canonical name
|
|
|
|
|
LIMIT 1;
|
|
|
|
|
|
|
|
|
|
GRANT SELECT ON character_sets TO PUBLIC;
|
2006-04-02 13:38:13 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2009-07-13 16:25:57 -04:00
|
|
|
* 5.13
|
2006-04-02 13:38:13 -04:00
|
|
|
* CHECK_CONSTRAINT_ROUTINE_USAGE view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CREATE VIEW check_constraint_routine_usage AS
|
2021-04-21 05:54:47 -04:00
|
|
|
SELECT DISTINCT
|
|
|
|
|
CAST(current_database() AS sql_identifier) AS constraint_catalog,
|
2006-04-02 13:38:13 -04:00
|
|
|
CAST(nc.nspname AS sql_identifier) AS constraint_schema,
|
|
|
|
|
CAST(c.conname AS sql_identifier) AS constraint_name,
|
|
|
|
|
CAST(current_database() AS sql_identifier) AS specific_catalog,
|
|
|
|
|
CAST(np.nspname AS sql_identifier) AS specific_schema,
|
2018-12-20 15:58:58 -05:00
|
|
|
CAST(nameconcatoid(p.proname, p.oid) AS sql_identifier) AS specific_name
|
2006-04-02 13:38:13 -04:00
|
|
|
FROM pg_namespace nc, pg_constraint c, pg_depend d, pg_proc p, pg_namespace np
|
|
|
|
|
WHERE nc.oid = c.connamespace
|
|
|
|
|
AND c.contype = 'c'
|
|
|
|
|
AND c.oid = d.objid
|
|
|
|
|
AND d.classid = 'pg_catalog.pg_constraint'::regclass
|
|
|
|
|
AND d.refobjid = p.oid
|
|
|
|
|
AND d.refclassid = 'pg_catalog.pg_proc'::regclass
|
|
|
|
|
AND p.pronamespace = np.oid
|
|
|
|
|
AND pg_has_role(p.proowner, 'USAGE');
|
|
|
|
|
|
|
|
|
|
GRANT SELECT ON check_constraint_routine_usage TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2009-07-13 16:25:57 -04:00
|
|
|
* 5.14
|
2002-12-13 19:24:35 -05:00
|
|
|
* CHECK_CONSTRAINTS view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CREATE VIEW check_constraints AS
|
|
|
|
|
SELECT CAST(current_database() AS sql_identifier) AS constraint_catalog,
|
|
|
|
|
CAST(rs.nspname AS sql_identifier) AS constraint_schema,
|
|
|
|
|
CAST(con.conname AS sql_identifier) AS constraint_name,
|
2003-10-18 08:53:35 -04:00
|
|
|
CAST(substring(pg_get_constraintdef(con.oid) from 7) AS character_data)
|
|
|
|
|
AS check_clause
|
2005-07-25 20:04:19 -04:00
|
|
|
FROM pg_constraint con
|
|
|
|
|
LEFT OUTER JOIN pg_namespace rs ON (rs.oid = con.connamespace)
|
2003-06-17 14:00:48 -04:00
|
|
|
LEFT OUTER JOIN pg_class c ON (c.oid = con.conrelid)
|
2005-07-25 20:04:19 -04:00
|
|
|
LEFT OUTER JOIN pg_type t ON (t.oid = con.contypid)
|
2006-04-02 13:38:13 -04:00
|
|
|
WHERE pg_has_role(coalesce(c.relowner, t.typowner), 'USAGE')
|
|
|
|
|
AND con.contype = 'c'
|
|
|
|
|
|
|
|
|
|
UNION
|
|
|
|
|
-- not-null constraints
|
|
|
|
|
|
|
|
|
|
SELECT CAST(current_database() AS sql_identifier) AS constraint_catalog,
|
|
|
|
|
CAST(n.nspname AS sql_identifier) AS constraint_schema,
|
2007-02-27 13:49:43 -05:00
|
|
|
CAST(CAST(n.oid AS text) || '_' || CAST(r.oid AS text) || '_' || CAST(a.attnum AS text) || '_not_null' AS sql_identifier) AS constraint_name, -- XXX
|
2006-04-02 13:38:13 -04:00
|
|
|
CAST(a.attname || ' IS NOT NULL' AS character_data)
|
|
|
|
|
AS check_clause
|
|
|
|
|
FROM pg_namespace n, pg_class r, pg_attribute a
|
|
|
|
|
WHERE n.oid = r.relnamespace
|
|
|
|
|
AND r.oid = a.attrelid
|
|
|
|
|
AND a.attnum > 0
|
|
|
|
|
AND NOT a.attisdropped
|
|
|
|
|
AND a.attnotnull
|
2017-03-10 13:15:47 -05:00
|
|
|
AND r.relkind IN ('r', 'p')
|
2006-04-02 13:38:13 -04:00
|
|
|
AND pg_has_role(r.relowner, 'USAGE');
|
2002-12-13 19:24:35 -05:00
|
|
|
|
|
|
|
|
GRANT SELECT ON check_constraints TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2009-07-13 16:25:57 -04:00
|
|
|
* 5.15
|
2006-04-02 13:38:13 -04:00
|
|
|
* COLLATIONS view
|
|
|
|
|
*/
|
|
|
|
|
|
2011-02-09 16:26:48 -05:00
|
|
|
CREATE VIEW collations AS
|
|
|
|
|
SELECT CAST(current_database() AS sql_identifier) AS collation_catalog,
|
|
|
|
|
CAST(nc.nspname AS sql_identifier) AS collation_schema,
|
|
|
|
|
CAST(c.collname AS sql_identifier) AS collation_name,
|
|
|
|
|
CAST('NO PAD' AS character_data) AS pad_attribute
|
|
|
|
|
FROM pg_collation c, pg_namespace nc
|
|
|
|
|
WHERE c.collnamespace = nc.oid
|
2011-03-11 13:20:11 -05:00
|
|
|
AND collencoding IN (-1, (SELECT encoding FROM pg_database WHERE datname = current_database()));
|
2011-02-09 16:26:48 -05:00
|
|
|
|
|
|
|
|
GRANT SELECT ON collations TO PUBLIC;
|
|
|
|
|
|
2006-04-02 13:38:13 -04:00
|
|
|
|
|
|
|
|
/*
|
2009-07-13 16:25:57 -04:00
|
|
|
* 5.16
|
2006-04-02 13:38:13 -04:00
|
|
|
* COLLATION_CHARACTER_SET_APPLICABILITY view
|
|
|
|
|
*/
|
|
|
|
|
|
2011-02-09 16:26:48 -05:00
|
|
|
CREATE VIEW collation_character_set_applicability AS
|
|
|
|
|
SELECT CAST(current_database() AS sql_identifier) AS collation_catalog,
|
|
|
|
|
CAST(nc.nspname AS sql_identifier) AS collation_schema,
|
|
|
|
|
CAST(c.collname AS sql_identifier) AS collation_name,
|
|
|
|
|
CAST(null AS sql_identifier) AS character_set_catalog,
|
|
|
|
|
CAST(null AS sql_identifier) AS character_set_schema,
|
|
|
|
|
CAST(getdatabaseencoding() AS sql_identifier) AS character_set_name
|
|
|
|
|
FROM pg_collation c, pg_namespace nc
|
|
|
|
|
WHERE c.collnamespace = nc.oid
|
2011-03-11 13:20:11 -05:00
|
|
|
AND collencoding IN (-1, (SELECT encoding FROM pg_database WHERE datname = current_database()));
|
2011-02-09 16:26:48 -05:00
|
|
|
|
|
|
|
|
GRANT SELECT ON collation_character_set_applicability TO PUBLIC;
|
2006-04-02 13:38:13 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2009-07-13 16:25:57 -04:00
|
|
|
* 5.17
|
2006-04-02 13:38:13 -04:00
|
|
|
* COLUMN_COLUMN_USAGE view
|
|
|
|
|
*/
|
|
|
|
|
|
2019-03-30 03:13:09 -04:00
|
|
|
CREATE VIEW column_column_usage AS
|
2021-04-21 05:54:47 -04:00
|
|
|
SELECT DISTINCT
|
|
|
|
|
CAST(current_database() AS sql_identifier) AS table_catalog,
|
2019-03-30 03:13:09 -04:00
|
|
|
CAST(n.nspname AS sql_identifier) AS table_schema,
|
|
|
|
|
CAST(c.relname AS sql_identifier) AS table_name,
|
|
|
|
|
CAST(ac.attname AS sql_identifier) AS column_name,
|
|
|
|
|
CAST(ad.attname AS sql_identifier) AS dependent_column
|
|
|
|
|
|
|
|
|
|
FROM pg_namespace n, pg_class c, pg_depend d,
|
|
|
|
|
pg_attribute ac, pg_attribute ad
|
|
|
|
|
|
|
|
|
|
WHERE n.oid = c.relnamespace
|
|
|
|
|
AND c.oid = ac.attrelid
|
|
|
|
|
AND c.oid = ad.attrelid
|
|
|
|
|
AND d.classid = 'pg_catalog.pg_class'::regclass
|
|
|
|
|
AND d.refclassid = 'pg_catalog.pg_class'::regclass
|
|
|
|
|
AND d.objid = d.refobjid
|
|
|
|
|
AND c.oid = d.objid
|
|
|
|
|
AND d.objsubid = ad.attnum
|
|
|
|
|
AND d.refobjsubid = ac.attnum
|
|
|
|
|
AND ad.attgenerated <> ''
|
|
|
|
|
AND pg_has_role(c.relowner, 'USAGE');
|
|
|
|
|
|
|
|
|
|
GRANT SELECT ON column_column_usage TO PUBLIC;
|
2006-04-02 13:38:13 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2009-07-13 16:25:57 -04:00
|
|
|
* 5.18
|
2002-12-13 19:24:35 -05:00
|
|
|
* COLUMN_DOMAIN_USAGE view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CREATE VIEW column_domain_usage AS
|
|
|
|
|
SELECT CAST(current_database() AS sql_identifier) AS domain_catalog,
|
|
|
|
|
CAST(nt.nspname AS sql_identifier) AS domain_schema,
|
|
|
|
|
CAST(t.typname AS sql_identifier) AS domain_name,
|
|
|
|
|
CAST(current_database() AS sql_identifier) AS table_catalog,
|
|
|
|
|
CAST(nc.nspname AS sql_identifier) AS table_schema,
|
|
|
|
|
CAST(c.relname AS sql_identifier) AS table_name,
|
|
|
|
|
CAST(a.attname AS sql_identifier) AS column_name
|
|
|
|
|
|
|
|
|
|
FROM pg_type t, pg_namespace nt, pg_class c, pg_namespace nc,
|
2005-07-25 20:04:19 -04:00
|
|
|
pg_attribute a
|
2002-12-13 19:24:35 -05:00
|
|
|
|
2003-06-17 14:00:48 -04:00
|
|
|
WHERE t.typnamespace = nt.oid
|
|
|
|
|
AND c.relnamespace = nc.oid
|
|
|
|
|
AND a.attrelid = c.oid
|
|
|
|
|
AND a.atttypid = t.oid
|
|
|
|
|
AND t.typtype = 'd'
|
2017-03-10 13:15:47 -05:00
|
|
|
AND c.relkind IN ('r', 'v', 'f', 'p')
|
2003-06-17 14:00:48 -04:00
|
|
|
AND a.attnum > 0
|
|
|
|
|
AND NOT a.attisdropped
|
2006-04-02 13:38:13 -04:00
|
|
|
AND pg_has_role(t.typowner, 'USAGE');
|
2002-12-13 19:24:35 -05:00
|
|
|
|
|
|
|
|
GRANT SELECT ON column_domain_usage TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2009-07-13 16:25:57 -04:00
|
|
|
* 5.19
|
2002-12-13 19:24:35 -05:00
|
|
|
* COLUMN_PRIVILEGES
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CREATE VIEW column_privileges AS
|
2005-06-28 01:09:14 -04:00
|
|
|
SELECT CAST(u_grantor.rolname AS sql_identifier) AS grantor,
|
2005-07-25 20:04:19 -04:00
|
|
|
CAST(grantee.rolname AS sql_identifier) AS grantee,
|
2003-06-17 14:00:48 -04:00
|
|
|
CAST(current_database() AS sql_identifier) AS table_catalog,
|
|
|
|
|
CAST(nc.nspname AS sql_identifier) AS table_schema,
|
2009-12-05 16:43:36 -05:00
|
|
|
CAST(x.relname AS sql_identifier) AS table_name,
|
|
|
|
|
CAST(x.attname AS sql_identifier) AS column_name,
|
|
|
|
|
CAST(x.prtype AS character_data) AS privilege_type,
|
2003-06-17 14:00:48 -04:00
|
|
|
CAST(
|
2009-02-06 16:15:12 -05:00
|
|
|
CASE WHEN
|
|
|
|
|
-- object owner always has grant options
|
2009-12-05 16:43:36 -05:00
|
|
|
pg_has_role(x.grantee, x.relowner, 'USAGE')
|
|
|
|
|
OR x.grantable
|
2009-07-13 16:25:57 -04:00
|
|
|
THEN 'YES' ELSE 'NO' END AS yes_or_no) AS is_grantable
|
2003-06-17 14:00:48 -04:00
|
|
|
|
2009-12-05 16:43:36 -05:00
|
|
|
FROM (
|
|
|
|
|
SELECT pr_c.grantor,
|
|
|
|
|
pr_c.grantee,
|
|
|
|
|
attname,
|
|
|
|
|
relname,
|
|
|
|
|
relnamespace,
|
|
|
|
|
pr_c.prtype,
|
|
|
|
|
pr_c.grantable,
|
|
|
|
|
pr_c.relowner
|
2012-01-27 14:58:51 -05:00
|
|
|
FROM (SELECT oid, relname, relnamespace, relowner, (aclexplode(coalesce(relacl, acldefault('r', relowner)))).*
|
2009-12-05 16:43:36 -05:00
|
|
|
FROM pg_class
|
2017-03-10 13:15:47 -05:00
|
|
|
WHERE relkind IN ('r', 'v', 'f', 'p')
|
2009-12-05 16:43:36 -05:00
|
|
|
) pr_c (oid, relname, relnamespace, relowner, grantor, grantee, prtype, grantable),
|
|
|
|
|
pg_attribute a
|
|
|
|
|
WHERE a.attrelid = pr_c.oid
|
|
|
|
|
AND a.attnum > 0
|
|
|
|
|
AND NOT a.attisdropped
|
|
|
|
|
UNION
|
|
|
|
|
SELECT pr_a.grantor,
|
|
|
|
|
pr_a.grantee,
|
|
|
|
|
attname,
|
|
|
|
|
relname,
|
|
|
|
|
relnamespace,
|
|
|
|
|
pr_a.prtype,
|
|
|
|
|
pr_a.grantable,
|
|
|
|
|
c.relowner
|
2012-01-27 14:58:51 -05:00
|
|
|
FROM (SELECT attrelid, attname, (aclexplode(coalesce(attacl, acldefault('c', relowner)))).*
|
|
|
|
|
FROM pg_attribute a JOIN pg_class cc ON (a.attrelid = cc.oid)
|
2009-12-05 16:43:36 -05:00
|
|
|
WHERE attnum > 0
|
|
|
|
|
AND NOT attisdropped
|
|
|
|
|
) pr_a (attrelid, attname, grantor, grantee, prtype, grantable),
|
|
|
|
|
pg_class c
|
|
|
|
|
WHERE pr_a.attrelid = c.oid
|
2017-03-10 13:15:47 -05:00
|
|
|
AND relkind IN ('r', 'v', 'f', 'p')
|
2009-12-05 16:43:36 -05:00
|
|
|
) x,
|
2003-06-17 14:00:48 -04:00
|
|
|
pg_namespace nc,
|
2005-06-28 01:09:14 -04:00
|
|
|
pg_authid u_grantor,
|
2003-06-29 11:14:41 -04:00
|
|
|
(
|
2005-06-28 01:09:14 -04:00
|
|
|
SELECT oid, rolname FROM pg_authid
|
2003-10-18 08:53:35 -04:00
|
|
|
UNION ALL
|
2005-07-25 20:04:19 -04:00
|
|
|
SELECT 0::oid, 'PUBLIC'
|
2009-12-05 16:43:36 -05:00
|
|
|
) AS grantee (oid, rolname)
|
2003-06-17 14:00:48 -04:00
|
|
|
|
2009-12-05 16:43:36 -05:00
|
|
|
WHERE x.relnamespace = nc.oid
|
|
|
|
|
AND x.grantee = grantee.oid
|
|
|
|
|
AND x.grantor = u_grantor.oid
|
|
|
|
|
AND x.prtype IN ('INSERT', 'SELECT', 'UPDATE', 'REFERENCES')
|
2006-04-02 13:38:13 -04:00
|
|
|
AND (pg_has_role(u_grantor.oid, 'USAGE')
|
|
|
|
|
OR pg_has_role(grantee.oid, 'USAGE')
|
2005-07-25 20:04:19 -04:00
|
|
|
OR grantee.rolname = 'PUBLIC');
|
2002-12-13 19:24:35 -05:00
|
|
|
|
|
|
|
|
GRANT SELECT ON column_privileges TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
2003-06-17 14:00:48 -04:00
|
|
|
/*
|
2009-07-13 16:25:57 -04:00
|
|
|
* 5.20
|
2003-06-17 14:00:48 -04:00
|
|
|
* COLUMN_UDT_USAGE view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CREATE VIEW column_udt_usage AS
|
|
|
|
|
SELECT CAST(current_database() AS sql_identifier) AS udt_catalog,
|
|
|
|
|
CAST(coalesce(nbt.nspname, nt.nspname) AS sql_identifier) AS udt_schema,
|
|
|
|
|
CAST(coalesce(bt.typname, t.typname) AS sql_identifier) AS udt_name,
|
|
|
|
|
CAST(current_database() AS sql_identifier) AS table_catalog,
|
|
|
|
|
CAST(nc.nspname AS sql_identifier) AS table_schema,
|
|
|
|
|
CAST(c.relname AS sql_identifier) AS table_name,
|
|
|
|
|
CAST(a.attname AS sql_identifier) AS column_name
|
|
|
|
|
|
2005-07-25 20:04:19 -04:00
|
|
|
FROM pg_attribute a, pg_class c, pg_namespace nc,
|
2003-06-17 14:00:48 -04:00
|
|
|
(pg_type t JOIN pg_namespace nt ON (t.typnamespace = nt.oid))
|
|
|
|
|
LEFT JOIN (pg_type bt JOIN pg_namespace nbt ON (bt.typnamespace = nbt.oid))
|
|
|
|
|
ON (t.typtype = 'd' AND t.typbasetype = bt.oid)
|
|
|
|
|
|
|
|
|
|
WHERE a.attrelid = c.oid
|
|
|
|
|
AND a.atttypid = t.oid
|
|
|
|
|
AND nc.oid = c.relnamespace
|
2017-03-10 13:15:47 -05:00
|
|
|
AND a.attnum > 0 AND NOT a.attisdropped
|
|
|
|
|
AND c.relkind in ('r', 'v', 'f', 'p')
|
2006-04-02 13:38:13 -04:00
|
|
|
AND pg_has_role(coalesce(bt.typowner, t.typowner), 'USAGE');
|
2003-06-17 14:00:48 -04:00
|
|
|
|
|
|
|
|
GRANT SELECT ON column_udt_usage TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
2002-12-13 19:24:35 -05:00
|
|
|
/*
|
2009-07-13 16:25:57 -04:00
|
|
|
* 5.21
|
2002-12-13 19:24:35 -05:00
|
|
|
* COLUMNS view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CREATE VIEW columns AS
|
|
|
|
|
SELECT CAST(current_database() AS sql_identifier) AS table_catalog,
|
|
|
|
|
CAST(nc.nspname AS sql_identifier) AS table_schema,
|
|
|
|
|
CAST(c.relname AS sql_identifier) AS table_name,
|
|
|
|
|
CAST(a.attname AS sql_identifier) AS column_name,
|
|
|
|
|
CAST(a.attnum AS cardinal_number) AS ordinal_position,
|
2019-03-30 03:13:09 -04:00
|
|
|
CAST(CASE WHEN a.attgenerated = '' THEN pg_get_expr(ad.adbin, ad.adrelid) END AS character_data) AS column_default,
|
2003-05-25 05:36:09 -04:00
|
|
|
CAST(CASE WHEN a.attnotnull OR (t.typtype = 'd' AND t.typnotnull) THEN 'NO' ELSE 'YES' END
|
2009-07-13 16:25:57 -04:00
|
|
|
AS yes_or_no)
|
2002-12-13 19:24:35 -05:00
|
|
|
AS is_nullable,
|
2003-05-25 05:36:09 -04:00
|
|
|
|
|
|
|
|
CAST(
|
|
|
|
|
CASE WHEN t.typtype = 'd' THEN
|
2003-06-28 16:50:08 -04:00
|
|
|
CASE WHEN bt.typelem <> 0 AND bt.typlen = -1 THEN 'ARRAY'
|
|
|
|
|
WHEN nbt.nspname = 'pg_catalog' THEN format_type(t.typbasetype, null)
|
2003-05-25 05:36:09 -04:00
|
|
|
ELSE 'USER-DEFINED' END
|
|
|
|
|
ELSE
|
2003-06-28 16:50:08 -04:00
|
|
|
CASE WHEN t.typelem <> 0 AND t.typlen = -1 THEN 'ARRAY'
|
|
|
|
|
WHEN nt.nspname = 'pg_catalog' THEN format_type(a.atttypid, null)
|
2003-05-25 05:36:09 -04:00
|
|
|
ELSE 'USER-DEFINED' END
|
|
|
|
|
END
|
|
|
|
|
AS character_data)
|
2002-12-13 19:24:35 -05:00
|
|
|
AS data_type,
|
|
|
|
|
|
|
|
|
|
CAST(
|
2004-06-22 18:30:32 -04:00
|
|
|
_pg_char_max_length(_pg_truetypid(a, t), _pg_truetypmod(a, t))
|
2002-12-13 19:24:35 -05:00
|
|
|
AS cardinal_number)
|
|
|
|
|
AS character_maximum_length,
|
|
|
|
|
|
|
|
|
|
CAST(
|
2004-06-22 18:30:32 -04:00
|
|
|
_pg_char_octet_length(_pg_truetypid(a, t), _pg_truetypmod(a, t))
|
2002-12-13 19:24:35 -05:00
|
|
|
AS cardinal_number)
|
|
|
|
|
AS character_octet_length,
|
|
|
|
|
|
|
|
|
|
CAST(
|
2004-06-22 18:30:32 -04:00
|
|
|
_pg_numeric_precision(_pg_truetypid(a, t), _pg_truetypmod(a, t))
|
2002-12-13 19:24:35 -05:00
|
|
|
AS cardinal_number)
|
|
|
|
|
AS numeric_precision,
|
|
|
|
|
|
|
|
|
|
CAST(
|
2004-06-22 18:30:32 -04:00
|
|
|
_pg_numeric_precision_radix(_pg_truetypid(a, t), _pg_truetypmod(a, t))
|
2002-12-13 19:24:35 -05:00
|
|
|
AS cardinal_number)
|
|
|
|
|
AS numeric_precision_radix,
|
|
|
|
|
|
|
|
|
|
CAST(
|
2004-06-22 18:30:32 -04:00
|
|
|
_pg_numeric_scale(_pg_truetypid(a, t), _pg_truetypmod(a, t))
|
2002-12-13 19:24:35 -05:00
|
|
|
AS cardinal_number)
|
|
|
|
|
AS numeric_scale,
|
|
|
|
|
|
|
|
|
|
CAST(
|
2004-06-22 18:30:32 -04:00
|
|
|
_pg_datetime_precision(_pg_truetypid(a, t), _pg_truetypmod(a, t))
|
2002-12-13 19:24:35 -05:00
|
|
|
AS cardinal_number)
|
|
|
|
|
AS datetime_precision,
|
|
|
|
|
|
2011-07-13 13:30:40 -04:00
|
|
|
CAST(
|
|
|
|
|
_pg_interval_type(_pg_truetypid(a, t), _pg_truetypmod(a, t))
|
|
|
|
|
AS character_data)
|
|
|
|
|
AS interval_type,
|
2011-07-11 11:49:44 -04:00
|
|
|
CAST(null AS cardinal_number) AS interval_precision,
|
2002-12-13 19:24:35 -05:00
|
|
|
|
|
|
|
|
CAST(null AS sql_identifier) AS character_set_catalog,
|
|
|
|
|
CAST(null AS sql_identifier) AS character_set_schema,
|
|
|
|
|
CAST(null AS sql_identifier) AS character_set_name,
|
|
|
|
|
|
2011-06-28 10:49:28 -04:00
|
|
|
CAST(CASE WHEN nco.nspname IS NOT NULL THEN current_database() END AS sql_identifier) AS collation_catalog,
|
|
|
|
|
CAST(nco.nspname AS sql_identifier) AS collation_schema,
|
|
|
|
|
CAST(co.collname AS sql_identifier) AS collation_name,
|
2002-12-13 19:24:35 -05:00
|
|
|
|
2003-05-18 16:55:57 -04:00
|
|
|
CAST(CASE WHEN t.typtype = 'd' THEN current_database() ELSE null END
|
2002-12-13 19:24:35 -05:00
|
|
|
AS sql_identifier) AS domain_catalog,
|
2003-05-18 16:55:57 -04:00
|
|
|
CAST(CASE WHEN t.typtype = 'd' THEN nt.nspname ELSE null END
|
2002-12-13 19:24:35 -05:00
|
|
|
AS sql_identifier) AS domain_schema,
|
2003-05-18 16:55:57 -04:00
|
|
|
CAST(CASE WHEN t.typtype = 'd' THEN t.typname ELSE null END
|
2002-12-13 19:24:35 -05:00
|
|
|
AS sql_identifier) AS domain_name,
|
|
|
|
|
|
2003-05-25 05:36:09 -04:00
|
|
|
CAST(current_database() AS sql_identifier) AS udt_catalog,
|
|
|
|
|
CAST(coalesce(nbt.nspname, nt.nspname) AS sql_identifier) AS udt_schema,
|
|
|
|
|
CAST(coalesce(bt.typname, t.typname) AS sql_identifier) AS udt_name,
|
2002-12-13 19:24:35 -05:00
|
|
|
|
|
|
|
|
CAST(null AS sql_identifier) AS scope_catalog,
|
|
|
|
|
CAST(null AS sql_identifier) AS scope_schema,
|
|
|
|
|
CAST(null AS sql_identifier) AS scope_name,
|
|
|
|
|
|
|
|
|
|
CAST(null AS cardinal_number) AS maximum_cardinality,
|
2003-06-28 16:50:08 -04:00
|
|
|
CAST(a.attnum AS sql_identifier) AS dtd_identifier,
|
2009-07-13 16:25:57 -04:00
|
|
|
CAST('NO' AS yes_or_no) AS is_self_referencing,
|
2006-04-02 13:38:13 -04:00
|
|
|
|
2017-04-06 08:33:16 -04:00
|
|
|
CAST(CASE WHEN a.attidentity IN ('a', 'd') THEN 'YES' ELSE 'NO' END AS yes_or_no) AS is_identity,
|
|
|
|
|
CAST(CASE a.attidentity WHEN 'a' THEN 'ALWAYS' WHEN 'd' THEN 'BY DEFAULT' END AS character_data) AS identity_generation,
|
|
|
|
|
CAST(seq.seqstart AS character_data) AS identity_start,
|
|
|
|
|
CAST(seq.seqincrement AS character_data) AS identity_increment,
|
|
|
|
|
CAST(seq.seqmax AS character_data) AS identity_maximum,
|
|
|
|
|
CAST(seq.seqmin AS character_data) AS identity_minimum,
|
|
|
|
|
CAST(CASE WHEN seq.seqcycle THEN 'YES' ELSE 'NO' END AS yes_or_no) AS identity_cycle,
|
2006-04-02 13:38:13 -04:00
|
|
|
|
2019-03-30 03:13:09 -04:00
|
|
|
CAST(CASE WHEN a.attgenerated <> '' THEN 'ALWAYS' ELSE 'NEVER' END AS character_data) AS is_generated,
|
|
|
|
|
CAST(CASE WHEN a.attgenerated <> '' THEN pg_get_expr(ad.adbin, ad.adrelid) END AS character_data) AS generation_expression,
|
2006-04-02 13:38:13 -04:00
|
|
|
|
2017-03-10 13:15:47 -05:00
|
|
|
CAST(CASE WHEN c.relkind IN ('r', 'p') OR
|
2013-06-12 17:52:54 -04:00
|
|
|
(c.relkind IN ('v', 'f') AND
|
|
|
|
|
pg_column_is_updatable(c.oid, a.attnum, false))
|
2009-07-13 16:25:57 -04:00
|
|
|
THEN 'YES' ELSE 'NO' END AS yes_or_no) AS is_updatable
|
2002-12-13 19:24:35 -05:00
|
|
|
|
2011-06-28 10:49:28 -04:00
|
|
|
FROM (pg_attribute a LEFT JOIN pg_attrdef ad ON attrelid = adrelid AND attnum = adnum)
|
|
|
|
|
JOIN (pg_class c JOIN pg_namespace nc ON (c.relnamespace = nc.oid)) ON a.attrelid = c.oid
|
|
|
|
|
JOIN (pg_type t JOIN pg_namespace nt ON (t.typnamespace = nt.oid)) ON a.atttypid = t.oid
|
|
|
|
|
LEFT JOIN (pg_type bt JOIN pg_namespace nbt ON (bt.typnamespace = nbt.oid))
|
2003-05-25 05:36:09 -04:00
|
|
|
ON (t.typtype = 'd' AND t.typbasetype = bt.oid)
|
2011-06-28 10:49:28 -04:00
|
|
|
LEFT JOIN (pg_collation co JOIN pg_namespace nco ON (co.collnamespace = nco.oid))
|
|
|
|
|
ON a.attcollation = co.oid AND (nco.nspname, co.collname) <> ('pg_catalog', 'default')
|
2017-04-06 08:33:16 -04:00
|
|
|
LEFT JOIN (pg_depend dep JOIN pg_sequence seq ON (dep.classid = 'pg_class'::regclass AND dep.objid = seq.seqrelid AND dep.deptype = 'i'))
|
|
|
|
|
ON (dep.refclassid = 'pg_class'::regclass AND dep.refobjid = c.oid AND dep.refobjsubid = a.attnum)
|
2002-12-13 19:24:35 -05:00
|
|
|
|
2011-06-28 10:49:28 -04:00
|
|
|
WHERE (NOT pg_is_other_temp_schema(nc.oid))
|
2006-09-14 18:05:06 -04:00
|
|
|
|
2017-03-10 13:15:47 -05:00
|
|
|
AND a.attnum > 0 AND NOT a.attisdropped
|
|
|
|
|
AND c.relkind IN ('r', 'v', 'f', 'p')
|
2003-05-25 05:36:09 -04:00
|
|
|
|
2006-04-02 13:38:13 -04:00
|
|
|
AND (pg_has_role(c.relowner, 'USAGE')
|
2009-02-06 16:15:12 -05:00
|
|
|
OR has_column_privilege(c.oid, a.attnum,
|
|
|
|
|
'SELECT, INSERT, UPDATE, REFERENCES'));
|
2002-12-13 19:24:35 -05:00
|
|
|
|
|
|
|
|
GRANT SELECT ON columns TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
2003-05-25 05:36:09 -04:00
|
|
|
/*
|
2009-07-13 16:25:57 -04:00
|
|
|
* 5.22
|
2003-05-25 05:36:09 -04:00
|
|
|
* CONSTRAINT_COLUMN_USAGE view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CREATE VIEW constraint_column_usage AS
|
|
|
|
|
SELECT CAST(current_database() AS sql_identifier) AS table_catalog,
|
|
|
|
|
CAST(tblschema AS sql_identifier) AS table_schema,
|
|
|
|
|
CAST(tblname AS sql_identifier) AS table_name,
|
|
|
|
|
CAST(colname AS sql_identifier) AS column_name,
|
|
|
|
|
CAST(current_database() AS sql_identifier) AS constraint_catalog,
|
|
|
|
|
CAST(cstrschema AS sql_identifier) AS constraint_schema,
|
|
|
|
|
CAST(cstrname AS sql_identifier) AS constraint_name
|
|
|
|
|
|
|
|
|
|
FROM (
|
2003-06-17 14:00:48 -04:00
|
|
|
/* check constraints */
|
2003-05-25 05:36:09 -04:00
|
|
|
SELECT DISTINCT nr.nspname, r.relname, r.relowner, a.attname, nc.nspname, c.conname
|
|
|
|
|
FROM pg_namespace nr, pg_class r, pg_attribute a, pg_depend d, pg_namespace nc, pg_constraint c
|
|
|
|
|
WHERE nr.oid = r.relnamespace
|
|
|
|
|
AND r.oid = a.attrelid
|
2003-10-18 08:53:35 -04:00
|
|
|
AND d.refclassid = 'pg_catalog.pg_class'::regclass
|
2003-05-25 05:36:09 -04:00
|
|
|
AND d.refobjid = r.oid
|
|
|
|
|
AND d.refobjsubid = a.attnum
|
2003-10-18 08:53:35 -04:00
|
|
|
AND d.classid = 'pg_catalog.pg_constraint'::regclass
|
2003-05-25 05:36:09 -04:00
|
|
|
AND d.objid = c.oid
|
|
|
|
|
AND c.connamespace = nc.oid
|
|
|
|
|
AND c.contype = 'c'
|
2017-03-10 13:15:47 -05:00
|
|
|
AND r.relkind IN ('r', 'p')
|
2003-06-17 14:00:48 -04:00
|
|
|
AND NOT a.attisdropped
|
|
|
|
|
|
2003-10-18 08:53:35 -04:00
|
|
|
UNION ALL
|
2003-06-17 14:00:48 -04:00
|
|
|
|
|
|
|
|
/* unique/primary key/foreign key constraints */
|
|
|
|
|
SELECT nr.nspname, r.relname, r.relowner, a.attname, nc.nspname, c.conname
|
2003-10-18 15:06:10 -04:00
|
|
|
FROM pg_namespace nr, pg_class r, pg_attribute a, pg_namespace nc,
|
2005-03-28 19:17:27 -05:00
|
|
|
pg_constraint c
|
2003-06-17 14:00:48 -04:00
|
|
|
WHERE nr.oid = r.relnamespace
|
|
|
|
|
AND r.oid = a.attrelid
|
|
|
|
|
AND nc.oid = c.connamespace
|
2017-02-17 19:32:15 -05:00
|
|
|
AND r.oid = CASE c.contype WHEN 'f' THEN c.confrelid ELSE c.conrelid END
|
|
|
|
|
AND a.attnum = ANY (CASE c.contype WHEN 'f' THEN c.confkey ELSE c.conkey END)
|
2003-06-17 14:00:48 -04:00
|
|
|
AND NOT a.attisdropped
|
|
|
|
|
AND c.contype IN ('p', 'u', 'f')
|
2017-03-10 13:15:47 -05:00
|
|
|
AND r.relkind IN ('r', 'p')
|
2003-06-17 14:00:48 -04:00
|
|
|
|
2005-07-25 20:04:19 -04:00
|
|
|
) AS x (tblschema, tblname, tblowner, colname, cstrschema, cstrname)
|
2003-05-25 05:36:09 -04:00
|
|
|
|
2006-04-02 13:38:13 -04:00
|
|
|
WHERE pg_has_role(x.tblowner, 'USAGE');
|
2003-05-25 05:36:09 -04:00
|
|
|
|
|
|
|
|
GRANT SELECT ON constraint_column_usage TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2009-07-13 16:25:57 -04:00
|
|
|
* 5.23
|
2012-07-23 15:31:43 -04:00
|
|
|
* CONSTRAINT_PERIOD_USAGE view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
-- feature not supported
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 5.24
|
2003-05-25 05:36:09 -04:00
|
|
|
* CONSTRAINT_TABLE_USAGE view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CREATE VIEW constraint_table_usage AS
|
|
|
|
|
SELECT CAST(current_database() AS sql_identifier) AS table_catalog,
|
|
|
|
|
CAST(nr.nspname AS sql_identifier) AS table_schema,
|
|
|
|
|
CAST(r.relname AS sql_identifier) AS table_name,
|
|
|
|
|
CAST(current_database() AS sql_identifier) AS constraint_catalog,
|
|
|
|
|
CAST(nc.nspname AS sql_identifier) AS constraint_schema,
|
|
|
|
|
CAST(c.conname AS sql_identifier) AS constraint_name
|
|
|
|
|
|
|
|
|
|
FROM pg_constraint c, pg_namespace nc,
|
2005-07-25 20:04:19 -04:00
|
|
|
pg_class r, pg_namespace nr
|
2003-05-25 05:36:09 -04:00
|
|
|
|
|
|
|
|
WHERE c.connamespace = nc.oid AND r.relnamespace = nr.oid
|
|
|
|
|
AND ( (c.contype = 'f' AND c.confrelid = r.oid)
|
|
|
|
|
OR (c.contype IN ('p', 'u') AND c.conrelid = r.oid) )
|
2017-03-10 13:15:47 -05:00
|
|
|
AND r.relkind IN ('r', 'p')
|
2006-04-02 13:38:13 -04:00
|
|
|
AND pg_has_role(r.relowner, 'USAGE');
|
2003-05-25 05:36:09 -04:00
|
|
|
|
|
|
|
|
GRANT SELECT ON constraint_table_usage TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
2012-07-23 15:31:43 -04:00
|
|
|
-- 5.25 DATA_TYPE_PRIVILEGES view appears later.
|
2003-06-28 16:50:08 -04:00
|
|
|
|
|
|
|
|
|
2003-03-20 00:06:55 -05:00
|
|
|
/*
|
2012-07-23 15:31:43 -04:00
|
|
|
* 5.26
|
2006-04-02 13:38:13 -04:00
|
|
|
* DIRECT_SUPERTABLES view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
-- feature not supported
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-07-23 15:31:43 -04:00
|
|
|
* 5.27
|
2006-04-02 13:38:13 -04:00
|
|
|
* DIRECT_SUPERTYPES view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
-- feature not supported
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-07-23 15:31:43 -04:00
|
|
|
* 5.28
|
2003-03-20 00:06:55 -05:00
|
|
|
* DOMAIN_CONSTRAINTS view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CREATE VIEW domain_constraints AS
|
|
|
|
|
SELECT CAST(current_database() AS sql_identifier) AS constraint_catalog,
|
|
|
|
|
CAST(rs.nspname AS sql_identifier) AS constraint_schema,
|
|
|
|
|
CAST(con.conname AS sql_identifier) AS constraint_name,
|
|
|
|
|
CAST(current_database() AS sql_identifier) AS domain_catalog,
|
|
|
|
|
CAST(n.nspname AS sql_identifier) AS domain_schema,
|
|
|
|
|
CAST(t.typname AS sql_identifier) AS domain_name,
|
|
|
|
|
CAST(CASE WHEN condeferrable THEN 'YES' ELSE 'NO' END
|
2009-07-13 16:25:57 -04:00
|
|
|
AS yes_or_no) AS is_deferrable,
|
2003-03-20 00:06:55 -05:00
|
|
|
CAST(CASE WHEN condeferred THEN 'YES' ELSE 'NO' END
|
2009-07-13 16:25:57 -04:00
|
|
|
AS yes_or_no) AS initially_deferred
|
2005-07-25 20:04:19 -04:00
|
|
|
FROM pg_namespace rs, pg_namespace n, pg_constraint con, pg_type t
|
2003-03-20 00:06:55 -05:00
|
|
|
WHERE rs.oid = con.connamespace
|
|
|
|
|
AND n.oid = t.typnamespace
|
2011-12-19 17:05:19 -05:00
|
|
|
AND t.oid = con.contypid
|
|
|
|
|
AND (pg_has_role(t.typowner, 'USAGE')
|
|
|
|
|
OR has_type_privilege(t.oid, 'USAGE'));
|
2003-03-20 00:06:55 -05:00
|
|
|
|
|
|
|
|
GRANT SELECT ON domain_constraints TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
2003-06-17 14:00:48 -04:00
|
|
|
/*
|
|
|
|
|
* DOMAIN_UDT_USAGE view
|
2006-04-02 13:38:13 -04:00
|
|
|
* apparently removed in SQL:2003
|
2003-06-17 14:00:48 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CREATE VIEW domain_udt_usage AS
|
|
|
|
|
SELECT CAST(current_database() AS sql_identifier) AS udt_catalog,
|
|
|
|
|
CAST(nbt.nspname AS sql_identifier) AS udt_schema,
|
|
|
|
|
CAST(bt.typname AS sql_identifier) AS udt_name,
|
|
|
|
|
CAST(current_database() AS sql_identifier) AS domain_catalog,
|
|
|
|
|
CAST(nt.nspname AS sql_identifier) AS domain_schema,
|
|
|
|
|
CAST(t.typname AS sql_identifier) AS domain_name
|
|
|
|
|
|
|
|
|
|
FROM pg_type t, pg_namespace nt,
|
2005-07-25 20:04:19 -04:00
|
|
|
pg_type bt, pg_namespace nbt
|
2003-06-17 14:00:48 -04:00
|
|
|
|
|
|
|
|
WHERE t.typnamespace = nt.oid
|
|
|
|
|
AND t.typbasetype = bt.oid
|
|
|
|
|
AND bt.typnamespace = nbt.oid
|
|
|
|
|
AND t.typtype = 'd'
|
2006-04-02 13:38:13 -04:00
|
|
|
AND pg_has_role(bt.typowner, 'USAGE');
|
2003-06-17 14:00:48 -04:00
|
|
|
|
|
|
|
|
GRANT SELECT ON domain_udt_usage TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
2003-03-20 00:06:55 -05:00
|
|
|
/*
|
2012-07-23 15:31:43 -04:00
|
|
|
* 5.29
|
2003-03-20 00:06:55 -05:00
|
|
|
* DOMAINS view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CREATE VIEW domains AS
|
|
|
|
|
SELECT CAST(current_database() AS sql_identifier) AS domain_catalog,
|
2003-05-25 05:36:09 -04:00
|
|
|
CAST(nt.nspname AS sql_identifier) AS domain_schema,
|
2003-03-20 00:06:55 -05:00
|
|
|
CAST(t.typname AS sql_identifier) AS domain_name,
|
2003-05-25 05:36:09 -04:00
|
|
|
|
|
|
|
|
CAST(
|
2003-06-28 16:50:08 -04:00
|
|
|
CASE WHEN t.typelem <> 0 AND t.typlen = -1 THEN 'ARRAY'
|
|
|
|
|
WHEN nbt.nspname = 'pg_catalog' THEN format_type(t.typbasetype, null)
|
|
|
|
|
ELSE 'USER-DEFINED' END
|
2003-05-25 05:36:09 -04:00
|
|
|
AS character_data)
|
2003-03-20 00:06:55 -05:00
|
|
|
AS data_type,
|
|
|
|
|
|
|
|
|
|
CAST(
|
2004-06-22 18:30:32 -04:00
|
|
|
_pg_char_max_length(t.typbasetype, t.typtypmod)
|
2003-03-20 00:06:55 -05:00
|
|
|
AS cardinal_number)
|
|
|
|
|
AS character_maximum_length,
|
|
|
|
|
|
|
|
|
|
CAST(
|
2004-06-22 18:30:32 -04:00
|
|
|
_pg_char_octet_length(t.typbasetype, t.typtypmod)
|
2003-03-20 00:06:55 -05:00
|
|
|
AS cardinal_number)
|
|
|
|
|
AS character_octet_length,
|
2003-05-25 05:36:09 -04:00
|
|
|
|
2003-03-20 00:06:55 -05:00
|
|
|
CAST(null AS sql_identifier) AS character_set_catalog,
|
|
|
|
|
CAST(null AS sql_identifier) AS character_set_schema,
|
|
|
|
|
CAST(null AS sql_identifier) AS character_set_name,
|
|
|
|
|
|
2011-06-28 10:49:28 -04:00
|
|
|
CAST(CASE WHEN nco.nspname IS NOT NULL THEN current_database() END AS sql_identifier) AS collation_catalog,
|
|
|
|
|
CAST(nco.nspname AS sql_identifier) AS collation_schema,
|
|
|
|
|
CAST(co.collname AS sql_identifier) AS collation_name,
|
2003-03-20 00:06:55 -05:00
|
|
|
|
|
|
|
|
CAST(
|
2004-06-22 18:30:32 -04:00
|
|
|
_pg_numeric_precision(t.typbasetype, t.typtypmod)
|
2003-03-20 00:06:55 -05:00
|
|
|
AS cardinal_number)
|
|
|
|
|
AS numeric_precision,
|
|
|
|
|
|
|
|
|
|
CAST(
|
2004-06-22 18:30:32 -04:00
|
|
|
_pg_numeric_precision_radix(t.typbasetype, t.typtypmod)
|
2003-03-20 00:06:55 -05:00
|
|
|
AS cardinal_number)
|
|
|
|
|
AS numeric_precision_radix,
|
|
|
|
|
|
|
|
|
|
CAST(
|
2004-06-22 18:30:32 -04:00
|
|
|
_pg_numeric_scale(t.typbasetype, t.typtypmod)
|
2003-03-20 00:06:55 -05:00
|
|
|
AS cardinal_number)
|
|
|
|
|
AS numeric_scale,
|
|
|
|
|
|
|
|
|
|
CAST(
|
2004-06-22 18:30:32 -04:00
|
|
|
_pg_datetime_precision(t.typbasetype, t.typtypmod)
|
2003-03-20 00:06:55 -05:00
|
|
|
AS cardinal_number)
|
|
|
|
|
AS datetime_precision,
|
|
|
|
|
|
2011-07-13 13:30:40 -04:00
|
|
|
CAST(
|
|
|
|
|
_pg_interval_type(t.typbasetype, t.typtypmod)
|
|
|
|
|
AS character_data)
|
|
|
|
|
AS interval_type,
|
2011-07-11 11:49:44 -04:00
|
|
|
CAST(null AS cardinal_number) AS interval_precision,
|
2003-03-20 00:06:55 -05:00
|
|
|
|
2003-05-25 05:36:09 -04:00
|
|
|
CAST(t.typdefault AS character_data) AS domain_default,
|
2003-03-20 00:06:55 -05:00
|
|
|
|
2003-05-25 05:36:09 -04:00
|
|
|
CAST(current_database() AS sql_identifier) AS udt_catalog,
|
|
|
|
|
CAST(nbt.nspname AS sql_identifier) AS udt_schema,
|
|
|
|
|
CAST(bt.typname AS sql_identifier) AS udt_name,
|
2003-03-20 00:06:55 -05:00
|
|
|
|
|
|
|
|
CAST(null AS sql_identifier) AS scope_catalog,
|
|
|
|
|
CAST(null AS sql_identifier) AS scope_schema,
|
|
|
|
|
CAST(null AS sql_identifier) AS scope_name,
|
|
|
|
|
|
|
|
|
|
CAST(null AS cardinal_number) AS maximum_cardinality,
|
2003-06-28 16:50:08 -04:00
|
|
|
CAST(1 AS sql_identifier) AS dtd_identifier
|
2003-03-20 00:06:55 -05:00
|
|
|
|
2011-06-28 10:49:28 -04:00
|
|
|
FROM (pg_type t JOIN pg_namespace nt ON t.typnamespace = nt.oid)
|
|
|
|
|
JOIN (pg_type bt JOIN pg_namespace nbt ON bt.typnamespace = nbt.oid)
|
|
|
|
|
ON (t.typbasetype = bt.oid AND t.typtype = 'd')
|
|
|
|
|
LEFT JOIN (pg_collation co JOIN pg_namespace nco ON (co.collnamespace = nco.oid))
|
|
|
|
|
ON t.typcollation = co.oid AND (nco.nspname, co.collname) <> ('pg_catalog', 'default')
|
2003-03-20 00:06:55 -05:00
|
|
|
|
2011-12-19 17:05:19 -05:00
|
|
|
WHERE (pg_has_role(t.typowner, 'USAGE')
|
|
|
|
|
OR has_type_privilege(t.oid, 'USAGE'));
|
2003-03-20 00:06:55 -05:00
|
|
|
|
|
|
|
|
GRANT SELECT ON domains TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
2012-07-23 15:31:43 -04:00
|
|
|
-- 5.30 ELEMENT_TYPES view appears later.
|
2003-06-28 16:50:08 -04:00
|
|
|
|
|
|
|
|
|
2003-06-29 11:14:41 -04:00
|
|
|
/*
|
2012-07-23 15:31:43 -04:00
|
|
|
* 5.31
|
2003-06-29 11:14:41 -04:00
|
|
|
* ENABLED_ROLES view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CREATE VIEW enabled_roles AS
|
2005-06-28 01:09:14 -04:00
|
|
|
SELECT CAST(a.rolname AS sql_identifier) AS role_name
|
2005-07-25 20:04:19 -04:00
|
|
|
FROM pg_authid a
|
2006-04-02 13:38:13 -04:00
|
|
|
WHERE pg_has_role(a.oid, 'USAGE');
|
2003-06-29 11:14:41 -04:00
|
|
|
|
|
|
|
|
GRANT SELECT ON enabled_roles TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
2003-06-17 14:00:48 -04:00
|
|
|
/*
|
2012-07-23 15:31:43 -04:00
|
|
|
* 5.32
|
2006-04-02 13:38:13 -04:00
|
|
|
* FIELDS view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
-- feature not supported
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-07-23 15:31:43 -04:00
|
|
|
* 5.33
|
2003-06-17 14:00:48 -04:00
|
|
|
* KEY_COLUMN_USAGE view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CREATE VIEW key_column_usage AS
|
|
|
|
|
SELECT CAST(current_database() AS sql_identifier) AS constraint_catalog,
|
2005-03-28 19:17:27 -05:00
|
|
|
CAST(nc_nspname AS sql_identifier) AS constraint_schema,
|
|
|
|
|
CAST(conname AS sql_identifier) AS constraint_name,
|
2003-06-17 14:00:48 -04:00
|
|
|
CAST(current_database() AS sql_identifier) AS table_catalog,
|
2005-03-28 19:17:27 -05:00
|
|
|
CAST(nr_nspname AS sql_identifier) AS table_schema,
|
|
|
|
|
CAST(relname AS sql_identifier) AS table_name,
|
2003-06-17 14:00:48 -04:00
|
|
|
CAST(a.attname AS sql_identifier) AS column_name,
|
2006-04-02 13:38:13 -04:00
|
|
|
CAST((ss.x).n AS cardinal_number) AS ordinal_position,
|
2006-11-10 13:10:10 -05:00
|
|
|
CAST(CASE WHEN contype = 'f' THEN
|
2009-07-27 22:56:31 -04:00
|
|
|
_pg_index_position(ss.conindid, ss.confkey[(ss.x).n])
|
2006-11-10 13:10:10 -05:00
|
|
|
ELSE NULL
|
|
|
|
|
END AS cardinal_number)
|
|
|
|
|
AS position_in_unique_constraint
|
2005-03-28 19:17:27 -05:00
|
|
|
FROM pg_attribute a,
|
2009-02-06 16:15:12 -05:00
|
|
|
(SELECT r.oid AS roid, r.relname, r.relowner,
|
|
|
|
|
nc.nspname AS nc_nspname, nr.nspname AS nr_nspname,
|
2009-07-27 22:56:31 -04:00
|
|
|
c.oid AS coid, c.conname, c.contype, c.conindid,
|
|
|
|
|
c.confkey, c.confrelid,
|
2006-09-04 19:13:01 -04:00
|
|
|
_pg_expandarray(c.conkey) AS x
|
2005-03-28 19:17:27 -05:00
|
|
|
FROM pg_namespace nr, pg_class r, pg_namespace nc,
|
2005-07-25 20:04:19 -04:00
|
|
|
pg_constraint c
|
2005-03-28 19:17:27 -05:00
|
|
|
WHERE nr.oid = r.relnamespace
|
|
|
|
|
AND r.oid = c.conrelid
|
|
|
|
|
AND nc.oid = c.connamespace
|
|
|
|
|
AND c.contype IN ('p', 'u', 'f')
|
2017-03-10 13:15:47 -05:00
|
|
|
AND r.relkind IN ('r', 'p')
|
2009-02-06 16:15:12 -05:00
|
|
|
AND (NOT pg_is_other_temp_schema(nr.oid)) ) AS ss
|
2006-11-10 13:10:10 -05:00
|
|
|
WHERE ss.roid = a.attrelid
|
2005-05-30 23:36:24 -04:00
|
|
|
AND a.attnum = (ss.x).x
|
2009-02-06 16:15:12 -05:00
|
|
|
AND NOT a.attisdropped
|
|
|
|
|
AND (pg_has_role(relowner, 'USAGE')
|
|
|
|
|
OR has_column_privilege(roid, a.attnum,
|
|
|
|
|
'SELECT, INSERT, UPDATE, REFERENCES'));
|
2003-06-17 14:00:48 -04:00
|
|
|
|
|
|
|
|
GRANT SELECT ON key_column_usage TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
2003-06-05 12:08:47 -04:00
|
|
|
/*
|
2012-07-23 15:31:43 -04:00
|
|
|
* 5.34
|
|
|
|
|
* KEY_PERIOD_USAGE view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
-- feature not supported
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 5.35
|
2006-04-02 13:38:13 -04:00
|
|
|
* METHOD_SPECIFICATION_PARAMETERS view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
-- feature not supported
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-07-23 15:31:43 -04:00
|
|
|
* 5.36
|
2006-04-02 13:38:13 -04:00
|
|
|
* METHOD_SPECIFICATIONS view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
-- feature not supported
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-07-23 15:31:43 -04:00
|
|
|
* 5.37
|
2003-06-05 12:08:47 -04:00
|
|
|
* PARAMETERS view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CREATE VIEW parameters AS
|
|
|
|
|
SELECT CAST(current_database() AS sql_identifier) AS specific_catalog,
|
2005-03-28 19:17:27 -05:00
|
|
|
CAST(n_nspname AS sql_identifier) AS specific_schema,
|
2018-12-20 15:58:58 -05:00
|
|
|
CAST(nameconcatoid(proname, p_oid) AS sql_identifier) AS specific_name,
|
2005-03-28 19:17:27 -05:00
|
|
|
CAST((ss.x).n AS cardinal_number) AS ordinal_position,
|
2005-05-30 23:36:24 -04:00
|
|
|
CAST(
|
|
|
|
|
CASE WHEN proargmodes IS NULL THEN 'IN'
|
|
|
|
|
WHEN proargmodes[(ss.x).n] = 'i' THEN 'IN'
|
|
|
|
|
WHEN proargmodes[(ss.x).n] = 'o' THEN 'OUT'
|
|
|
|
|
WHEN proargmodes[(ss.x).n] = 'b' THEN 'INOUT'
|
2008-07-15 21:30:23 -04:00
|
|
|
WHEN proargmodes[(ss.x).n] = 'v' THEN 'IN'
|
2008-07-17 23:32:53 -04:00
|
|
|
WHEN proargmodes[(ss.x).n] = 't' THEN 'OUT'
|
2005-05-30 23:36:24 -04:00
|
|
|
END AS character_data) AS parameter_mode,
|
2009-07-13 16:25:57 -04:00
|
|
|
CAST('NO' AS yes_or_no) AS is_result,
|
|
|
|
|
CAST('NO' AS yes_or_no) AS as_locator,
|
2005-03-28 19:17:27 -05:00
|
|
|
CAST(NULLIF(proargnames[(ss.x).n], '') AS sql_identifier) AS parameter_name,
|
2003-06-05 12:08:47 -04:00
|
|
|
CAST(
|
2003-06-28 16:50:08 -04:00
|
|
|
CASE WHEN t.typelem <> 0 AND t.typlen = -1 THEN 'ARRAY'
|
|
|
|
|
WHEN nt.nspname = 'pg_catalog' THEN format_type(t.oid, null)
|
2003-06-05 12:08:47 -04:00
|
|
|
ELSE 'USER-DEFINED' END AS character_data)
|
|
|
|
|
AS data_type,
|
|
|
|
|
CAST(null AS cardinal_number) AS character_maximum_length,
|
|
|
|
|
CAST(null AS cardinal_number) AS character_octet_length,
|
|
|
|
|
CAST(null AS sql_identifier) AS character_set_catalog,
|
|
|
|
|
CAST(null AS sql_identifier) AS character_set_schema,
|
|
|
|
|
CAST(null AS sql_identifier) AS character_set_name,
|
|
|
|
|
CAST(null AS sql_identifier) AS collation_catalog,
|
|
|
|
|
CAST(null AS sql_identifier) AS collation_schema,
|
|
|
|
|
CAST(null AS sql_identifier) AS collation_name,
|
|
|
|
|
CAST(null AS cardinal_number) AS numeric_precision,
|
|
|
|
|
CAST(null AS cardinal_number) AS numeric_precision_radix,
|
|
|
|
|
CAST(null AS cardinal_number) AS numeric_scale,
|
|
|
|
|
CAST(null AS cardinal_number) AS datetime_precision,
|
|
|
|
|
CAST(null AS character_data) AS interval_type,
|
2011-07-11 11:49:44 -04:00
|
|
|
CAST(null AS cardinal_number) AS interval_precision,
|
2003-06-05 12:08:47 -04:00
|
|
|
CAST(current_database() AS sql_identifier) AS udt_catalog,
|
|
|
|
|
CAST(nt.nspname AS sql_identifier) AS udt_schema,
|
|
|
|
|
CAST(t.typname AS sql_identifier) AS udt_name,
|
|
|
|
|
CAST(null AS sql_identifier) AS scope_catalog,
|
|
|
|
|
CAST(null AS sql_identifier) AS scope_schema,
|
|
|
|
|
CAST(null AS sql_identifier) AS scope_name,
|
|
|
|
|
CAST(null AS cardinal_number) AS maximum_cardinality,
|
2013-11-26 23:18:58 -05:00
|
|
|
CAST((ss.x).n AS sql_identifier) AS dtd_identifier,
|
|
|
|
|
CAST(
|
|
|
|
|
CASE WHEN pg_has_role(proowner, 'USAGE')
|
|
|
|
|
THEN pg_get_function_arg_default(p_oid, (ss.x).n)
|
|
|
|
|
ELSE NULL END
|
|
|
|
|
AS character_data) AS parameter_default
|
2003-10-18 15:06:10 -04:00
|
|
|
|
2005-03-28 19:17:27 -05:00
|
|
|
FROM pg_type t, pg_namespace nt,
|
2013-11-26 23:18:58 -05:00
|
|
|
(SELECT n.nspname AS n_nspname, p.proname, p.oid AS p_oid, p.proowner,
|
2005-05-30 23:36:24 -04:00
|
|
|
p.proargnames, p.proargmodes,
|
|
|
|
|
_pg_expandarray(coalesce(p.proallargtypes, p.proargtypes::oid[])) AS x
|
2005-07-25 20:04:19 -04:00
|
|
|
FROM pg_namespace n, pg_proc p
|
2005-03-28 19:17:27 -05:00
|
|
|
WHERE n.oid = p.pronamespace
|
2006-04-02 13:38:13 -04:00
|
|
|
AND (pg_has_role(p.proowner, 'USAGE') OR
|
2005-03-28 19:17:27 -05:00
|
|
|
has_function_privilege(p.oid, 'EXECUTE'))) AS ss
|
2005-05-30 23:36:24 -04:00
|
|
|
WHERE t.oid = (ss.x).x AND t.typnamespace = nt.oid;
|
2003-06-05 12:08:47 -04:00
|
|
|
|
|
|
|
|
GRANT SELECT ON parameters TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
2002-12-13 19:24:35 -05:00
|
|
|
/*
|
2012-07-23 15:31:43 -04:00
|
|
|
* 5.38
|
|
|
|
|
* PERIODS view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
-- feature not supported
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 5.39
|
2019-05-14 09:15:05 -04:00
|
|
|
* PRIVATE_PARAMETERS view
|
2006-04-02 13:38:13 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
-- feature not supported
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-07-23 15:31:43 -04:00
|
|
|
* 5.40
|
2019-05-14 09:15:05 -04:00
|
|
|
* REFERENCED_TYPES view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
-- feature not supported
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 5.41
|
2002-12-13 19:24:35 -05:00
|
|
|
* REFERENTIAL_CONSTRAINTS view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CREATE VIEW referential_constraints AS
|
|
|
|
|
SELECT CAST(current_database() AS sql_identifier) AS constraint_catalog,
|
|
|
|
|
CAST(ncon.nspname AS sql_identifier) AS constraint_schema,
|
|
|
|
|
CAST(con.conname AS sql_identifier) AS constraint_name,
|
2003-10-16 19:46:17 -04:00
|
|
|
CAST(
|
|
|
|
|
CASE WHEN npkc.nspname IS NULL THEN NULL
|
|
|
|
|
ELSE current_database() END
|
|
|
|
|
AS sql_identifier) AS unique_constraint_catalog,
|
2003-05-25 05:36:09 -04:00
|
|
|
CAST(npkc.nspname AS sql_identifier) AS unique_constraint_schema,
|
|
|
|
|
CAST(pkc.conname AS sql_identifier) AS unique_constraint_name,
|
2002-12-13 19:24:35 -05:00
|
|
|
|
|
|
|
|
CAST(
|
|
|
|
|
CASE con.confmatchtype WHEN 'f' THEN 'FULL'
|
|
|
|
|
WHEN 'p' THEN 'PARTIAL'
|
2012-06-17 20:16:07 -04:00
|
|
|
WHEN 's' THEN 'NONE' END
|
2002-12-13 19:24:35 -05:00
|
|
|
AS character_data) AS match_option,
|
|
|
|
|
|
|
|
|
|
CAST(
|
|
|
|
|
CASE con.confupdtype WHEN 'c' THEN 'CASCADE'
|
|
|
|
|
WHEN 'n' THEN 'SET NULL'
|
|
|
|
|
WHEN 'd' THEN 'SET DEFAULT'
|
|
|
|
|
WHEN 'r' THEN 'RESTRICT'
|
2003-10-16 19:46:17 -04:00
|
|
|
WHEN 'a' THEN 'NO ACTION' END
|
2002-12-13 19:24:35 -05:00
|
|
|
AS character_data) AS update_rule,
|
|
|
|
|
|
|
|
|
|
CAST(
|
|
|
|
|
CASE con.confdeltype WHEN 'c' THEN 'CASCADE'
|
|
|
|
|
WHEN 'n' THEN 'SET NULL'
|
|
|
|
|
WHEN 'd' THEN 'SET DEFAULT'
|
|
|
|
|
WHEN 'r' THEN 'RESTRICT'
|
2003-10-16 19:46:17 -04:00
|
|
|
WHEN 'a' THEN 'NO ACTION' END
|
2002-12-13 19:24:35 -05:00
|
|
|
AS character_data) AS delete_rule
|
|
|
|
|
|
2005-07-25 20:04:19 -04:00
|
|
|
FROM (pg_namespace ncon
|
|
|
|
|
INNER JOIN pg_constraint con ON ncon.oid = con.connamespace
|
2011-10-14 20:24:17 -04:00
|
|
|
INNER JOIN pg_class c ON con.conrelid = c.oid AND con.contype = 'f')
|
|
|
|
|
LEFT JOIN pg_depend d1 -- find constraint's dependency on an index
|
|
|
|
|
ON d1.objid = con.oid AND d1.classid = 'pg_constraint'::regclass
|
|
|
|
|
AND d1.refclassid = 'pg_class'::regclass AND d1.refobjsubid = 0
|
|
|
|
|
LEFT JOIN pg_depend d2 -- find pkey/unique constraint for that index
|
|
|
|
|
ON d2.refclassid = 'pg_constraint'::regclass
|
|
|
|
|
AND d2.classid = 'pg_class'::regclass
|
|
|
|
|
AND d2.objid = d1.refobjid AND d2.objsubid = 0
|
|
|
|
|
AND d2.deptype = 'i'
|
|
|
|
|
LEFT JOIN pg_constraint pkc ON pkc.oid = d2.refobjid
|
|
|
|
|
AND pkc.contype IN ('p', 'u')
|
|
|
|
|
AND pkc.conrelid = con.confrelid
|
|
|
|
|
LEFT JOIN pg_namespace npkc ON pkc.connamespace = npkc.oid
|
|
|
|
|
|
|
|
|
|
WHERE pg_has_role(c.relowner, 'USAGE')
|
|
|
|
|
-- SELECT privilege omitted, per SQL standard
|
|
|
|
|
OR has_table_privilege(c.oid, 'INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER')
|
|
|
|
|
OR has_any_column_privilege(c.oid, 'INSERT, UPDATE, REFERENCES') ;
|
2002-12-13 19:24:35 -05:00
|
|
|
|
|
|
|
|
GRANT SELECT ON referential_constraints TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
2003-06-29 11:14:41 -04:00
|
|
|
/*
|
2019-05-14 09:15:05 -04:00
|
|
|
* 5.42
|
2003-06-29 11:14:41 -04:00
|
|
|
* ROLE_COLUMN_GRANTS view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CREATE VIEW role_column_grants AS
|
2009-12-05 16:43:36 -05:00
|
|
|
SELECT grantor,
|
|
|
|
|
grantee,
|
|
|
|
|
table_catalog,
|
|
|
|
|
table_schema,
|
|
|
|
|
table_name,
|
|
|
|
|
column_name,
|
|
|
|
|
privilege_type,
|
|
|
|
|
is_grantable
|
|
|
|
|
FROM column_privileges
|
|
|
|
|
WHERE grantor IN (SELECT role_name FROM enabled_roles)
|
|
|
|
|
OR grantee IN (SELECT role_name FROM enabled_roles);
|
2003-06-29 11:14:41 -04:00
|
|
|
|
|
|
|
|
GRANT SELECT ON role_column_grants TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
2019-05-14 09:15:05 -04:00
|
|
|
-- 5.43 ROLE_ROUTINE_GRANTS view is based on 5.50 ROUTINE_PRIVILEGES and is defined there instead.
|
2003-06-29 11:14:41 -04:00
|
|
|
|
|
|
|
|
|
2019-05-14 09:15:05 -04:00
|
|
|
-- 5.44 ROLE_TABLE_GRANTS view is based on 5.63 TABLE_PRIVILEGES and is defined there instead.
|
2003-06-29 11:14:41 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2019-05-14 09:15:05 -04:00
|
|
|
* 5.45
|
2006-04-02 13:38:13 -04:00
|
|
|
* ROLE_TABLE_METHOD_GRANTS view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
-- feature not supported
|
|
|
|
|
|
|
|
|
|
|
2008-12-19 11:25:19 -05:00
|
|
|
|
2019-05-14 09:15:05 -04:00
|
|
|
-- 5.46 ROLE_USAGE_GRANTS view is based on 5.75 USAGE_PRIVILEGES and is defined there instead.
|
2003-06-29 11:14:41 -04:00
|
|
|
|
|
|
|
|
|
2019-05-14 09:15:05 -04:00
|
|
|
-- 5.47 ROLE_UDT_GRANTS view is based on 5.74 UDT_PRIVILEGES and is defined there instead.
|
2006-04-02 13:38:13 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2019-05-14 09:15:05 -04:00
|
|
|
* 5.48
|
2006-04-02 13:38:13 -04:00
|
|
|
* ROUTINE_COLUMN_USAGE view
|
|
|
|
|
*/
|
|
|
|
|
|
2021-02-17 11:53:18 -05:00
|
|
|
CREATE VIEW routine_column_usage AS
|
2021-04-21 05:54:47 -04:00
|
|
|
SELECT DISTINCT
|
|
|
|
|
CAST(current_database() AS sql_identifier) AS specific_catalog,
|
2021-02-17 11:53:18 -05:00
|
|
|
CAST(np.nspname AS sql_identifier) AS specific_schema,
|
|
|
|
|
CAST(nameconcatoid(p.proname, p.oid) AS sql_identifier) AS specific_name,
|
|
|
|
|
CAST(current_database() AS sql_identifier) AS routine_catalog,
|
|
|
|
|
CAST(np.nspname AS sql_identifier) AS routine_schema,
|
|
|
|
|
CAST(p.proname AS sql_identifier) AS routine_name,
|
|
|
|
|
CAST(current_database() AS sql_identifier) AS table_catalog,
|
|
|
|
|
CAST(nt.nspname AS sql_identifier) AS table_schema,
|
|
|
|
|
CAST(t.relname AS sql_identifier) AS table_name,
|
|
|
|
|
CAST(a.attname AS sql_identifier) AS column_name
|
|
|
|
|
|
|
|
|
|
FROM pg_namespace np, pg_proc p, pg_depend d,
|
|
|
|
|
pg_class t, pg_namespace nt, pg_attribute a
|
|
|
|
|
|
|
|
|
|
WHERE np.oid = p.pronamespace
|
|
|
|
|
AND p.oid = d.objid
|
|
|
|
|
AND d.classid = 'pg_catalog.pg_proc'::regclass
|
|
|
|
|
AND d.refobjid = t.oid
|
|
|
|
|
AND d.refclassid = 'pg_catalog.pg_class'::regclass
|
|
|
|
|
AND t.relnamespace = nt.oid
|
|
|
|
|
AND t.relkind IN ('r', 'v', 'f', 'p')
|
|
|
|
|
AND t.oid = a.attrelid
|
|
|
|
|
AND d.refobjsubid = a.attnum
|
|
|
|
|
AND pg_has_role(t.relowner, 'USAGE');
|
|
|
|
|
|
|
|
|
|
GRANT SELECT ON routine_column_usage TO PUBLIC;
|
2006-04-02 13:38:13 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2019-05-14 09:15:05 -04:00
|
|
|
* 5.49
|
2012-07-23 15:31:43 -04:00
|
|
|
* ROUTINE_PERIOD_USAGE view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
-- feature not supported
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2019-05-14 09:15:05 -04:00
|
|
|
* 5.50
|
2003-06-05 12:08:47 -04:00
|
|
|
* ROUTINE_PRIVILEGES view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CREATE VIEW routine_privileges AS
|
2005-06-28 01:09:14 -04:00
|
|
|
SELECT CAST(u_grantor.rolname AS sql_identifier) AS grantor,
|
2005-07-25 20:04:19 -04:00
|
|
|
CAST(grantee.rolname AS sql_identifier) AS grantee,
|
2003-06-05 12:08:47 -04:00
|
|
|
CAST(current_database() AS sql_identifier) AS specific_catalog,
|
|
|
|
|
CAST(n.nspname AS sql_identifier) AS specific_schema,
|
2018-12-20 15:58:58 -05:00
|
|
|
CAST(nameconcatoid(p.proname, p.oid) AS sql_identifier) AS specific_name,
|
2003-06-05 12:08:47 -04:00
|
|
|
CAST(current_database() AS sql_identifier) AS routine_catalog,
|
|
|
|
|
CAST(n.nspname AS sql_identifier) AS routine_schema,
|
|
|
|
|
CAST(p.proname AS sql_identifier) AS routine_name,
|
|
|
|
|
CAST('EXECUTE' AS character_data) AS privilege_type,
|
2003-06-11 05:23:55 -04:00
|
|
|
CAST(
|
2009-02-06 16:15:12 -05:00
|
|
|
CASE WHEN
|
|
|
|
|
-- object owner always has grant options
|
|
|
|
|
pg_has_role(grantee.oid, p.proowner, 'USAGE')
|
2009-12-05 16:43:36 -05:00
|
|
|
OR p.grantable
|
2009-07-13 16:25:57 -04:00
|
|
|
THEN 'YES' ELSE 'NO' END AS yes_or_no) AS is_grantable
|
2003-06-05 12:08:47 -04:00
|
|
|
|
2009-12-05 16:43:36 -05:00
|
|
|
FROM (
|
2012-01-27 14:58:51 -05:00
|
|
|
SELECT oid, proname, proowner, pronamespace, (aclexplode(coalesce(proacl, acldefault('f', proowner)))).* FROM pg_proc
|
2009-12-05 16:43:36 -05:00
|
|
|
) p (oid, proname, proowner, pronamespace, grantor, grantee, prtype, grantable),
|
2003-06-05 12:08:47 -04:00
|
|
|
pg_namespace n,
|
2005-06-28 01:09:14 -04:00
|
|
|
pg_authid u_grantor,
|
2003-06-29 11:14:41 -04:00
|
|
|
(
|
2005-06-28 01:09:14 -04:00
|
|
|
SELECT oid, rolname FROM pg_authid
|
2003-10-18 08:53:35 -04:00
|
|
|
UNION ALL
|
2005-07-25 20:04:19 -04:00
|
|
|
SELECT 0::oid, 'PUBLIC'
|
|
|
|
|
) AS grantee (oid, rolname)
|
2003-06-05 12:08:47 -04:00
|
|
|
|
2003-06-11 05:23:55 -04:00
|
|
|
WHERE p.pronamespace = n.oid
|
2009-12-05 16:43:36 -05:00
|
|
|
AND grantee.oid = p.grantee
|
|
|
|
|
AND u_grantor.oid = p.grantor
|
|
|
|
|
AND p.prtype IN ('EXECUTE')
|
2006-04-02 13:38:13 -04:00
|
|
|
AND (pg_has_role(u_grantor.oid, 'USAGE')
|
|
|
|
|
OR pg_has_role(grantee.oid, 'USAGE')
|
2005-07-25 20:04:19 -04:00
|
|
|
OR grantee.rolname = 'PUBLIC');
|
2003-06-05 12:08:47 -04:00
|
|
|
|
|
|
|
|
GRANT SELECT ON routine_privileges TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
2009-12-05 16:43:36 -05:00
|
|
|
/*
|
2012-07-23 15:31:43 -04:00
|
|
|
* 5.42
|
2009-12-05 16:43:36 -05:00
|
|
|
* ROLE_ROUTINE_GRANTS view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CREATE VIEW role_routine_grants AS
|
|
|
|
|
SELECT grantor,
|
|
|
|
|
grantee,
|
|
|
|
|
specific_catalog,
|
|
|
|
|
specific_schema,
|
|
|
|
|
specific_name,
|
|
|
|
|
routine_catalog,
|
|
|
|
|
routine_schema,
|
|
|
|
|
routine_name,
|
|
|
|
|
privilege_type,
|
|
|
|
|
is_grantable
|
|
|
|
|
FROM routine_privileges
|
|
|
|
|
WHERE grantor IN (SELECT role_name FROM enabled_roles)
|
|
|
|
|
OR grantee IN (SELECT role_name FROM enabled_roles);
|
|
|
|
|
|
|
|
|
|
GRANT SELECT ON role_routine_grants TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
2003-06-05 12:08:47 -04:00
|
|
|
/*
|
2019-05-14 09:15:05 -04:00
|
|
|
* 5.51
|
2006-04-02 13:38:13 -04:00
|
|
|
* ROUTINE_ROUTINE_USAGE view
|
|
|
|
|
*/
|
|
|
|
|
|
2021-02-17 11:53:18 -05:00
|
|
|
CREATE VIEW routine_routine_usage AS
|
2021-04-21 05:54:47 -04:00
|
|
|
SELECT DISTINCT
|
|
|
|
|
CAST(current_database() AS sql_identifier) AS specific_catalog,
|
2021-02-17 11:53:18 -05:00
|
|
|
CAST(np.nspname AS sql_identifier) AS specific_schema,
|
|
|
|
|
CAST(nameconcatoid(p.proname, p.oid) AS sql_identifier) AS specific_name,
|
|
|
|
|
CAST(current_database() AS sql_identifier) AS routine_catalog,
|
|
|
|
|
CAST(np1.nspname AS sql_identifier) AS routine_schema,
|
|
|
|
|
CAST(nameconcatoid(p1.proname, p1.oid) AS sql_identifier) AS routine_name
|
|
|
|
|
|
|
|
|
|
FROM pg_namespace np, pg_proc p, pg_depend d,
|
|
|
|
|
pg_proc p1, pg_namespace np1
|
|
|
|
|
|
|
|
|
|
WHERE np.oid = p.pronamespace
|
|
|
|
|
AND p.oid = d.objid
|
|
|
|
|
AND d.classid = 'pg_catalog.pg_proc'::regclass
|
|
|
|
|
AND d.refobjid = p1.oid
|
|
|
|
|
AND d.refclassid = 'pg_catalog.pg_proc'::regclass
|
|
|
|
|
AND p1.pronamespace = np1.oid
|
|
|
|
|
AND p.prokind IN ('f', 'p') AND p1.prokind IN ('f', 'p')
|
|
|
|
|
AND pg_has_role(p1.proowner, 'USAGE');
|
|
|
|
|
|
|
|
|
|
GRANT SELECT ON routine_routine_usage TO PUBLIC;
|
2006-04-02 13:38:13 -04:00
|
|
|
|
|
|
|
|
|
2010-11-23 15:27:50 -05:00
|
|
|
/*
|
2019-05-14 09:15:05 -04:00
|
|
|
* 5.52
|
2006-04-02 13:38:13 -04:00
|
|
|
* ROUTINE_SEQUENCE_USAGE view
|
|
|
|
|
*/
|
|
|
|
|
|
2021-02-17 11:53:18 -05:00
|
|
|
CREATE VIEW routine_sequence_usage AS
|
2021-04-21 05:54:47 -04:00
|
|
|
SELECT DISTINCT
|
|
|
|
|
CAST(current_database() AS sql_identifier) AS specific_catalog,
|
2021-02-17 11:53:18 -05:00
|
|
|
CAST(np.nspname AS sql_identifier) AS specific_schema,
|
|
|
|
|
CAST(nameconcatoid(p.proname, p.oid) AS sql_identifier) AS specific_name,
|
|
|
|
|
CAST(current_database() AS sql_identifier) AS routine_catalog,
|
|
|
|
|
CAST(np.nspname AS sql_identifier) AS routine_schema,
|
|
|
|
|
CAST(p.proname AS sql_identifier) AS routine_name,
|
|
|
|
|
CAST(current_database() AS sql_identifier) AS sequence_catalog,
|
|
|
|
|
CAST(ns.nspname AS sql_identifier) AS sequence_schema,
|
|
|
|
|
CAST(s.relname AS sql_identifier) AS sequence_name
|
|
|
|
|
|
|
|
|
|
FROM pg_namespace np, pg_proc p, pg_depend d,
|
|
|
|
|
pg_class s, pg_namespace ns
|
|
|
|
|
|
|
|
|
|
WHERE np.oid = p.pronamespace
|
|
|
|
|
AND p.oid = d.objid
|
|
|
|
|
AND d.classid = 'pg_catalog.pg_proc'::regclass
|
|
|
|
|
AND d.refobjid = s.oid
|
|
|
|
|
AND d.refclassid = 'pg_catalog.pg_class'::regclass
|
|
|
|
|
AND s.relnamespace = ns.oid
|
|
|
|
|
AND s.relkind = 'S'
|
|
|
|
|
AND pg_has_role(s.relowner, 'USAGE');
|
|
|
|
|
|
|
|
|
|
GRANT SELECT ON routine_sequence_usage TO PUBLIC;
|
2006-04-02 13:38:13 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2019-05-14 09:15:05 -04:00
|
|
|
* 5.53
|
2006-04-02 13:38:13 -04:00
|
|
|
* ROUTINE_TABLE_USAGE view
|
|
|
|
|
*/
|
|
|
|
|
|
2021-02-17 11:53:18 -05:00
|
|
|
CREATE VIEW routine_table_usage AS
|
2021-04-21 05:54:47 -04:00
|
|
|
SELECT DISTINCT
|
|
|
|
|
CAST(current_database() AS sql_identifier) AS specific_catalog,
|
2021-02-17 11:53:18 -05:00
|
|
|
CAST(np.nspname AS sql_identifier) AS specific_schema,
|
|
|
|
|
CAST(nameconcatoid(p.proname, p.oid) AS sql_identifier) AS specific_name,
|
|
|
|
|
CAST(current_database() AS sql_identifier) AS routine_catalog,
|
|
|
|
|
CAST(np.nspname AS sql_identifier) AS routine_schema,
|
|
|
|
|
CAST(p.proname AS sql_identifier) AS routine_name,
|
|
|
|
|
CAST(current_database() AS sql_identifier) AS table_catalog,
|
|
|
|
|
CAST(nt.nspname AS sql_identifier) AS table_schema,
|
|
|
|
|
CAST(t.relname AS sql_identifier) AS table_name
|
|
|
|
|
|
|
|
|
|
FROM pg_namespace np, pg_proc p, pg_depend d,
|
|
|
|
|
pg_class t, pg_namespace nt
|
|
|
|
|
|
|
|
|
|
WHERE np.oid = p.pronamespace
|
|
|
|
|
AND p.oid = d.objid
|
|
|
|
|
AND d.classid = 'pg_catalog.pg_proc'::regclass
|
|
|
|
|
AND d.refobjid = t.oid
|
|
|
|
|
AND d.refclassid = 'pg_catalog.pg_class'::regclass
|
|
|
|
|
AND t.relnamespace = nt.oid
|
|
|
|
|
AND t.relkind IN ('r', 'v', 'f', 'p')
|
|
|
|
|
AND pg_has_role(t.relowner, 'USAGE');
|
|
|
|
|
|
|
|
|
|
GRANT SELECT ON routine_table_usage TO PUBLIC;
|
2006-04-02 13:38:13 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2019-05-14 09:15:05 -04:00
|
|
|
* 5.54
|
2003-06-05 12:08:47 -04:00
|
|
|
* ROUTINES view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CREATE VIEW routines AS
|
|
|
|
|
SELECT CAST(current_database() AS sql_identifier) AS specific_catalog,
|
|
|
|
|
CAST(n.nspname AS sql_identifier) AS specific_schema,
|
2018-12-20 15:58:58 -05:00
|
|
|
CAST(nameconcatoid(p.proname, p.oid) AS sql_identifier) AS specific_name,
|
2003-06-05 12:08:47 -04:00
|
|
|
CAST(current_database() AS sql_identifier) AS routine_catalog,
|
|
|
|
|
CAST(n.nspname AS sql_identifier) AS routine_schema,
|
|
|
|
|
CAST(p.proname AS sql_identifier) AS routine_name,
|
2018-03-02 08:57:38 -05:00
|
|
|
CAST(CASE p.prokind WHEN 'f' THEN 'FUNCTION' WHEN 'p' THEN 'PROCEDURE' END
|
2017-11-30 08:46:13 -05:00
|
|
|
AS character_data) AS routine_type,
|
2003-06-05 12:08:47 -04:00
|
|
|
CAST(null AS sql_identifier) AS module_catalog,
|
|
|
|
|
CAST(null AS sql_identifier) AS module_schema,
|
|
|
|
|
CAST(null AS sql_identifier) AS module_name,
|
|
|
|
|
CAST(null AS sql_identifier) AS udt_catalog,
|
|
|
|
|
CAST(null AS sql_identifier) AS udt_schema,
|
|
|
|
|
CAST(null AS sql_identifier) AS udt_name,
|
|
|
|
|
|
|
|
|
|
CAST(
|
2018-03-02 08:57:38 -05:00
|
|
|
CASE WHEN p.prokind = 'p' THEN NULL
|
2017-11-30 08:46:13 -05:00
|
|
|
WHEN t.typelem <> 0 AND t.typlen = -1 THEN 'ARRAY'
|
2003-06-28 16:50:08 -04:00
|
|
|
WHEN nt.nspname = 'pg_catalog' THEN format_type(t.oid, null)
|
2003-06-05 12:08:47 -04:00
|
|
|
ELSE 'USER-DEFINED' END AS character_data)
|
|
|
|
|
AS data_type,
|
|
|
|
|
CAST(null AS cardinal_number) AS character_maximum_length,
|
|
|
|
|
CAST(null AS cardinal_number) AS character_octet_length,
|
|
|
|
|
CAST(null AS sql_identifier) AS character_set_catalog,
|
|
|
|
|
CAST(null AS sql_identifier) AS character_set_schema,
|
|
|
|
|
CAST(null AS sql_identifier) AS character_set_name,
|
|
|
|
|
CAST(null AS sql_identifier) AS collation_catalog,
|
|
|
|
|
CAST(null AS sql_identifier) AS collation_schema,
|
|
|
|
|
CAST(null AS sql_identifier) AS collation_name,
|
|
|
|
|
CAST(null AS cardinal_number) AS numeric_precision,
|
|
|
|
|
CAST(null AS cardinal_number) AS numeric_precision_radix,
|
|
|
|
|
CAST(null AS cardinal_number) AS numeric_scale,
|
|
|
|
|
CAST(null AS cardinal_number) AS datetime_precision,
|
|
|
|
|
CAST(null AS character_data) AS interval_type,
|
2011-07-11 11:49:44 -04:00
|
|
|
CAST(null AS cardinal_number) AS interval_precision,
|
2018-03-02 08:57:38 -05:00
|
|
|
CAST(CASE WHEN nt.nspname IS NOT NULL THEN current_database() END AS sql_identifier) AS type_udt_catalog,
|
2003-06-05 12:08:47 -04:00
|
|
|
CAST(nt.nspname AS sql_identifier) AS type_udt_schema,
|
|
|
|
|
CAST(t.typname AS sql_identifier) AS type_udt_name,
|
|
|
|
|
CAST(null AS sql_identifier) AS scope_catalog,
|
|
|
|
|
CAST(null AS sql_identifier) AS scope_schema,
|
|
|
|
|
CAST(null AS sql_identifier) AS scope_name,
|
|
|
|
|
CAST(null AS cardinal_number) AS maximum_cardinality,
|
2018-03-02 08:57:38 -05:00
|
|
|
CAST(CASE WHEN p.prokind <> 'p' THEN 0 END AS sql_identifier) AS dtd_identifier,
|
2003-06-05 12:08:47 -04:00
|
|
|
|
|
|
|
|
CAST(CASE WHEN l.lanname = 'sql' THEN 'SQL' ELSE 'EXTERNAL' END AS character_data)
|
|
|
|
|
AS routine_body,
|
|
|
|
|
CAST(
|
2006-04-02 13:38:13 -04:00
|
|
|
CASE WHEN pg_has_role(p.proowner, 'USAGE') THEN p.prosrc ELSE null END
|
2003-06-05 12:08:47 -04:00
|
|
|
AS character_data) AS routine_definition,
|
|
|
|
|
CAST(
|
|
|
|
|
CASE WHEN l.lanname = 'c' THEN p.prosrc ELSE null END
|
|
|
|
|
AS character_data) AS external_name,
|
|
|
|
|
CAST(upper(l.lanname) AS character_data) AS external_language,
|
|
|
|
|
|
|
|
|
|
CAST('GENERAL' AS character_data) AS parameter_style,
|
2009-07-13 16:25:57 -04:00
|
|
|
CAST(CASE WHEN p.provolatile = 'i' THEN 'YES' ELSE 'NO' END AS yes_or_no) AS is_deterministic,
|
2003-06-05 12:08:47 -04:00
|
|
|
CAST('MODIFIES' AS character_data) AS sql_data_access,
|
2018-03-02 08:57:38 -05:00
|
|
|
CAST(CASE WHEN p.prokind <> 'p' THEN
|
2017-11-30 08:46:13 -05:00
|
|
|
CASE WHEN p.proisstrict THEN 'YES' ELSE 'NO' END END AS yes_or_no) AS is_null_call,
|
2003-06-05 12:08:47 -04:00
|
|
|
CAST(null AS character_data) AS sql_path,
|
2009-07-13 16:25:57 -04:00
|
|
|
CAST('YES' AS yes_or_no) AS schema_level_routine,
|
2003-06-05 12:08:47 -04:00
|
|
|
CAST(0 AS cardinal_number) AS max_dynamic_result_sets,
|
2009-07-13 16:25:57 -04:00
|
|
|
CAST(null AS yes_or_no) AS is_user_defined_cast,
|
|
|
|
|
CAST(null AS yes_or_no) AS is_implicitly_invocable,
|
2003-06-05 12:08:47 -04:00
|
|
|
CAST(CASE WHEN p.prosecdef THEN 'DEFINER' ELSE 'INVOKER' END AS character_data) AS security_type,
|
|
|
|
|
CAST(null AS sql_identifier) AS to_sql_specific_catalog,
|
|
|
|
|
CAST(null AS sql_identifier) AS to_sql_specific_schema,
|
|
|
|
|
CAST(null AS sql_identifier) AS to_sql_specific_name,
|
2009-07-13 16:25:57 -04:00
|
|
|
CAST('NO' AS yes_or_no) AS as_locator,
|
2006-04-02 13:38:13 -04:00
|
|
|
CAST(null AS time_stamp) AS created,
|
|
|
|
|
CAST(null AS time_stamp) AS last_altered,
|
2009-07-13 16:25:57 -04:00
|
|
|
CAST(null AS yes_or_no) AS new_savepoint_level,
|
2011-07-14 12:18:17 -04:00
|
|
|
CAST('NO' AS yes_or_no) AS is_udt_dependent,
|
2006-04-02 13:38:13 -04:00
|
|
|
|
|
|
|
|
CAST(null AS character_data) AS result_cast_from_data_type,
|
2009-07-13 16:25:57 -04:00
|
|
|
CAST(null AS yes_or_no) AS result_cast_as_locator,
|
2006-04-02 13:38:13 -04:00
|
|
|
CAST(null AS cardinal_number) AS result_cast_char_max_length,
|
|
|
|
|
CAST(null AS cardinal_number) AS result_cast_char_octet_length,
|
|
|
|
|
CAST(null AS sql_identifier) AS result_cast_char_set_catalog,
|
|
|
|
|
CAST(null AS sql_identifier) AS result_cast_char_set_schema,
|
2016-08-07 21:53:16 -04:00
|
|
|
CAST(null AS sql_identifier) AS result_cast_char_set_name,
|
2006-04-02 13:38:13 -04:00
|
|
|
CAST(null AS sql_identifier) AS result_cast_collation_catalog,
|
|
|
|
|
CAST(null AS sql_identifier) AS result_cast_collation_schema,
|
|
|
|
|
CAST(null AS sql_identifier) AS result_cast_collation_name,
|
|
|
|
|
CAST(null AS cardinal_number) AS result_cast_numeric_precision,
|
|
|
|
|
CAST(null AS cardinal_number) AS result_cast_numeric_precision_radix,
|
|
|
|
|
CAST(null AS cardinal_number) AS result_cast_numeric_scale,
|
|
|
|
|
CAST(null AS cardinal_number) AS result_cast_datetime_precision,
|
|
|
|
|
CAST(null AS character_data) AS result_cast_interval_type,
|
2011-07-11 11:49:44 -04:00
|
|
|
CAST(null AS cardinal_number) AS result_cast_interval_precision,
|
2006-04-02 13:38:13 -04:00
|
|
|
CAST(null AS sql_identifier) AS result_cast_type_udt_catalog,
|
|
|
|
|
CAST(null AS sql_identifier) AS result_cast_type_udt_schema,
|
|
|
|
|
CAST(null AS sql_identifier) AS result_cast_type_udt_name,
|
|
|
|
|
CAST(null AS sql_identifier) AS result_cast_scope_catalog,
|
|
|
|
|
CAST(null AS sql_identifier) AS result_cast_scope_schema,
|
|
|
|
|
CAST(null AS sql_identifier) AS result_cast_scope_name,
|
|
|
|
|
CAST(null AS cardinal_number) AS result_cast_maximum_cardinality,
|
2010-11-23 15:27:50 -05:00
|
|
|
CAST(null AS sql_identifier) AS result_cast_dtd_identifier
|
2003-06-05 12:08:47 -04:00
|
|
|
|
2017-11-30 08:46:13 -05:00
|
|
|
FROM (pg_namespace n
|
|
|
|
|
JOIN pg_proc p ON n.oid = p.pronamespace
|
|
|
|
|
JOIN pg_language l ON p.prolang = l.oid)
|
|
|
|
|
LEFT JOIN
|
|
|
|
|
(pg_type t JOIN pg_namespace nt ON t.typnamespace = nt.oid)
|
2018-03-02 08:57:38 -05:00
|
|
|
ON p.prorettype = t.oid AND p.prokind <> 'p'
|
2003-06-05 12:08:47 -04:00
|
|
|
|
2017-11-30 08:46:13 -05:00
|
|
|
WHERE (pg_has_role(p.proowner, 'USAGE')
|
|
|
|
|
OR has_function_privilege(p.oid, 'EXECUTE'));
|
2003-06-05 12:08:47 -04:00
|
|
|
|
|
|
|
|
GRANT SELECT ON routines TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
2002-12-13 19:24:35 -05:00
|
|
|
/*
|
2019-05-14 09:15:05 -04:00
|
|
|
* 5.55
|
2002-12-13 19:24:35 -05:00
|
|
|
* SCHEMATA view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CREATE VIEW schemata AS
|
|
|
|
|
SELECT CAST(current_database() AS sql_identifier) AS catalog_name,
|
|
|
|
|
CAST(n.nspname AS sql_identifier) AS schema_name,
|
2005-07-25 20:04:19 -04:00
|
|
|
CAST(u.rolname AS sql_identifier) AS schema_owner,
|
2002-12-13 19:24:35 -05:00
|
|
|
CAST(null AS sql_identifier) AS default_character_set_catalog,
|
|
|
|
|
CAST(null AS sql_identifier) AS default_character_set_schema,
|
|
|
|
|
CAST(null AS sql_identifier) AS default_character_set_name,
|
|
|
|
|
CAST(null AS character_data) AS sql_path
|
2005-07-25 20:04:19 -04:00
|
|
|
FROM pg_namespace n, pg_authid u
|
2013-09-09 22:25:37 -04:00
|
|
|
WHERE n.nspowner = u.oid
|
|
|
|
|
AND (pg_has_role(n.nspowner, 'USAGE')
|
|
|
|
|
OR has_schema_privilege(n.oid, 'CREATE, USAGE'));
|
2002-12-13 19:24:35 -05:00
|
|
|
|
|
|
|
|
GRANT SELECT ON schemata TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2019-05-14 09:15:05 -04:00
|
|
|
* 5.56
|
2006-04-02 13:38:13 -04:00
|
|
|
* SEQUENCES view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CREATE VIEW sequences AS
|
|
|
|
|
SELECT CAST(current_database() AS sql_identifier) AS sequence_catalog,
|
|
|
|
|
CAST(nc.nspname AS sql_identifier) AS sequence_schema,
|
|
|
|
|
CAST(c.relname AS sql_identifier) AS sequence_name,
|
2017-02-10 15:12:32 -05:00
|
|
|
CAST(format_type(s.seqtypid, null) AS character_data) AS data_type,
|
|
|
|
|
CAST(_pg_numeric_precision(s.seqtypid, -1) AS cardinal_number) AS numeric_precision,
|
2006-04-02 13:38:13 -04:00
|
|
|
CAST(2 AS cardinal_number) AS numeric_precision_radix,
|
|
|
|
|
CAST(0 AS cardinal_number) AS numeric_scale,
|
2016-12-20 12:00:00 -05:00
|
|
|
CAST(s.seqstart AS character_data) AS start_value,
|
|
|
|
|
CAST(s.seqmin AS character_data) AS minimum_value,
|
|
|
|
|
CAST(s.seqmax AS character_data) AS maximum_value,
|
|
|
|
|
CAST(s.seqincrement AS character_data) AS increment,
|
|
|
|
|
CAST(CASE WHEN s.seqcycle THEN 'YES' ELSE 'NO' END AS yes_or_no) AS cycle_option
|
|
|
|
|
FROM pg_namespace nc, pg_class c, pg_sequence s
|
2006-04-02 13:38:13 -04:00
|
|
|
WHERE c.relnamespace = nc.oid
|
2006-09-04 17:03:18 -04:00
|
|
|
AND c.relkind = 'S'
|
2017-04-06 08:33:16 -04:00
|
|
|
AND NOT EXISTS (SELECT 1 FROM pg_depend WHERE classid = 'pg_class'::regclass AND objid = c.oid AND deptype = 'i')
|
2006-09-14 18:05:06 -04:00
|
|
|
AND (NOT pg_is_other_temp_schema(nc.oid))
|
2016-12-20 12:00:00 -05:00
|
|
|
AND c.oid = s.seqrelid
|
2006-04-02 13:38:13 -04:00
|
|
|
AND (pg_has_role(c.relowner, 'USAGE')
|
2011-01-02 08:08:08 -05:00
|
|
|
OR has_sequence_privilege(c.oid, 'SELECT, UPDATE, USAGE') );
|
2006-04-02 13:38:13 -04:00
|
|
|
|
|
|
|
|
GRANT SELECT ON sequences TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2019-05-14 09:15:05 -04:00
|
|
|
* 5.57
|
2002-12-13 19:24:35 -05:00
|
|
|
* SQL_FEATURES table
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CREATE TABLE sql_features (
|
|
|
|
|
feature_id character_data,
|
|
|
|
|
feature_name character_data,
|
|
|
|
|
sub_feature_id character_data,
|
|
|
|
|
sub_feature_name character_data,
|
2009-07-13 16:25:57 -04:00
|
|
|
is_supported yes_or_no,
|
2002-12-13 19:24:35 -05:00
|
|
|
is_verified_by character_data,
|
|
|
|
|
comments character_data
|
Remove WITH OIDS support, change oid catalog column visibility.
Previously tables declared WITH OIDS, including a significant fraction
of the catalog tables, stored the oid column not as a normal column,
but as part of the tuple header.
This special column was not shown by default, which was somewhat odd,
as it's often (consider e.g. pg_class.oid) one of the more important
parts of a row. Neither pg_dump nor COPY included the contents of the
oid column by default.
The fact that the oid column was not an ordinary column necessitated a
significant amount of special case code to support oid columns. That
already was painful for the existing, but upcoming work aiming to make
table storage pluggable, would have required expanding and duplicating
that "specialness" significantly.
WITH OIDS has been deprecated since 2005 (commit ff02d0a05280e0).
Remove it.
Removing includes:
- CREATE TABLE and ALTER TABLE syntax for declaring the table to be
WITH OIDS has been removed (WITH (oids[ = true]) will error out)
- pg_dump does not support dumping tables declared WITH OIDS and will
issue a warning when dumping one (and ignore the oid column).
- restoring an pg_dump archive with pg_restore will warn when
restoring a table with oid contents (and ignore the oid column)
- COPY will refuse to load binary dump that includes oids.
- pg_upgrade will error out when encountering tables declared WITH
OIDS, they have to be altered to remove the oid column first.
- Functionality to access the oid of the last inserted row (like
plpgsql's RESULT_OID, spi's SPI_lastoid, ...) has been removed.
The syntax for declaring a table WITHOUT OIDS (or WITH (oids = false)
for CREATE TABLE) is still supported. While that requires a bit of
support code, it seems unnecessary to break applications / dumps that
do not use oids, and are explicit about not using them.
The biggest user of WITH OID columns was postgres' catalog. This
commit changes all 'magic' oid columns to be columns that are normally
declared and stored. To reduce unnecessary query breakage all the
newly added columns are still named 'oid', even if a table's column
naming scheme would indicate 'reloid' or such. This obviously
requires adapting a lot code, mostly replacing oid access via
HeapTupleGetOid() with access to the underlying Form_pg_*->oid column.
The bootstrap process now assigns oids for all oid columns in
genbki.pl that do not have an explicit value (starting at the largest
oid previously used), only oids assigned later by oids will be above
FirstBootstrapObjectId. As the oid column now is a normal column the
special bootstrap syntax for oids has been removed.
Oids are not automatically assigned during insertion anymore, all
backend code explicitly assigns oids with GetNewOidWithIndex(). For
the rare case that insertions into the catalog via SQL are called for
the new pg_nextoid() function can be used (which only works on catalog
tables).
The fact that oid columns on system tables are now normal columns
means that they will be included in the set of columns expanded
by * (i.e. SELECT * FROM pg_class will now include the table's oid,
previously it did not). It'd not technically be hard to hide oid
column by default, but that'd mean confusing behavior would either
have to be carried forward forever, or it'd cause breakage down the
line.
While it's not unlikely that further adjustments are needed, the
scope/invasiveness of the patch makes it worthwhile to get merge this
now. It's painful to maintain externally, too complicated to commit
after the code code freeze, and a dependency of a number of other
patches.
Catversion bump, for obvious reasons.
Author: Andres Freund, with contributions by John Naylor
Discussion: https://postgr.es/m/20180930034810.ywp2c7awz7opzcfr@alap3.anarazel.de
2018-11-20 18:36:57 -05:00
|
|
|
);
|
2002-12-13 19:24:35 -05:00
|
|
|
|
2003-01-14 18:19:34 -05:00
|
|
|
-- Will be filled with external data by initdb.
|
2002-12-13 19:24:35 -05:00
|
|
|
|
|
|
|
|
GRANT SELECT ON sql_features TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
2003-01-15 18:37:28 -05:00
|
|
|
/*
|
2019-05-14 09:15:05 -04:00
|
|
|
* 5.58
|
2003-01-15 18:37:28 -05:00
|
|
|
* SQL_IMPLEMENTATION_INFO table
|
|
|
|
|
*/
|
|
|
|
|
|
2009-07-13 16:25:57 -04:00
|
|
|
-- Note: Implementation information items are defined in ISO/IEC 9075-3:2008,
|
|
|
|
|
-- clause 9.1.
|
2003-01-15 18:37:28 -05:00
|
|
|
|
|
|
|
|
CREATE TABLE sql_implementation_info (
|
|
|
|
|
implementation_info_id character_data,
|
|
|
|
|
implementation_info_name character_data,
|
|
|
|
|
integer_value cardinal_number,
|
|
|
|
|
character_value character_data,
|
|
|
|
|
comments character_data
|
Remove WITH OIDS support, change oid catalog column visibility.
Previously tables declared WITH OIDS, including a significant fraction
of the catalog tables, stored the oid column not as a normal column,
but as part of the tuple header.
This special column was not shown by default, which was somewhat odd,
as it's often (consider e.g. pg_class.oid) one of the more important
parts of a row. Neither pg_dump nor COPY included the contents of the
oid column by default.
The fact that the oid column was not an ordinary column necessitated a
significant amount of special case code to support oid columns. That
already was painful for the existing, but upcoming work aiming to make
table storage pluggable, would have required expanding and duplicating
that "specialness" significantly.
WITH OIDS has been deprecated since 2005 (commit ff02d0a05280e0).
Remove it.
Removing includes:
- CREATE TABLE and ALTER TABLE syntax for declaring the table to be
WITH OIDS has been removed (WITH (oids[ = true]) will error out)
- pg_dump does not support dumping tables declared WITH OIDS and will
issue a warning when dumping one (and ignore the oid column).
- restoring an pg_dump archive with pg_restore will warn when
restoring a table with oid contents (and ignore the oid column)
- COPY will refuse to load binary dump that includes oids.
- pg_upgrade will error out when encountering tables declared WITH
OIDS, they have to be altered to remove the oid column first.
- Functionality to access the oid of the last inserted row (like
plpgsql's RESULT_OID, spi's SPI_lastoid, ...) has been removed.
The syntax for declaring a table WITHOUT OIDS (or WITH (oids = false)
for CREATE TABLE) is still supported. While that requires a bit of
support code, it seems unnecessary to break applications / dumps that
do not use oids, and are explicit about not using them.
The biggest user of WITH OID columns was postgres' catalog. This
commit changes all 'magic' oid columns to be columns that are normally
declared and stored. To reduce unnecessary query breakage all the
newly added columns are still named 'oid', even if a table's column
naming scheme would indicate 'reloid' or such. This obviously
requires adapting a lot code, mostly replacing oid access via
HeapTupleGetOid() with access to the underlying Form_pg_*->oid column.
The bootstrap process now assigns oids for all oid columns in
genbki.pl that do not have an explicit value (starting at the largest
oid previously used), only oids assigned later by oids will be above
FirstBootstrapObjectId. As the oid column now is a normal column the
special bootstrap syntax for oids has been removed.
Oids are not automatically assigned during insertion anymore, all
backend code explicitly assigns oids with GetNewOidWithIndex(). For
the rare case that insertions into the catalog via SQL are called for
the new pg_nextoid() function can be used (which only works on catalog
tables).
The fact that oid columns on system tables are now normal columns
means that they will be included in the set of columns expanded
by * (i.e. SELECT * FROM pg_class will now include the table's oid,
previously it did not). It'd not technically be hard to hide oid
column by default, but that'd mean confusing behavior would either
have to be carried forward forever, or it'd cause breakage down the
line.
While it's not unlikely that further adjustments are needed, the
scope/invasiveness of the patch makes it worthwhile to get merge this
now. It's painful to maintain externally, too complicated to commit
after the code code freeze, and a dependency of a number of other
patches.
Catversion bump, for obvious reasons.
Author: Andres Freund, with contributions by John Naylor
Discussion: https://postgr.es/m/20180930034810.ywp2c7awz7opzcfr@alap3.anarazel.de
2018-11-20 18:36:57 -05:00
|
|
|
);
|
2003-01-15 18:37:28 -05:00
|
|
|
|
|
|
|
|
INSERT INTO sql_implementation_info VALUES ('10003', 'CATALOG NAME', NULL, 'Y', NULL);
|
2011-06-28 10:49:28 -04:00
|
|
|
INSERT INTO sql_implementation_info VALUES ('10004', 'COLLATING SEQUENCE', NULL, (SELECT default_collate_name FROM character_sets), NULL);
|
2003-01-15 18:37:28 -05:00
|
|
|
INSERT INTO sql_implementation_info VALUES ('23', 'CURSOR COMMIT BEHAVIOR', 1, NULL, 'close cursors and retain prepared statements');
|
|
|
|
|
INSERT INTO sql_implementation_info VALUES ('2', 'DATA SOURCE NAME', NULL, '', NULL);
|
|
|
|
|
INSERT INTO sql_implementation_info VALUES ('17', 'DBMS NAME', NULL, (select trim(trailing ' ' from substring(version() from '^[^0-9]*'))), NULL);
|
|
|
|
|
INSERT INTO sql_implementation_info VALUES ('18', 'DBMS VERSION', NULL, '???', NULL); -- filled by initdb
|
2003-10-18 08:53:35 -04:00
|
|
|
INSERT INTO sql_implementation_info VALUES ('26', 'DEFAULT TRANSACTION ISOLATION', 2, NULL, 'READ COMMITTED; user-settable');
|
2003-01-15 18:37:28 -05:00
|
|
|
INSERT INTO sql_implementation_info VALUES ('28', 'IDENTIFIER CASE', 3, NULL, 'stored in mixed case - case sensitive');
|
|
|
|
|
INSERT INTO sql_implementation_info VALUES ('85', 'NULL COLLATION', 0, NULL, 'nulls higher than non-nulls');
|
|
|
|
|
INSERT INTO sql_implementation_info VALUES ('13', 'SERVER NAME', NULL, '', NULL);
|
|
|
|
|
INSERT INTO sql_implementation_info VALUES ('94', 'SPECIAL CHARACTERS', NULL, '', 'all non-ASCII characters allowed');
|
|
|
|
|
INSERT INTO sql_implementation_info VALUES ('46', 'TRANSACTION CAPABLE', 2, NULL, 'both DML and DDL');
|
|
|
|
|
|
|
|
|
|
GRANT SELECT ON sql_implementation_info TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2019-05-14 09:15:05 -04:00
|
|
|
* 5.59
|
2006-04-02 13:38:13 -04:00
|
|
|
* SQL_PARTS table
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CREATE TABLE sql_parts (
|
|
|
|
|
feature_id character_data,
|
|
|
|
|
feature_name character_data,
|
2009-07-13 16:25:57 -04:00
|
|
|
is_supported yes_or_no,
|
2006-04-02 13:38:13 -04:00
|
|
|
is_verified_by character_data,
|
|
|
|
|
comments character_data
|
Remove WITH OIDS support, change oid catalog column visibility.
Previously tables declared WITH OIDS, including a significant fraction
of the catalog tables, stored the oid column not as a normal column,
but as part of the tuple header.
This special column was not shown by default, which was somewhat odd,
as it's often (consider e.g. pg_class.oid) one of the more important
parts of a row. Neither pg_dump nor COPY included the contents of the
oid column by default.
The fact that the oid column was not an ordinary column necessitated a
significant amount of special case code to support oid columns. That
already was painful for the existing, but upcoming work aiming to make
table storage pluggable, would have required expanding and duplicating
that "specialness" significantly.
WITH OIDS has been deprecated since 2005 (commit ff02d0a05280e0).
Remove it.
Removing includes:
- CREATE TABLE and ALTER TABLE syntax for declaring the table to be
WITH OIDS has been removed (WITH (oids[ = true]) will error out)
- pg_dump does not support dumping tables declared WITH OIDS and will
issue a warning when dumping one (and ignore the oid column).
- restoring an pg_dump archive with pg_restore will warn when
restoring a table with oid contents (and ignore the oid column)
- COPY will refuse to load binary dump that includes oids.
- pg_upgrade will error out when encountering tables declared WITH
OIDS, they have to be altered to remove the oid column first.
- Functionality to access the oid of the last inserted row (like
plpgsql's RESULT_OID, spi's SPI_lastoid, ...) has been removed.
The syntax for declaring a table WITHOUT OIDS (or WITH (oids = false)
for CREATE TABLE) is still supported. While that requires a bit of
support code, it seems unnecessary to break applications / dumps that
do not use oids, and are explicit about not using them.
The biggest user of WITH OID columns was postgres' catalog. This
commit changes all 'magic' oid columns to be columns that are normally
declared and stored. To reduce unnecessary query breakage all the
newly added columns are still named 'oid', even if a table's column
naming scheme would indicate 'reloid' or such. This obviously
requires adapting a lot code, mostly replacing oid access via
HeapTupleGetOid() with access to the underlying Form_pg_*->oid column.
The bootstrap process now assigns oids for all oid columns in
genbki.pl that do not have an explicit value (starting at the largest
oid previously used), only oids assigned later by oids will be above
FirstBootstrapObjectId. As the oid column now is a normal column the
special bootstrap syntax for oids has been removed.
Oids are not automatically assigned during insertion anymore, all
backend code explicitly assigns oids with GetNewOidWithIndex(). For
the rare case that insertions into the catalog via SQL are called for
the new pg_nextoid() function can be used (which only works on catalog
tables).
The fact that oid columns on system tables are now normal columns
means that they will be included in the set of columns expanded
by * (i.e. SELECT * FROM pg_class will now include the table's oid,
previously it did not). It'd not technically be hard to hide oid
column by default, but that'd mean confusing behavior would either
have to be carried forward forever, or it'd cause breakage down the
line.
While it's not unlikely that further adjustments are needed, the
scope/invasiveness of the patch makes it worthwhile to get merge this
now. It's painful to maintain externally, too complicated to commit
after the code code freeze, and a dependency of a number of other
patches.
Catversion bump, for obvious reasons.
Author: Andres Freund, with contributions by John Naylor
Discussion: https://postgr.es/m/20180930034810.ywp2c7awz7opzcfr@alap3.anarazel.de
2018-11-20 18:36:57 -05:00
|
|
|
);
|
2006-04-02 13:38:13 -04:00
|
|
|
|
|
|
|
|
INSERT INTO sql_parts VALUES ('1', 'Framework (SQL/Framework)', 'NO', NULL, '');
|
|
|
|
|
INSERT INTO sql_parts VALUES ('2', 'Foundation (SQL/Foundation)', 'NO', NULL, '');
|
|
|
|
|
INSERT INTO sql_parts VALUES ('3', 'Call-Level Interface (SQL/CLI)', 'NO', NULL, '');
|
2007-02-03 12:59:36 -05:00
|
|
|
INSERT INTO sql_parts VALUES ('4', 'Persistent Stored Modules (SQL/PSM)', 'NO', NULL, '');
|
|
|
|
|
INSERT INTO sql_parts VALUES ('9', 'Management of External Data (SQL/MED)', 'NO', NULL, '');
|
|
|
|
|
INSERT INTO sql_parts VALUES ('10', 'Object Language Bindings (SQL/OLB)', 'NO', NULL, '');
|
|
|
|
|
INSERT INTO sql_parts VALUES ('11', 'Information and Definition Schema (SQL/Schemata)', 'NO', NULL, '');
|
|
|
|
|
INSERT INTO sql_parts VALUES ('13', 'Routines and Types Using the Java Programming Language (SQL/JRT)', 'NO', NULL, '');
|
2019-05-14 08:56:58 -04:00
|
|
|
INSERT INTO sql_parts VALUES ('14', 'XML-Related Specifications (SQL/XML)', 'NO', NULL, '');
|
2020-03-30 02:55:55 -04:00
|
|
|
INSERT INTO sql_parts VALUES ('15', 'Multi-Dimensional Arrays (SQL/MDA)', 'NO', NULL, '');
|
2006-04-02 13:38:13 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2019-05-14 09:15:05 -04:00
|
|
|
* 5.60
|
2003-01-15 18:37:28 -05:00
|
|
|
* SQL_SIZING table
|
|
|
|
|
*/
|
|
|
|
|
|
2009-07-13 16:25:57 -04:00
|
|
|
-- Note: Sizing items are defined in ISO/IEC 9075-3:2008, clause 9.2.
|
2003-01-15 18:37:28 -05:00
|
|
|
|
|
|
|
|
CREATE TABLE sql_sizing (
|
|
|
|
|
sizing_id cardinal_number,
|
|
|
|
|
sizing_name character_data,
|
|
|
|
|
supported_value cardinal_number,
|
|
|
|
|
comments character_data
|
Remove WITH OIDS support, change oid catalog column visibility.
Previously tables declared WITH OIDS, including a significant fraction
of the catalog tables, stored the oid column not as a normal column,
but as part of the tuple header.
This special column was not shown by default, which was somewhat odd,
as it's often (consider e.g. pg_class.oid) one of the more important
parts of a row. Neither pg_dump nor COPY included the contents of the
oid column by default.
The fact that the oid column was not an ordinary column necessitated a
significant amount of special case code to support oid columns. That
already was painful for the existing, but upcoming work aiming to make
table storage pluggable, would have required expanding and duplicating
that "specialness" significantly.
WITH OIDS has been deprecated since 2005 (commit ff02d0a05280e0).
Remove it.
Removing includes:
- CREATE TABLE and ALTER TABLE syntax for declaring the table to be
WITH OIDS has been removed (WITH (oids[ = true]) will error out)
- pg_dump does not support dumping tables declared WITH OIDS and will
issue a warning when dumping one (and ignore the oid column).
- restoring an pg_dump archive with pg_restore will warn when
restoring a table with oid contents (and ignore the oid column)
- COPY will refuse to load binary dump that includes oids.
- pg_upgrade will error out when encountering tables declared WITH
OIDS, they have to be altered to remove the oid column first.
- Functionality to access the oid of the last inserted row (like
plpgsql's RESULT_OID, spi's SPI_lastoid, ...) has been removed.
The syntax for declaring a table WITHOUT OIDS (or WITH (oids = false)
for CREATE TABLE) is still supported. While that requires a bit of
support code, it seems unnecessary to break applications / dumps that
do not use oids, and are explicit about not using them.
The biggest user of WITH OID columns was postgres' catalog. This
commit changes all 'magic' oid columns to be columns that are normally
declared and stored. To reduce unnecessary query breakage all the
newly added columns are still named 'oid', even if a table's column
naming scheme would indicate 'reloid' or such. This obviously
requires adapting a lot code, mostly replacing oid access via
HeapTupleGetOid() with access to the underlying Form_pg_*->oid column.
The bootstrap process now assigns oids for all oid columns in
genbki.pl that do not have an explicit value (starting at the largest
oid previously used), only oids assigned later by oids will be above
FirstBootstrapObjectId. As the oid column now is a normal column the
special bootstrap syntax for oids has been removed.
Oids are not automatically assigned during insertion anymore, all
backend code explicitly assigns oids with GetNewOidWithIndex(). For
the rare case that insertions into the catalog via SQL are called for
the new pg_nextoid() function can be used (which only works on catalog
tables).
The fact that oid columns on system tables are now normal columns
means that they will be included in the set of columns expanded
by * (i.e. SELECT * FROM pg_class will now include the table's oid,
previously it did not). It'd not technically be hard to hide oid
column by default, but that'd mean confusing behavior would either
have to be carried forward forever, or it'd cause breakage down the
line.
While it's not unlikely that further adjustments are needed, the
scope/invasiveness of the patch makes it worthwhile to get merge this
now. It's painful to maintain externally, too complicated to commit
after the code code freeze, and a dependency of a number of other
patches.
Catversion bump, for obvious reasons.
Author: Andres Freund, with contributions by John Naylor
Discussion: https://postgr.es/m/20180930034810.ywp2c7awz7opzcfr@alap3.anarazel.de
2018-11-20 18:36:57 -05:00
|
|
|
);
|
2003-01-15 18:37:28 -05:00
|
|
|
|
|
|
|
|
INSERT INTO sql_sizing VALUES (34, 'MAXIMUM CATALOG NAME LENGTH', 63, NULL);
|
|
|
|
|
INSERT INTO sql_sizing VALUES (30, 'MAXIMUM COLUMN NAME LENGTH', 63, NULL);
|
|
|
|
|
INSERT INTO sql_sizing VALUES (97, 'MAXIMUM COLUMNS IN GROUP BY', 0, NULL);
|
|
|
|
|
INSERT INTO sql_sizing VALUES (99, 'MAXIMUM COLUMNS IN ORDER BY', 0, NULL);
|
2003-10-18 08:53:35 -04:00
|
|
|
INSERT INTO sql_sizing VALUES (100, 'MAXIMUM COLUMNS IN SELECT', 1664, NULL); -- match MaxTupleAttributeNumber
|
2003-01-15 18:37:28 -05:00
|
|
|
INSERT INTO sql_sizing VALUES (101, 'MAXIMUM COLUMNS IN TABLE', 1600, NULL); -- match MaxHeapAttributeNumber
|
|
|
|
|
INSERT INTO sql_sizing VALUES (1, 'MAXIMUM CONCURRENT ACTIVITIES', 0, NULL);
|
|
|
|
|
INSERT INTO sql_sizing VALUES (31, 'MAXIMUM CURSOR NAME LENGTH', 63, NULL);
|
|
|
|
|
INSERT INTO sql_sizing VALUES (0, 'MAXIMUM DRIVER CONNECTIONS', NULL, NULL);
|
|
|
|
|
INSERT INTO sql_sizing VALUES (10005, 'MAXIMUM IDENTIFIER LENGTH', 63, NULL);
|
|
|
|
|
INSERT INTO sql_sizing VALUES (32, 'MAXIMUM SCHEMA NAME LENGTH', 63, NULL);
|
|
|
|
|
INSERT INTO sql_sizing VALUES (20000, 'MAXIMUM STATEMENT OCTETS', 0, NULL);
|
|
|
|
|
INSERT INTO sql_sizing VALUES (20001, 'MAXIMUM STATEMENT OCTETS DATA', 0, NULL);
|
|
|
|
|
INSERT INTO sql_sizing VALUES (20002, 'MAXIMUM STATEMENT OCTETS SCHEMA', 0, NULL);
|
|
|
|
|
INSERT INTO sql_sizing VALUES (35, 'MAXIMUM TABLE NAME LENGTH', 63, NULL);
|
|
|
|
|
INSERT INTO sql_sizing VALUES (106, 'MAXIMUM TABLES IN SELECT', 0, NULL);
|
|
|
|
|
INSERT INTO sql_sizing VALUES (107, 'MAXIMUM USER NAME LENGTH', 63, NULL);
|
|
|
|
|
INSERT INTO sql_sizing VALUES (25000, 'MAXIMUM CURRENT DEFAULT TRANSFORM GROUP LENGTH', NULL, NULL);
|
|
|
|
|
INSERT INTO sql_sizing VALUES (25001, 'MAXIMUM CURRENT TRANSFORM GROUP LENGTH', NULL, NULL);
|
|
|
|
|
INSERT INTO sql_sizing VALUES (25002, 'MAXIMUM CURRENT PATH LENGTH', 0, NULL);
|
|
|
|
|
INSERT INTO sql_sizing VALUES (25003, 'MAXIMUM CURRENT ROLE LENGTH', NULL, NULL);
|
|
|
|
|
INSERT INTO sql_sizing VALUES (25004, 'MAXIMUM SESSION USER LENGTH', 63, NULL);
|
|
|
|
|
INSERT INTO sql_sizing VALUES (25005, 'MAXIMUM SYSTEM USER LENGTH', 63, NULL);
|
|
|
|
|
|
|
|
|
|
UPDATE sql_sizing
|
|
|
|
|
SET supported_value = (SELECT typlen-1 FROM pg_catalog.pg_type WHERE typname = 'name'),
|
|
|
|
|
comments = 'Might be less, depending on character set.'
|
|
|
|
|
WHERE supported_value = 63;
|
|
|
|
|
|
|
|
|
|
GRANT SELECT ON sql_sizing TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
2002-12-13 19:24:35 -05:00
|
|
|
/*
|
2019-05-14 09:15:05 -04:00
|
|
|
* 5.61
|
2002-12-13 19:24:35 -05:00
|
|
|
* TABLE_CONSTRAINTS view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CREATE VIEW table_constraints AS
|
|
|
|
|
SELECT CAST(current_database() AS sql_identifier) AS constraint_catalog,
|
|
|
|
|
CAST(nc.nspname AS sql_identifier) AS constraint_schema,
|
|
|
|
|
CAST(c.conname AS sql_identifier) AS constraint_name,
|
|
|
|
|
CAST(current_database() AS sql_identifier) AS table_catalog,
|
|
|
|
|
CAST(nr.nspname AS sql_identifier) AS table_schema,
|
|
|
|
|
CAST(r.relname AS sql_identifier) AS table_name,
|
|
|
|
|
CAST(
|
|
|
|
|
CASE c.contype WHEN 'c' THEN 'CHECK'
|
|
|
|
|
WHEN 'f' THEN 'FOREIGN KEY'
|
|
|
|
|
WHEN 'p' THEN 'PRIMARY KEY'
|
|
|
|
|
WHEN 'u' THEN 'UNIQUE' END
|
|
|
|
|
AS character_data) AS constraint_type,
|
2009-07-13 16:25:57 -04:00
|
|
|
CAST(CASE WHEN c.condeferrable THEN 'YES' ELSE 'NO' END AS yes_or_no)
|
2002-12-13 19:24:35 -05:00
|
|
|
AS is_deferrable,
|
2009-07-13 16:25:57 -04:00
|
|
|
CAST(CASE WHEN c.condeferred THEN 'YES' ELSE 'NO' END AS yes_or_no)
|
2018-02-06 22:43:21 -05:00
|
|
|
AS initially_deferred,
|
|
|
|
|
CAST('YES' AS yes_or_no) AS enforced
|
2002-12-13 19:24:35 -05:00
|
|
|
|
|
|
|
|
FROM pg_namespace nc,
|
|
|
|
|
pg_namespace nr,
|
|
|
|
|
pg_constraint c,
|
2005-07-25 20:04:19 -04:00
|
|
|
pg_class r
|
2002-12-13 19:24:35 -05:00
|
|
|
|
|
|
|
|
WHERE nc.oid = c.connamespace AND nr.oid = r.relnamespace
|
2005-07-25 20:04:19 -04:00
|
|
|
AND c.conrelid = r.oid
|
2010-01-17 17:56:23 -05:00
|
|
|
AND c.contype NOT IN ('t', 'x') -- ignore nonstandard constraints
|
2017-03-10 13:15:47 -05:00
|
|
|
AND r.relkind IN ('r', 'p')
|
2006-09-14 18:05:06 -04:00
|
|
|
AND (NOT pg_is_other_temp_schema(nr.oid))
|
2006-04-02 13:38:13 -04:00
|
|
|
AND (pg_has_role(r.relowner, 'USAGE')
|
|
|
|
|
-- SELECT privilege omitted, per SQL standard
|
2009-02-06 16:15:12 -05:00
|
|
|
OR has_table_privilege(r.oid, 'INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER')
|
|
|
|
|
OR has_any_column_privilege(r.oid, 'INSERT, UPDATE, REFERENCES') )
|
2006-04-02 13:38:13 -04:00
|
|
|
|
2009-02-14 15:48:36 -05:00
|
|
|
UNION ALL
|
2006-04-02 13:38:13 -04:00
|
|
|
|
|
|
|
|
-- not-null constraints
|
|
|
|
|
|
|
|
|
|
SELECT CAST(current_database() AS sql_identifier) AS constraint_catalog,
|
|
|
|
|
CAST(nr.nspname AS sql_identifier) AS constraint_schema,
|
2007-02-27 13:49:43 -05:00
|
|
|
CAST(CAST(nr.oid AS text) || '_' || CAST(r.oid AS text) || '_' || CAST(a.attnum AS text) || '_not_null' AS sql_identifier) AS constraint_name, -- XXX
|
2006-04-02 13:38:13 -04:00
|
|
|
CAST(current_database() AS sql_identifier) AS table_catalog,
|
|
|
|
|
CAST(nr.nspname AS sql_identifier) AS table_schema,
|
|
|
|
|
CAST(r.relname AS sql_identifier) AS table_name,
|
|
|
|
|
CAST('CHECK' AS character_data) AS constraint_type,
|
2009-07-13 16:25:57 -04:00
|
|
|
CAST('NO' AS yes_or_no) AS is_deferrable,
|
2018-02-06 22:43:21 -05:00
|
|
|
CAST('NO' AS yes_or_no) AS initially_deferred,
|
|
|
|
|
CAST('YES' AS yes_or_no) AS enforced
|
2002-12-13 19:24:35 -05:00
|
|
|
|
2006-04-02 13:38:13 -04:00
|
|
|
FROM pg_namespace nr,
|
|
|
|
|
pg_class r,
|
|
|
|
|
pg_attribute a
|
|
|
|
|
|
|
|
|
|
WHERE nr.oid = r.relnamespace
|
|
|
|
|
AND r.oid = a.attrelid
|
|
|
|
|
AND a.attnotnull
|
|
|
|
|
AND a.attnum > 0
|
|
|
|
|
AND NOT a.attisdropped
|
2017-03-10 13:15:47 -05:00
|
|
|
AND r.relkind IN ('r', 'p')
|
2006-09-14 18:05:06 -04:00
|
|
|
AND (NOT pg_is_other_temp_schema(nr.oid))
|
2006-04-02 13:38:13 -04:00
|
|
|
AND (pg_has_role(r.relowner, 'USAGE')
|
2009-02-06 16:15:12 -05:00
|
|
|
-- SELECT privilege omitted, per SQL standard
|
|
|
|
|
OR has_table_privilege(r.oid, 'INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER')
|
|
|
|
|
OR has_any_column_privilege(r.oid, 'INSERT, UPDATE, REFERENCES') );
|
2002-12-13 19:24:35 -05:00
|
|
|
|
|
|
|
|
GRANT SELECT ON table_constraints TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2019-05-14 09:15:05 -04:00
|
|
|
* 5.62
|
2006-04-02 13:38:13 -04:00
|
|
|
* TABLE_METHOD_PRIVILEGES view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
-- feature not supported
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2019-05-14 09:15:05 -04:00
|
|
|
* 5.63
|
2002-12-13 19:24:35 -05:00
|
|
|
* TABLE_PRIVILEGES view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CREATE VIEW table_privileges AS
|
2005-06-28 01:09:14 -04:00
|
|
|
SELECT CAST(u_grantor.rolname AS sql_identifier) AS grantor,
|
2005-07-25 20:04:19 -04:00
|
|
|
CAST(grantee.rolname AS sql_identifier) AS grantee,
|
2002-12-13 19:24:35 -05:00
|
|
|
CAST(current_database() AS sql_identifier) AS table_catalog,
|
|
|
|
|
CAST(nc.nspname AS sql_identifier) AS table_schema,
|
|
|
|
|
CAST(c.relname AS sql_identifier) AS table_name,
|
2009-12-05 16:43:36 -05:00
|
|
|
CAST(c.prtype AS character_data) AS privilege_type,
|
2003-06-11 05:23:55 -04:00
|
|
|
CAST(
|
2009-02-06 16:15:12 -05:00
|
|
|
CASE WHEN
|
|
|
|
|
-- object owner always has grant options
|
|
|
|
|
pg_has_role(grantee.oid, c.relowner, 'USAGE')
|
2009-12-05 16:43:36 -05:00
|
|
|
OR c.grantable
|
2009-07-13 16:25:57 -04:00
|
|
|
THEN 'YES' ELSE 'NO' END AS yes_or_no) AS is_grantable,
|
2011-08-27 08:03:02 -04:00
|
|
|
CAST(CASE WHEN c.prtype = 'SELECT' THEN 'YES' ELSE 'NO' END AS yes_or_no) AS with_hierarchy
|
2002-12-13 19:24:35 -05:00
|
|
|
|
2009-12-05 16:43:36 -05:00
|
|
|
FROM (
|
2012-01-27 14:58:51 -05:00
|
|
|
SELECT oid, relname, relnamespace, relkind, relowner, (aclexplode(coalesce(relacl, acldefault('r', relowner)))).* FROM pg_class
|
2009-12-05 16:43:36 -05:00
|
|
|
) AS c (oid, relname, relnamespace, relkind, relowner, grantor, grantee, prtype, grantable),
|
2002-12-13 19:24:35 -05:00
|
|
|
pg_namespace nc,
|
2005-06-28 01:09:14 -04:00
|
|
|
pg_authid u_grantor,
|
2003-06-29 11:14:41 -04:00
|
|
|
(
|
2005-06-28 01:09:14 -04:00
|
|
|
SELECT oid, rolname FROM pg_authid
|
2003-10-18 08:53:35 -04:00
|
|
|
UNION ALL
|
2005-07-25 20:04:19 -04:00
|
|
|
SELECT 0::oid, 'PUBLIC'
|
2009-12-05 16:43:36 -05:00
|
|
|
) AS grantee (oid, rolname)
|
2002-12-13 19:24:35 -05:00
|
|
|
|
2003-06-11 05:23:55 -04:00
|
|
|
WHERE c.relnamespace = nc.oid
|
2017-08-15 19:27:22 -04:00
|
|
|
AND c.relkind IN ('r', 'v', 'f', 'p')
|
2009-12-05 16:43:36 -05:00
|
|
|
AND c.grantee = grantee.oid
|
|
|
|
|
AND c.grantor = u_grantor.oid
|
|
|
|
|
AND c.prtype IN ('INSERT', 'SELECT', 'UPDATE', 'DELETE', 'TRUNCATE', 'REFERENCES', 'TRIGGER')
|
2006-04-02 13:38:13 -04:00
|
|
|
AND (pg_has_role(u_grantor.oid, 'USAGE')
|
|
|
|
|
OR pg_has_role(grantee.oid, 'USAGE')
|
2005-07-25 20:04:19 -04:00
|
|
|
OR grantee.rolname = 'PUBLIC');
|
2002-12-13 19:24:35 -05:00
|
|
|
|
|
|
|
|
GRANT SELECT ON table_privileges TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
2009-12-05 16:43:36 -05:00
|
|
|
/*
|
2012-07-23 15:31:43 -04:00
|
|
|
* 5.43
|
2009-12-05 16:43:36 -05:00
|
|
|
* ROLE_TABLE_GRANTS view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CREATE VIEW role_table_grants AS
|
|
|
|
|
SELECT grantor,
|
|
|
|
|
grantee,
|
|
|
|
|
table_catalog,
|
|
|
|
|
table_schema,
|
|
|
|
|
table_name,
|
|
|
|
|
privilege_type,
|
|
|
|
|
is_grantable,
|
|
|
|
|
with_hierarchy
|
|
|
|
|
FROM table_privileges
|
|
|
|
|
WHERE grantor IN (SELECT role_name FROM enabled_roles)
|
|
|
|
|
OR grantee IN (SELECT role_name FROM enabled_roles);
|
|
|
|
|
|
|
|
|
|
GRANT SELECT ON role_table_grants TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
2002-12-13 19:24:35 -05:00
|
|
|
/*
|
2012-07-23 15:31:43 -04:00
|
|
|
* 5.63
|
2002-12-13 19:24:35 -05:00
|
|
|
* TABLES view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CREATE VIEW tables AS
|
|
|
|
|
SELECT CAST(current_database() AS sql_identifier) AS table_catalog,
|
|
|
|
|
CAST(nc.nspname AS sql_identifier) AS table_schema,
|
|
|
|
|
CAST(c.relname AS sql_identifier) AS table_name,
|
|
|
|
|
|
|
|
|
|
CAST(
|
2006-09-14 18:05:06 -04:00
|
|
|
CASE WHEN nc.oid = pg_my_temp_schema() THEN 'LOCAL TEMPORARY'
|
2017-03-10 13:15:47 -05:00
|
|
|
WHEN c.relkind IN ('r', 'p') THEN 'BASE TABLE'
|
2002-12-13 19:24:35 -05:00
|
|
|
WHEN c.relkind = 'v' THEN 'VIEW'
|
2017-08-16 11:03:33 -04:00
|
|
|
WHEN c.relkind = 'f' THEN 'FOREIGN'
|
2002-12-13 19:24:35 -05:00
|
|
|
ELSE null END
|
|
|
|
|
AS character_data) AS table_type,
|
|
|
|
|
|
|
|
|
|
CAST(null AS sql_identifier) AS self_referencing_column_name,
|
|
|
|
|
CAST(null AS character_data) AS reference_generation,
|
|
|
|
|
|
2010-01-28 18:21:13 -05:00
|
|
|
CAST(CASE WHEN t.typname IS NOT NULL THEN current_database() ELSE null END AS sql_identifier) AS user_defined_type_catalog,
|
|
|
|
|
CAST(nt.nspname AS sql_identifier) AS user_defined_type_schema,
|
|
|
|
|
CAST(t.typname AS sql_identifier) AS user_defined_type_name,
|
2006-04-02 13:38:13 -04:00
|
|
|
|
2017-03-10 13:15:47 -05:00
|
|
|
CAST(CASE WHEN c.relkind IN ('r', 'p') OR
|
2013-06-12 17:52:54 -04:00
|
|
|
(c.relkind IN ('v', 'f') AND
|
|
|
|
|
-- 1 << CMD_INSERT
|
|
|
|
|
pg_relation_is_updatable(c.oid, false) & 8 = 8)
|
2009-07-13 16:25:57 -04:00
|
|
|
THEN 'YES' ELSE 'NO' END AS yes_or_no) AS is_insertable_into,
|
2009-01-14 16:12:09 -05:00
|
|
|
|
2010-01-28 18:21:13 -05:00
|
|
|
CAST(CASE WHEN t.typname IS NOT NULL THEN 'YES' ELSE 'NO' END AS yes_or_no) AS is_typed,
|
2011-07-15 14:11:14 -04:00
|
|
|
CAST(null AS character_data) AS commit_action
|
2002-12-13 19:24:35 -05:00
|
|
|
|
2010-01-28 18:21:13 -05:00
|
|
|
FROM pg_namespace nc JOIN pg_class c ON (nc.oid = c.relnamespace)
|
|
|
|
|
LEFT JOIN (pg_type t JOIN pg_namespace nt ON (t.typnamespace = nt.oid)) ON (c.reloftype = t.oid)
|
2002-12-13 19:24:35 -05:00
|
|
|
|
2017-03-10 13:15:47 -05:00
|
|
|
WHERE c.relkind IN ('r', 'v', 'f', 'p')
|
2006-09-14 18:05:06 -04:00
|
|
|
AND (NOT pg_is_other_temp_schema(nc.oid))
|
2006-04-02 13:38:13 -04:00
|
|
|
AND (pg_has_role(c.relowner, 'USAGE')
|
2009-02-06 16:15:12 -05:00
|
|
|
OR has_table_privilege(c.oid, 'SELECT, INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER')
|
|
|
|
|
OR has_any_column_privilege(c.oid, 'SELECT, INSERT, UPDATE, REFERENCES') );
|
2002-12-13 19:24:35 -05:00
|
|
|
|
|
|
|
|
GRANT SELECT ON tables TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
2003-06-17 14:00:48 -04:00
|
|
|
/*
|
2019-05-14 09:15:05 -04:00
|
|
|
* 5.65
|
2006-04-02 13:38:13 -04:00
|
|
|
* TRANSFORMS view
|
|
|
|
|
*/
|
|
|
|
|
|
2015-04-26 10:33:14 -04:00
|
|
|
CREATE VIEW transforms AS
|
|
|
|
|
SELECT CAST(current_database() AS sql_identifier) AS udt_catalog,
|
|
|
|
|
CAST(nt.nspname AS sql_identifier) AS udt_schema,
|
|
|
|
|
CAST(t.typname AS sql_identifier) AS udt_name,
|
|
|
|
|
CAST(current_database() AS sql_identifier) AS specific_catalog,
|
|
|
|
|
CAST(np.nspname AS sql_identifier) AS specific_schema,
|
2018-12-20 15:58:58 -05:00
|
|
|
CAST(nameconcatoid(p.proname, p.oid) AS sql_identifier) AS specific_name,
|
2015-04-26 10:33:14 -04:00
|
|
|
CAST(l.lanname AS sql_identifier) AS group_name,
|
|
|
|
|
CAST('FROM SQL' AS character_data) AS transform_type
|
|
|
|
|
FROM pg_type t JOIN pg_transform x ON t.oid = x.trftype
|
|
|
|
|
JOIN pg_language l ON x.trflang = l.oid
|
|
|
|
|
JOIN pg_proc p ON x.trffromsql = p.oid
|
|
|
|
|
JOIN pg_namespace nt ON t.typnamespace = nt.oid
|
|
|
|
|
JOIN pg_namespace np ON p.pronamespace = np.oid
|
|
|
|
|
|
|
|
|
|
UNION
|
|
|
|
|
|
|
|
|
|
SELECT CAST(current_database() AS sql_identifier) AS udt_catalog,
|
|
|
|
|
CAST(nt.nspname AS sql_identifier) AS udt_schema,
|
|
|
|
|
CAST(t.typname AS sql_identifier) AS udt_name,
|
|
|
|
|
CAST(current_database() AS sql_identifier) AS specific_catalog,
|
|
|
|
|
CAST(np.nspname AS sql_identifier) AS specific_schema,
|
2018-12-20 15:58:58 -05:00
|
|
|
CAST(nameconcatoid(p.proname, p.oid) AS sql_identifier) AS specific_name,
|
2015-04-26 10:33:14 -04:00
|
|
|
CAST(l.lanname AS sql_identifier) AS group_name,
|
|
|
|
|
CAST('TO SQL' AS character_data) AS transform_type
|
|
|
|
|
FROM pg_type t JOIN pg_transform x ON t.oid = x.trftype
|
|
|
|
|
JOIN pg_language l ON x.trflang = l.oid
|
|
|
|
|
JOIN pg_proc p ON x.trftosql = p.oid
|
|
|
|
|
JOIN pg_namespace nt ON t.typnamespace = nt.oid
|
|
|
|
|
JOIN pg_namespace np ON p.pronamespace = np.oid
|
|
|
|
|
|
|
|
|
|
ORDER BY udt_catalog, udt_schema, udt_name, group_name, transform_type -- some sensible grouping for interactive use
|
|
|
|
|
;
|
2006-04-02 13:38:13 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2019-05-14 09:15:05 -04:00
|
|
|
* 5.66
|
2006-04-02 13:38:13 -04:00
|
|
|
* TRANSLATIONS view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
-- feature not supported
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2019-05-14 09:15:05 -04:00
|
|
|
* 5.67
|
2003-06-17 14:00:48 -04:00
|
|
|
* TRIGGERED_UPDATE_COLUMNS view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CREATE VIEW triggered_update_columns AS
|
|
|
|
|
SELECT CAST(current_database() AS sql_identifier) AS trigger_catalog,
|
2009-12-31 09:41:23 -05:00
|
|
|
CAST(n.nspname AS sql_identifier) AS trigger_schema,
|
|
|
|
|
CAST(t.tgname AS sql_identifier) AS trigger_name,
|
2003-06-17 14:00:48 -04:00
|
|
|
CAST(current_database() AS sql_identifier) AS event_object_catalog,
|
2009-12-31 09:41:23 -05:00
|
|
|
CAST(n.nspname AS sql_identifier) AS event_object_schema,
|
|
|
|
|
CAST(c.relname AS sql_identifier) AS event_object_table,
|
|
|
|
|
CAST(a.attname AS sql_identifier) AS event_object_column
|
|
|
|
|
|
|
|
|
|
FROM pg_namespace n, pg_class c, pg_trigger t,
|
|
|
|
|
(SELECT tgoid, (ta0.tgat).x AS tgattnum, (ta0.tgat).n AS tgattpos
|
|
|
|
|
FROM (SELECT oid AS tgoid, information_schema._pg_expandarray(tgattr) AS tgat FROM pg_trigger) AS ta0) AS ta,
|
|
|
|
|
pg_attribute a
|
|
|
|
|
|
|
|
|
|
WHERE n.oid = c.relnamespace
|
|
|
|
|
AND c.oid = t.tgrelid
|
|
|
|
|
AND t.oid = ta.tgoid
|
|
|
|
|
AND (a.attrelid, a.attnum) = (t.tgrelid, ta.tgattnum)
|
2010-01-17 17:56:23 -05:00
|
|
|
AND NOT t.tgisinternal
|
2009-12-31 09:41:23 -05:00
|
|
|
AND (NOT pg_is_other_temp_schema(n.oid))
|
|
|
|
|
AND (pg_has_role(c.relowner, 'USAGE')
|
|
|
|
|
-- SELECT privilege omitted, per SQL standard
|
|
|
|
|
OR has_column_privilege(c.oid, a.attnum, 'INSERT, UPDATE, REFERENCES') );
|
2003-06-17 14:00:48 -04:00
|
|
|
|
|
|
|
|
GRANT SELECT ON triggered_update_columns TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2019-05-14 09:15:05 -04:00
|
|
|
* 5.68
|
2006-04-02 13:38:13 -04:00
|
|
|
* TRIGGER_COLUMN_USAGE view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
-- not tracked by PostgreSQL
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2019-05-14 09:15:05 -04:00
|
|
|
* 5.69
|
2012-07-23 15:31:43 -04:00
|
|
|
* TRIGGER_PERIOD_USAGE view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
-- feature not supported
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2019-05-14 09:15:05 -04:00
|
|
|
* 5.70
|
2006-04-02 13:38:13 -04:00
|
|
|
* TRIGGER_ROUTINE_USAGE view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
-- not tracked by PostgreSQL
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2019-05-14 09:15:05 -04:00
|
|
|
* 5.71
|
2006-04-02 13:38:13 -04:00
|
|
|
* TRIGGER_SEQUENCE_USAGE view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
-- not tracked by PostgreSQL
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2019-05-14 09:15:05 -04:00
|
|
|
* 5.72
|
2006-04-02 13:38:13 -04:00
|
|
|
* TRIGGER_TABLE_USAGE view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
-- not tracked by PostgreSQL
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2019-05-14 09:15:05 -04:00
|
|
|
* 5.73
|
2003-06-17 14:00:48 -04:00
|
|
|
* TRIGGERS view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CREATE VIEW triggers AS
|
|
|
|
|
SELECT CAST(current_database() AS sql_identifier) AS trigger_catalog,
|
|
|
|
|
CAST(n.nspname AS sql_identifier) AS trigger_schema,
|
|
|
|
|
CAST(t.tgname AS sql_identifier) AS trigger_name,
|
|
|
|
|
CAST(em.text AS character_data) AS event_manipulation,
|
|
|
|
|
CAST(current_database() AS sql_identifier) AS event_object_catalog,
|
|
|
|
|
CAST(n.nspname AS sql_identifier) AS event_object_schema,
|
|
|
|
|
CAST(c.relname AS sql_identifier) AS event_object_table,
|
2018-02-06 22:43:21 -05:00
|
|
|
CAST(
|
|
|
|
|
-- To determine action order, partition by schema, table,
|
|
|
|
|
-- event_manipulation (INSERT/DELETE/UPDATE), ROW/STATEMENT (1),
|
Repair performance regression in information_schema.triggers view.
Commit 32ff26911 introduced use of rank() into the triggers view to
calculate the spec-mandated action_order column. As written, this
prevents query constraints on the table-name column from being pushed
below the window aggregate step. That's bad for performance of this
typical usage pattern, since the view now has to be evaluated for all
tables not just the one(s) the user wants to see. It's also the cause
of some recent buildfarm failures, in which trying to evaluate the view
rows for triggers in process of being dropped resulted in "cache lookup
failed for function NNN" errors. Those rows aren't of interest to the
test script doing the query, but the filter that would eliminate them
is being applied too late. None of this happened before the rank()
call was there, so it's a regression compared to v10 and before.
We can improve matters by changing the rank() call so that instead of
partitioning by OIDs, it partitions by nspname and relname, casting
those to sql_identifier so that they match the respective view output
columns exactly. The planner has enough intelligence to know that
constraints on partitioning columns are safe to push down, so this
eliminates the performance problem and the regression test failure
risk. We could make the other partitioning columns match view outputs
as well, but it'd be more complicated and the performance benefits
are questionable.
Side note: as this stands, the planner will push down constraints on
event_object_table and trigger_schema, but not on event_object_schema,
because it checks for ressortgroupref matches not expression
equivalence. That might be worth improving someday, but it's not
necessary to fix the immediate concern.
Back-patch to v11 where the rank() call was added. Ordinarily we'd not
change information_schema in released branches, but the test failure has
been seen in v12 and presumably could happen in v11 as well, so we need
to do this to keep the buildfarm happy. The change is harmless so far
as users are concerned. Some might wish to apply it to existing
installations if performance of this type of query is of concern,
but those who don't are no worse off.
I bumped catversion in HEAD as a pro forma matter (there's no
catalog incompatibility that would really require a re-initdb).
Obviously that can't be done in the back branches.
Discussion: https://postgr.es/m/5891.1587594470@sss.pgh.pa.us
2020-04-24 12:02:36 -04:00
|
|
|
-- BEFORE/AFTER (66), then order by trigger name. It's preferable
|
|
|
|
|
-- to partition by view output columns, so that query constraints
|
|
|
|
|
-- can be pushed down below the window function.
|
|
|
|
|
rank() OVER (PARTITION BY CAST(n.nspname AS sql_identifier),
|
|
|
|
|
CAST(c.relname AS sql_identifier),
|
|
|
|
|
em.num,
|
|
|
|
|
t.tgtype & 1,
|
|
|
|
|
t.tgtype & 66
|
|
|
|
|
ORDER BY t.tgname)
|
2018-02-06 22:43:21 -05:00
|
|
|
AS cardinal_number) AS action_order,
|
2009-12-30 17:48:10 -05:00
|
|
|
CAST(
|
|
|
|
|
CASE WHEN pg_has_role(c.relowner, 'USAGE')
|
2019-02-07 03:01:54 -05:00
|
|
|
THEN (regexp_match(pg_get_triggerdef(t.oid), E'.{35,} WHEN \\((.+)\\) EXECUTE FUNCTION'))[1]
|
2009-12-30 17:48:10 -05:00
|
|
|
ELSE null END
|
|
|
|
|
AS character_data) AS action_condition,
|
2003-06-17 14:00:48 -04:00
|
|
|
CAST(
|
|
|
|
|
substring(pg_get_triggerdef(t.oid) from
|
2019-02-07 03:01:54 -05:00
|
|
|
position('EXECUTE FUNCTION' in substring(pg_get_triggerdef(t.oid) from 48)) + 47)
|
2003-06-17 14:00:48 -04:00
|
|
|
AS character_data) AS action_statement,
|
|
|
|
|
CAST(
|
2010-10-10 13:43:33 -04:00
|
|
|
-- hard-wired reference to TRIGGER_TYPE_ROW
|
|
|
|
|
CASE t.tgtype & 1 WHEN 1 THEN 'ROW' ELSE 'STATEMENT' END
|
2003-06-17 14:00:48 -04:00
|
|
|
AS character_data) AS action_orientation,
|
|
|
|
|
CAST(
|
2010-10-10 13:43:33 -04:00
|
|
|
-- hard-wired refs to TRIGGER_TYPE_BEFORE, TRIGGER_TYPE_INSTEAD
|
|
|
|
|
CASE t.tgtype & 66 WHEN 2 THEN 'BEFORE' WHEN 64 THEN 'INSTEAD OF' ELSE 'AFTER' END
|
|
|
|
|
AS character_data) AS action_timing,
|
2018-02-06 22:43:21 -05:00
|
|
|
CAST(tgoldtable AS sql_identifier) AS action_reference_old_table,
|
|
|
|
|
CAST(tgnewtable AS sql_identifier) AS action_reference_new_table,
|
2010-10-10 13:43:33 -04:00
|
|
|
CAST(null AS sql_identifier) AS action_reference_old_row,
|
|
|
|
|
CAST(null AS sql_identifier) AS action_reference_new_row,
|
2006-04-02 13:38:13 -04:00
|
|
|
CAST(null AS time_stamp) AS created
|
2003-06-17 14:00:48 -04:00
|
|
|
|
2005-07-25 20:04:19 -04:00
|
|
|
FROM pg_namespace n, pg_class c, pg_trigger t,
|
2010-10-10 13:43:33 -04:00
|
|
|
-- hard-wired refs to TRIGGER_TYPE_INSERT, TRIGGER_TYPE_DELETE,
|
|
|
|
|
-- TRIGGER_TYPE_UPDATE; we intentionally omit TRIGGER_TYPE_TRUNCATE
|
2009-02-06 16:15:12 -05:00
|
|
|
(VALUES (4, 'INSERT'),
|
|
|
|
|
(8, 'DELETE'),
|
|
|
|
|
(16, 'UPDATE')) AS em (num, text)
|
2003-06-17 14:00:48 -04:00
|
|
|
|
|
|
|
|
WHERE n.oid = c.relnamespace
|
|
|
|
|
AND c.oid = t.tgrelid
|
|
|
|
|
AND t.tgtype & em.num <> 0
|
2010-01-17 17:56:23 -05:00
|
|
|
AND NOT t.tgisinternal
|
2006-09-14 18:05:06 -04:00
|
|
|
AND (NOT pg_is_other_temp_schema(n.oid))
|
2006-04-02 13:38:13 -04:00
|
|
|
AND (pg_has_role(c.relowner, 'USAGE')
|
|
|
|
|
-- SELECT privilege omitted, per SQL standard
|
2009-02-06 16:15:12 -05:00
|
|
|
OR has_table_privilege(c.oid, 'INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER')
|
|
|
|
|
OR has_any_column_privilege(c.oid, 'INSERT, UPDATE, REFERENCES') );
|
2003-06-17 14:00:48 -04:00
|
|
|
|
|
|
|
|
GRANT SELECT ON triggers TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
2002-12-13 19:24:35 -05:00
|
|
|
/*
|
2019-05-14 09:15:05 -04:00
|
|
|
* 5.74
|
2006-04-02 13:38:13 -04:00
|
|
|
* UDT_PRIVILEGES view
|
|
|
|
|
*/
|
|
|
|
|
|
2011-06-23 15:12:46 -04:00
|
|
|
CREATE VIEW udt_privileges AS
|
2011-12-19 17:05:19 -05:00
|
|
|
SELECT CAST(u_grantor.rolname AS sql_identifier) AS grantor,
|
|
|
|
|
CAST(grantee.rolname AS sql_identifier) AS grantee,
|
2011-06-23 15:12:46 -04:00
|
|
|
CAST(current_database() AS sql_identifier) AS udt_catalog,
|
|
|
|
|
CAST(n.nspname AS sql_identifier) AS udt_schema,
|
|
|
|
|
CAST(t.typname AS sql_identifier) AS udt_name,
|
|
|
|
|
CAST('TYPE USAGE' AS character_data) AS privilege_type, -- sic
|
2011-12-19 17:05:19 -05:00
|
|
|
CAST(
|
|
|
|
|
CASE WHEN
|
|
|
|
|
-- object owner always has grant options
|
|
|
|
|
pg_has_role(grantee.oid, t.typowner, 'USAGE')
|
|
|
|
|
OR t.grantable
|
|
|
|
|
THEN 'YES' ELSE 'NO' END AS yes_or_no) AS is_grantable
|
2011-06-23 15:12:46 -04:00
|
|
|
|
2011-12-19 17:05:19 -05:00
|
|
|
FROM (
|
2012-01-27 14:58:51 -05:00
|
|
|
SELECT oid, typname, typnamespace, typtype, typowner, (aclexplode(coalesce(typacl, acldefault('T', typowner)))).* FROM pg_type
|
2011-12-19 17:05:19 -05:00
|
|
|
) AS t (oid, typname, typnamespace, typtype, typowner, grantor, grantee, prtype, grantable),
|
|
|
|
|
pg_namespace n,
|
|
|
|
|
pg_authid u_grantor,
|
|
|
|
|
(
|
|
|
|
|
SELECT oid, rolname FROM pg_authid
|
|
|
|
|
UNION ALL
|
|
|
|
|
SELECT 0::oid, 'PUBLIC'
|
|
|
|
|
) AS grantee (oid, rolname)
|
2011-06-23 15:12:46 -04:00
|
|
|
|
2011-12-19 17:05:19 -05:00
|
|
|
WHERE t.typnamespace = n.oid
|
|
|
|
|
AND t.typtype = 'c'
|
|
|
|
|
AND t.grantee = grantee.oid
|
|
|
|
|
AND t.grantor = u_grantor.oid
|
|
|
|
|
AND t.prtype IN ('USAGE')
|
|
|
|
|
AND (pg_has_role(u_grantor.oid, 'USAGE')
|
|
|
|
|
OR pg_has_role(grantee.oid, 'USAGE')
|
|
|
|
|
OR grantee.rolname = 'PUBLIC');
|
2011-06-23 15:12:46 -04:00
|
|
|
|
|
|
|
|
GRANT SELECT ON udt_privileges TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-07-23 15:31:43 -04:00
|
|
|
* 5.46
|
2011-06-23 15:12:46 -04:00
|
|
|
* ROLE_UDT_GRANTS view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CREATE VIEW role_udt_grants AS
|
|
|
|
|
SELECT grantor,
|
|
|
|
|
grantee,
|
|
|
|
|
udt_catalog,
|
|
|
|
|
udt_schema,
|
|
|
|
|
udt_name,
|
|
|
|
|
privilege_type,
|
|
|
|
|
is_grantable
|
|
|
|
|
FROM udt_privileges
|
|
|
|
|
WHERE grantor IN (SELECT role_name FROM enabled_roles)
|
|
|
|
|
OR grantee IN (SELECT role_name FROM enabled_roles);
|
|
|
|
|
|
|
|
|
|
GRANT SELECT ON role_udt_grants TO PUBLIC;
|
2006-04-02 13:38:13 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2019-05-14 09:15:05 -04:00
|
|
|
* 5.75
|
2002-12-13 19:24:35 -05:00
|
|
|
* USAGE_PRIVILEGES view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CREATE VIEW usage_privileges AS
|
2008-12-19 11:25:19 -05:00
|
|
|
|
2011-03-02 16:10:41 -05:00
|
|
|
/* collations */
|
|
|
|
|
-- Collations have no real privileges, so we represent all collations with implicit usage privilege here.
|
|
|
|
|
SELECT CAST(u.rolname AS sql_identifier) AS grantor,
|
|
|
|
|
CAST('PUBLIC' AS sql_identifier) AS grantee,
|
|
|
|
|
CAST(current_database() AS sql_identifier) AS object_catalog,
|
|
|
|
|
CAST(n.nspname AS sql_identifier) AS object_schema,
|
|
|
|
|
CAST(c.collname AS sql_identifier) AS object_name,
|
|
|
|
|
CAST('COLLATION' AS character_data) AS object_type,
|
|
|
|
|
CAST('USAGE' AS character_data) AS privilege_type,
|
|
|
|
|
CAST('NO' AS yes_or_no) AS is_grantable
|
|
|
|
|
|
|
|
|
|
FROM pg_authid u,
|
|
|
|
|
pg_namespace n,
|
|
|
|
|
pg_collation c
|
|
|
|
|
|
|
|
|
|
WHERE u.oid = c.collowner
|
|
|
|
|
AND c.collnamespace = n.oid
|
2011-03-11 13:20:11 -05:00
|
|
|
AND collencoding IN (-1, (SELECT encoding FROM pg_database WHERE datname = current_database()))
|
2011-03-02 16:10:41 -05:00
|
|
|
|
|
|
|
|
UNION ALL
|
|
|
|
|
|
2008-12-19 11:25:19 -05:00
|
|
|
/* domains */
|
2011-12-19 17:05:19 -05:00
|
|
|
SELECT CAST(u_grantor.rolname AS sql_identifier) AS grantor,
|
|
|
|
|
CAST(grantee.rolname AS sql_identifier) AS grantee,
|
2002-12-13 19:24:35 -05:00
|
|
|
CAST(current_database() AS sql_identifier) AS object_catalog,
|
|
|
|
|
CAST(n.nspname AS sql_identifier) AS object_schema,
|
|
|
|
|
CAST(t.typname AS sql_identifier) AS object_name,
|
|
|
|
|
CAST('DOMAIN' AS character_data) AS object_type,
|
|
|
|
|
CAST('USAGE' AS character_data) AS privilege_type,
|
2011-12-19 17:05:19 -05:00
|
|
|
CAST(
|
|
|
|
|
CASE WHEN
|
|
|
|
|
-- object owner always has grant options
|
|
|
|
|
pg_has_role(grantee.oid, t.typowner, 'USAGE')
|
|
|
|
|
OR t.grantable
|
|
|
|
|
THEN 'YES' ELSE 'NO' END AS yes_or_no) AS is_grantable
|
2002-12-13 19:24:35 -05:00
|
|
|
|
2011-12-19 17:05:19 -05:00
|
|
|
FROM (
|
2012-01-27 14:58:51 -05:00
|
|
|
SELECT oid, typname, typnamespace, typtype, typowner, (aclexplode(coalesce(typacl, acldefault('T', typowner)))).* FROM pg_type
|
2011-12-19 17:05:19 -05:00
|
|
|
) AS t (oid, typname, typnamespace, typtype, typowner, grantor, grantee, prtype, grantable),
|
2002-12-13 19:24:35 -05:00
|
|
|
pg_namespace n,
|
2011-12-19 17:05:19 -05:00
|
|
|
pg_authid u_grantor,
|
|
|
|
|
(
|
|
|
|
|
SELECT oid, rolname FROM pg_authid
|
|
|
|
|
UNION ALL
|
|
|
|
|
SELECT 0::oid, 'PUBLIC'
|
|
|
|
|
) AS grantee (oid, rolname)
|
2002-12-13 19:24:35 -05:00
|
|
|
|
2011-12-19 17:05:19 -05:00
|
|
|
WHERE t.typnamespace = n.oid
|
2008-12-19 11:25:19 -05:00
|
|
|
AND t.typtype = 'd'
|
2011-12-19 17:05:19 -05:00
|
|
|
AND t.grantee = grantee.oid
|
|
|
|
|
AND t.grantor = u_grantor.oid
|
|
|
|
|
AND t.prtype IN ('USAGE')
|
|
|
|
|
AND (pg_has_role(u_grantor.oid, 'USAGE')
|
|
|
|
|
OR pg_has_role(grantee.oid, 'USAGE')
|
|
|
|
|
OR grantee.rolname = 'PUBLIC')
|
2008-12-19 11:25:19 -05:00
|
|
|
|
|
|
|
|
UNION ALL
|
|
|
|
|
|
|
|
|
|
/* foreign-data wrappers */
|
|
|
|
|
SELECT CAST(u_grantor.rolname AS sql_identifier) AS grantor,
|
|
|
|
|
CAST(grantee.rolname AS sql_identifier) AS grantee,
|
|
|
|
|
CAST(current_database() AS sql_identifier) AS object_catalog,
|
|
|
|
|
CAST('' AS sql_identifier) AS object_schema,
|
|
|
|
|
CAST(fdw.fdwname AS sql_identifier) AS object_name,
|
|
|
|
|
CAST('FOREIGN DATA WRAPPER' AS character_data) AS object_type,
|
|
|
|
|
CAST('USAGE' AS character_data) AS privilege_type,
|
|
|
|
|
CAST(
|
2009-02-06 16:15:12 -05:00
|
|
|
CASE WHEN
|
|
|
|
|
-- object owner always has grant options
|
|
|
|
|
pg_has_role(grantee.oid, fdw.fdwowner, 'USAGE')
|
2009-12-05 16:43:36 -05:00
|
|
|
OR fdw.grantable
|
2009-07-13 16:25:57 -04:00
|
|
|
THEN 'YES' ELSE 'NO' END AS yes_or_no) AS is_grantable
|
2008-12-19 11:25:19 -05:00
|
|
|
|
2009-12-05 16:43:36 -05:00
|
|
|
FROM (
|
2012-01-27 14:58:51 -05:00
|
|
|
SELECT fdwname, fdwowner, (aclexplode(coalesce(fdwacl, acldefault('F', fdwowner)))).* FROM pg_foreign_data_wrapper
|
2009-12-05 16:43:36 -05:00
|
|
|
) AS fdw (fdwname, fdwowner, grantor, grantee, prtype, grantable),
|
2008-12-19 11:25:19 -05:00
|
|
|
pg_authid u_grantor,
|
|
|
|
|
(
|
|
|
|
|
SELECT oid, rolname FROM pg_authid
|
|
|
|
|
UNION ALL
|
|
|
|
|
SELECT 0::oid, 'PUBLIC'
|
|
|
|
|
) AS grantee (oid, rolname)
|
|
|
|
|
|
2009-12-05 16:43:36 -05:00
|
|
|
WHERE u_grantor.oid = fdw.grantor
|
|
|
|
|
AND grantee.oid = fdw.grantee
|
|
|
|
|
AND fdw.prtype IN ('USAGE')
|
2008-12-19 11:25:19 -05:00
|
|
|
AND (pg_has_role(u_grantor.oid, 'USAGE')
|
|
|
|
|
OR pg_has_role(grantee.oid, 'USAGE')
|
|
|
|
|
OR grantee.rolname = 'PUBLIC')
|
|
|
|
|
|
|
|
|
|
UNION ALL
|
|
|
|
|
|
|
|
|
|
/* foreign servers */
|
|
|
|
|
SELECT CAST(u_grantor.rolname AS sql_identifier) AS grantor,
|
|
|
|
|
CAST(grantee.rolname AS sql_identifier) AS grantee,
|
|
|
|
|
CAST(current_database() AS sql_identifier) AS object_catalog,
|
|
|
|
|
CAST('' AS sql_identifier) AS object_schema,
|
|
|
|
|
CAST(srv.srvname AS sql_identifier) AS object_name,
|
|
|
|
|
CAST('FOREIGN SERVER' AS character_data) AS object_type,
|
|
|
|
|
CAST('USAGE' AS character_data) AS privilege_type,
|
|
|
|
|
CAST(
|
2009-02-06 16:15:12 -05:00
|
|
|
CASE WHEN
|
|
|
|
|
-- object owner always has grant options
|
|
|
|
|
pg_has_role(grantee.oid, srv.srvowner, 'USAGE')
|
2009-12-05 16:43:36 -05:00
|
|
|
OR srv.grantable
|
2009-07-13 16:25:57 -04:00
|
|
|
THEN 'YES' ELSE 'NO' END AS yes_or_no) AS is_grantable
|
2008-12-19 11:25:19 -05:00
|
|
|
|
2009-12-05 16:43:36 -05:00
|
|
|
FROM (
|
2012-01-27 14:58:51 -05:00
|
|
|
SELECT srvname, srvowner, (aclexplode(coalesce(srvacl, acldefault('S', srvowner)))).* FROM pg_foreign_server
|
2009-12-05 16:43:36 -05:00
|
|
|
) AS srv (srvname, srvowner, grantor, grantee, prtype, grantable),
|
2008-12-19 11:25:19 -05:00
|
|
|
pg_authid u_grantor,
|
|
|
|
|
(
|
|
|
|
|
SELECT oid, rolname FROM pg_authid
|
|
|
|
|
UNION ALL
|
|
|
|
|
SELECT 0::oid, 'PUBLIC'
|
|
|
|
|
) AS grantee (oid, rolname)
|
|
|
|
|
|
2009-12-05 16:43:36 -05:00
|
|
|
WHERE u_grantor.oid = srv.grantor
|
|
|
|
|
AND grantee.oid = srv.grantee
|
|
|
|
|
AND srv.prtype IN ('USAGE')
|
2012-01-30 14:45:42 -05:00
|
|
|
AND (pg_has_role(u_grantor.oid, 'USAGE')
|
|
|
|
|
OR pg_has_role(grantee.oid, 'USAGE')
|
|
|
|
|
OR grantee.rolname = 'PUBLIC')
|
|
|
|
|
|
|
|
|
|
UNION ALL
|
|
|
|
|
|
|
|
|
|
/* sequences */
|
|
|
|
|
SELECT CAST(u_grantor.rolname AS sql_identifier) AS grantor,
|
|
|
|
|
CAST(grantee.rolname AS sql_identifier) AS grantee,
|
|
|
|
|
CAST(current_database() AS sql_identifier) AS object_catalog,
|
|
|
|
|
CAST(n.nspname AS sql_identifier) AS object_schema,
|
|
|
|
|
CAST(c.relname AS sql_identifier) AS object_name,
|
|
|
|
|
CAST('SEQUENCE' AS character_data) AS object_type,
|
|
|
|
|
CAST('USAGE' AS character_data) AS privilege_type,
|
|
|
|
|
CAST(
|
|
|
|
|
CASE WHEN
|
|
|
|
|
-- object owner always has grant options
|
|
|
|
|
pg_has_role(grantee.oid, c.relowner, 'USAGE')
|
|
|
|
|
OR c.grantable
|
|
|
|
|
THEN 'YES' ELSE 'NO' END AS yes_or_no) AS is_grantable
|
|
|
|
|
|
|
|
|
|
FROM (
|
|
|
|
|
SELECT oid, relname, relnamespace, relkind, relowner, (aclexplode(coalesce(relacl, acldefault('r', relowner)))).* FROM pg_class
|
|
|
|
|
) AS c (oid, relname, relnamespace, relkind, relowner, grantor, grantee, prtype, grantable),
|
|
|
|
|
pg_namespace n,
|
|
|
|
|
pg_authid u_grantor,
|
|
|
|
|
(
|
|
|
|
|
SELECT oid, rolname FROM pg_authid
|
|
|
|
|
UNION ALL
|
|
|
|
|
SELECT 0::oid, 'PUBLIC'
|
|
|
|
|
) AS grantee (oid, rolname)
|
|
|
|
|
|
|
|
|
|
WHERE c.relnamespace = n.oid
|
|
|
|
|
AND c.relkind = 'S'
|
|
|
|
|
AND c.grantee = grantee.oid
|
|
|
|
|
AND c.grantor = u_grantor.oid
|
|
|
|
|
AND c.prtype IN ('USAGE')
|
2008-12-19 11:25:19 -05:00
|
|
|
AND (pg_has_role(u_grantor.oid, 'USAGE')
|
|
|
|
|
OR pg_has_role(grantee.oid, 'USAGE')
|
|
|
|
|
OR grantee.rolname = 'PUBLIC');
|
2002-12-13 19:24:35 -05:00
|
|
|
|
|
|
|
|
GRANT SELECT ON usage_privileges TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
2009-12-05 16:43:36 -05:00
|
|
|
/*
|
2012-07-23 15:31:43 -04:00
|
|
|
* 5.45
|
2009-12-05 16:43:36 -05:00
|
|
|
* ROLE_USAGE_GRANTS view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CREATE VIEW role_usage_grants AS
|
|
|
|
|
SELECT grantor,
|
|
|
|
|
grantee,
|
|
|
|
|
object_catalog,
|
|
|
|
|
object_schema,
|
|
|
|
|
object_name,
|
|
|
|
|
object_type,
|
|
|
|
|
privilege_type,
|
|
|
|
|
is_grantable
|
|
|
|
|
FROM usage_privileges
|
|
|
|
|
WHERE grantor IN (SELECT role_name FROM enabled_roles)
|
|
|
|
|
OR grantee IN (SELECT role_name FROM enabled_roles);
|
|
|
|
|
|
|
|
|
|
GRANT SELECT ON role_usage_grants TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
2003-06-17 14:00:48 -04:00
|
|
|
/*
|
2019-05-14 09:15:05 -04:00
|
|
|
* 5.76
|
2006-04-02 13:38:13 -04:00
|
|
|
* USER_DEFINED_TYPES view
|
|
|
|
|
*/
|
|
|
|
|
|
2011-06-23 15:12:46 -04:00
|
|
|
CREATE VIEW user_defined_types AS
|
|
|
|
|
SELECT CAST(current_database() AS sql_identifier) AS user_defined_type_catalog,
|
|
|
|
|
CAST(n.nspname AS sql_identifier) AS user_defined_type_schema,
|
|
|
|
|
CAST(c.relname AS sql_identifier) AS user_defined_type_name,
|
|
|
|
|
CAST('STRUCTURED' AS character_data) AS user_defined_type_category,
|
|
|
|
|
CAST('YES' AS yes_or_no) AS is_instantiable,
|
|
|
|
|
CAST(null AS yes_or_no) AS is_final,
|
|
|
|
|
CAST(null AS character_data) AS ordering_form,
|
|
|
|
|
CAST(null AS character_data) AS ordering_category,
|
|
|
|
|
CAST(null AS sql_identifier) AS ordering_routine_catalog,
|
|
|
|
|
CAST(null AS sql_identifier) AS ordering_routine_schema,
|
|
|
|
|
CAST(null AS sql_identifier) AS ordering_routine_name,
|
|
|
|
|
CAST(null AS character_data) AS reference_type,
|
2011-07-04 16:09:42 -04:00
|
|
|
CAST(null AS character_data) AS data_type,
|
2011-06-23 15:12:46 -04:00
|
|
|
CAST(null AS cardinal_number) AS character_maximum_length,
|
|
|
|
|
CAST(null AS cardinal_number) AS character_octet_length,
|
|
|
|
|
CAST(null AS sql_identifier) AS character_set_catalog,
|
|
|
|
|
CAST(null AS sql_identifier) AS character_set_schema,
|
|
|
|
|
CAST(null AS sql_identifier) AS character_set_name,
|
|
|
|
|
CAST(null AS sql_identifier) AS collation_catalog,
|
|
|
|
|
CAST(null AS sql_identifier) AS collation_schema,
|
|
|
|
|
CAST(null AS sql_identifier) AS collation_name,
|
|
|
|
|
CAST(null AS cardinal_number) AS numeric_precision,
|
|
|
|
|
CAST(null AS cardinal_number) AS numeric_precision_radix,
|
|
|
|
|
CAST(null AS cardinal_number) AS numeric_scale,
|
|
|
|
|
CAST(null AS cardinal_number) AS datetime_precision,
|
|
|
|
|
CAST(null AS character_data) AS interval_type,
|
2011-07-11 11:49:44 -04:00
|
|
|
CAST(null AS cardinal_number) AS interval_precision,
|
2011-06-23 15:12:46 -04:00
|
|
|
CAST(null AS sql_identifier) AS source_dtd_identifier,
|
|
|
|
|
CAST(null AS sql_identifier) AS ref_dtd_identifier
|
|
|
|
|
|
2011-12-19 17:05:19 -05:00
|
|
|
FROM pg_namespace n, pg_class c, pg_type t
|
2011-06-23 15:12:46 -04:00
|
|
|
|
|
|
|
|
WHERE n.oid = c.relnamespace
|
2011-12-19 17:05:19 -05:00
|
|
|
AND t.typrelid = c.oid
|
|
|
|
|
AND c.relkind = 'c'
|
|
|
|
|
AND (pg_has_role(t.typowner, 'USAGE')
|
|
|
|
|
OR has_type_privilege(t.oid, 'USAGE'));
|
2011-06-23 15:12:46 -04:00
|
|
|
|
|
|
|
|
GRANT SELECT ON user_defined_types TO PUBLIC;
|
2006-04-02 13:38:13 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2019-05-14 09:15:05 -04:00
|
|
|
* 5.77
|
2003-06-17 14:00:48 -04:00
|
|
|
* VIEW_COLUMN_USAGE
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CREATE VIEW view_column_usage AS
|
|
|
|
|
SELECT DISTINCT
|
|
|
|
|
CAST(current_database() AS sql_identifier) AS view_catalog,
|
|
|
|
|
CAST(nv.nspname AS sql_identifier) AS view_schema,
|
|
|
|
|
CAST(v.relname AS sql_identifier) AS view_name,
|
|
|
|
|
CAST(current_database() AS sql_identifier) AS table_catalog,
|
|
|
|
|
CAST(nt.nspname AS sql_identifier) AS table_schema,
|
|
|
|
|
CAST(t.relname AS sql_identifier) AS table_name,
|
|
|
|
|
CAST(a.attname AS sql_identifier) AS column_name
|
|
|
|
|
|
2005-07-25 20:04:19 -04:00
|
|
|
FROM pg_namespace nv, pg_class v, pg_depend dv,
|
2003-06-17 14:00:48 -04:00
|
|
|
pg_depend dt, pg_class t, pg_namespace nt,
|
2005-07-25 20:04:19 -04:00
|
|
|
pg_attribute a
|
2003-06-17 14:00:48 -04:00
|
|
|
|
|
|
|
|
WHERE nv.oid = v.relnamespace
|
|
|
|
|
AND v.relkind = 'v'
|
|
|
|
|
AND v.oid = dv.refobjid
|
2003-10-18 08:53:35 -04:00
|
|
|
AND dv.refclassid = 'pg_catalog.pg_class'::regclass
|
|
|
|
|
AND dv.classid = 'pg_catalog.pg_rewrite'::regclass
|
2003-06-17 14:00:48 -04:00
|
|
|
AND dv.deptype = 'i'
|
|
|
|
|
AND dv.objid = dt.objid
|
|
|
|
|
AND dv.refobjid <> dt.refobjid
|
2003-10-18 08:53:35 -04:00
|
|
|
AND dt.classid = 'pg_catalog.pg_rewrite'::regclass
|
|
|
|
|
AND dt.refclassid = 'pg_catalog.pg_class'::regclass
|
2003-06-17 14:00:48 -04:00
|
|
|
AND dt.refobjid = t.oid
|
|
|
|
|
AND t.relnamespace = nt.oid
|
2017-03-10 13:15:47 -05:00
|
|
|
AND t.relkind IN ('r', 'v', 'f', 'p')
|
2003-06-17 14:00:48 -04:00
|
|
|
AND t.oid = a.attrelid
|
|
|
|
|
AND dt.refobjsubid = a.attnum
|
2006-04-02 13:38:13 -04:00
|
|
|
AND pg_has_role(t.relowner, 'USAGE');
|
2003-06-17 14:00:48 -04:00
|
|
|
|
|
|
|
|
GRANT SELECT ON view_column_usage TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2019-05-14 09:15:05 -04:00
|
|
|
* 5.78
|
2012-07-23 15:31:43 -04:00
|
|
|
* VIEW_PERIOD_USAGE
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
-- feature not supported
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2019-05-14 09:15:05 -04:00
|
|
|
* 5.79
|
2006-04-02 13:38:13 -04:00
|
|
|
* VIEW_ROUTINE_USAGE
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CREATE VIEW view_routine_usage AS
|
|
|
|
|
SELECT DISTINCT
|
|
|
|
|
CAST(current_database() AS sql_identifier) AS table_catalog,
|
|
|
|
|
CAST(nv.nspname AS sql_identifier) AS table_schema,
|
|
|
|
|
CAST(v.relname AS sql_identifier) AS table_name,
|
|
|
|
|
CAST(current_database() AS sql_identifier) AS specific_catalog,
|
|
|
|
|
CAST(np.nspname AS sql_identifier) AS specific_schema,
|
2018-12-20 15:58:58 -05:00
|
|
|
CAST(nameconcatoid(p.proname, p.oid) AS sql_identifier) AS specific_name
|
2006-04-02 13:38:13 -04:00
|
|
|
|
|
|
|
|
FROM pg_namespace nv, pg_class v, pg_depend dv,
|
|
|
|
|
pg_depend dp, pg_proc p, pg_namespace np
|
|
|
|
|
|
|
|
|
|
WHERE nv.oid = v.relnamespace
|
|
|
|
|
AND v.relkind = 'v'
|
|
|
|
|
AND v.oid = dv.refobjid
|
|
|
|
|
AND dv.refclassid = 'pg_catalog.pg_class'::regclass
|
|
|
|
|
AND dv.classid = 'pg_catalog.pg_rewrite'::regclass
|
|
|
|
|
AND dv.deptype = 'i'
|
|
|
|
|
AND dv.objid = dp.objid
|
|
|
|
|
AND dp.classid = 'pg_catalog.pg_rewrite'::regclass
|
|
|
|
|
AND dp.refclassid = 'pg_catalog.pg_proc'::regclass
|
|
|
|
|
AND dp.refobjid = p.oid
|
|
|
|
|
AND p.pronamespace = np.oid
|
|
|
|
|
AND pg_has_role(p.proowner, 'USAGE');
|
|
|
|
|
|
|
|
|
|
GRANT SELECT ON view_routine_usage TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2019-05-14 09:15:05 -04:00
|
|
|
* 5.80
|
2003-06-17 14:00:48 -04:00
|
|
|
* VIEW_TABLE_USAGE
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CREATE VIEW view_table_usage AS
|
|
|
|
|
SELECT DISTINCT
|
|
|
|
|
CAST(current_database() AS sql_identifier) AS view_catalog,
|
|
|
|
|
CAST(nv.nspname AS sql_identifier) AS view_schema,
|
|
|
|
|
CAST(v.relname AS sql_identifier) AS view_name,
|
|
|
|
|
CAST(current_database() AS sql_identifier) AS table_catalog,
|
|
|
|
|
CAST(nt.nspname AS sql_identifier) AS table_schema,
|
|
|
|
|
CAST(t.relname AS sql_identifier) AS table_name
|
|
|
|
|
|
2005-07-25 20:04:19 -04:00
|
|
|
FROM pg_namespace nv, pg_class v, pg_depend dv,
|
|
|
|
|
pg_depend dt, pg_class t, pg_namespace nt
|
2003-06-17 14:00:48 -04:00
|
|
|
|
|
|
|
|
WHERE nv.oid = v.relnamespace
|
|
|
|
|
AND v.relkind = 'v'
|
|
|
|
|
AND v.oid = dv.refobjid
|
2003-10-18 08:53:35 -04:00
|
|
|
AND dv.refclassid = 'pg_catalog.pg_class'::regclass
|
|
|
|
|
AND dv.classid = 'pg_catalog.pg_rewrite'::regclass
|
2003-06-17 14:00:48 -04:00
|
|
|
AND dv.deptype = 'i'
|
|
|
|
|
AND dv.objid = dt.objid
|
|
|
|
|
AND dv.refobjid <> dt.refobjid
|
2003-10-18 08:53:35 -04:00
|
|
|
AND dt.classid = 'pg_catalog.pg_rewrite'::regclass
|
|
|
|
|
AND dt.refclassid = 'pg_catalog.pg_class'::regclass
|
2003-06-17 14:00:48 -04:00
|
|
|
AND dt.refobjid = t.oid
|
|
|
|
|
AND t.relnamespace = nt.oid
|
2017-03-10 13:15:47 -05:00
|
|
|
AND t.relkind IN ('r', 'v', 'f', 'p')
|
2006-04-02 13:38:13 -04:00
|
|
|
AND pg_has_role(t.relowner, 'USAGE');
|
2003-06-17 14:00:48 -04:00
|
|
|
|
|
|
|
|
GRANT SELECT ON view_table_usage TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
2002-12-13 19:24:35 -05:00
|
|
|
/*
|
2019-05-14 09:15:05 -04:00
|
|
|
* 5.81
|
2002-12-13 19:24:35 -05:00
|
|
|
* VIEWS view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CREATE VIEW views AS
|
|
|
|
|
SELECT CAST(current_database() AS sql_identifier) AS table_catalog,
|
|
|
|
|
CAST(nc.nspname AS sql_identifier) AS table_schema,
|
|
|
|
|
CAST(c.relname AS sql_identifier) AS table_name,
|
|
|
|
|
|
|
|
|
|
CAST(
|
2006-04-02 13:38:13 -04:00
|
|
|
CASE WHEN pg_has_role(c.relowner, 'USAGE')
|
2005-07-25 20:04:19 -04:00
|
|
|
THEN pg_get_viewdef(c.oid)
|
2002-12-13 19:24:35 -05:00
|
|
|
ELSE null END
|
|
|
|
|
AS character_data) AS view_definition,
|
|
|
|
|
|
2013-07-18 17:10:16 -04:00
|
|
|
CAST(
|
|
|
|
|
CASE WHEN 'check_option=cascaded' = ANY (c.reloptions)
|
|
|
|
|
THEN 'CASCADED'
|
|
|
|
|
WHEN 'check_option=local' = ANY (c.reloptions)
|
|
|
|
|
THEN 'LOCAL'
|
|
|
|
|
ELSE 'NONE' END
|
|
|
|
|
AS character_data) AS check_option,
|
2006-04-02 13:38:13 -04:00
|
|
|
|
|
|
|
|
CAST(
|
2013-06-12 17:52:54 -04:00
|
|
|
-- (1 << CMD_UPDATE) + (1 << CMD_DELETE)
|
|
|
|
|
CASE WHEN pg_relation_is_updatable(c.oid, false) & 20 = 20
|
|
|
|
|
THEN 'YES' ELSE 'NO' END
|
2009-07-13 16:25:57 -04:00
|
|
|
AS yes_or_no) AS is_updatable,
|
2006-04-02 13:38:13 -04:00
|
|
|
|
|
|
|
|
CAST(
|
2013-06-12 17:52:54 -04:00
|
|
|
-- 1 << CMD_INSERT
|
|
|
|
|
CASE WHEN pg_relation_is_updatable(c.oid, false) & 8 = 8
|
|
|
|
|
THEN 'YES' ELSE 'NO' END
|
2009-07-13 16:25:57 -04:00
|
|
|
AS yes_or_no) AS is_insertable_into,
|
|
|
|
|
|
2010-10-10 13:43:33 -04:00
|
|
|
CAST(
|
|
|
|
|
-- TRIGGER_TYPE_ROW + TRIGGER_TYPE_INSTEAD + TRIGGER_TYPE_UPDATE
|
|
|
|
|
CASE WHEN EXISTS (SELECT 1 FROM pg_trigger WHERE tgrelid = c.oid AND tgtype & 81 = 81)
|
|
|
|
|
THEN 'YES' ELSE 'NO' END
|
|
|
|
|
AS yes_or_no) AS is_trigger_updatable,
|
|
|
|
|
|
|
|
|
|
CAST(
|
|
|
|
|
-- TRIGGER_TYPE_ROW + TRIGGER_TYPE_INSTEAD + TRIGGER_TYPE_DELETE
|
|
|
|
|
CASE WHEN EXISTS (SELECT 1 FROM pg_trigger WHERE tgrelid = c.oid AND tgtype & 73 = 73)
|
|
|
|
|
THEN 'YES' ELSE 'NO' END
|
|
|
|
|
AS yes_or_no) AS is_trigger_deletable,
|
|
|
|
|
|
|
|
|
|
CAST(
|
|
|
|
|
-- TRIGGER_TYPE_ROW + TRIGGER_TYPE_INSTEAD + TRIGGER_TYPE_INSERT
|
|
|
|
|
CASE WHEN EXISTS (SELECT 1 FROM pg_trigger WHERE tgrelid = c.oid AND tgtype & 69 = 69)
|
|
|
|
|
THEN 'YES' ELSE 'NO' END
|
|
|
|
|
AS yes_or_no) AS is_trigger_insertable_into
|
2002-12-13 19:24:35 -05:00
|
|
|
|
2005-07-25 20:04:19 -04:00
|
|
|
FROM pg_namespace nc, pg_class c
|
2002-12-13 19:24:35 -05:00
|
|
|
|
2005-07-25 20:04:19 -04:00
|
|
|
WHERE c.relnamespace = nc.oid
|
2003-05-25 05:36:09 -04:00
|
|
|
AND c.relkind = 'v'
|
2006-09-14 18:05:06 -04:00
|
|
|
AND (NOT pg_is_other_temp_schema(nc.oid))
|
2006-04-02 13:38:13 -04:00
|
|
|
AND (pg_has_role(c.relowner, 'USAGE')
|
2009-02-06 16:15:12 -05:00
|
|
|
OR has_table_privilege(c.oid, 'SELECT, INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER')
|
|
|
|
|
OR has_any_column_privilege(c.oid, 'SELECT, INSERT, UPDATE, REFERENCES') );
|
2002-12-13 19:24:35 -05:00
|
|
|
|
|
|
|
|
GRANT SELECT ON views TO PUBLIC;
|
2003-06-28 16:50:08 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
-- The following views have dependencies that force them to appear out of order.
|
|
|
|
|
|
|
|
|
|
/*
|
2012-07-23 15:31:43 -04:00
|
|
|
* 5.25
|
2003-06-28 16:50:08 -04:00
|
|
|
* DATA_TYPE_PRIVILEGES view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CREATE VIEW data_type_privileges AS
|
|
|
|
|
SELECT CAST(current_database() AS sql_identifier) AS object_catalog,
|
|
|
|
|
CAST(x.objschema AS sql_identifier) AS object_schema,
|
|
|
|
|
CAST(x.objname AS sql_identifier) AS object_name,
|
|
|
|
|
CAST(x.objtype AS character_data) AS object_type,
|
|
|
|
|
CAST(x.objdtdid AS sql_identifier) AS dtd_identifier
|
|
|
|
|
|
|
|
|
|
FROM
|
|
|
|
|
(
|
2006-04-02 13:38:13 -04:00
|
|
|
SELECT udt_schema, udt_name, 'USER-DEFINED TYPE'::text, dtd_identifier FROM attributes
|
|
|
|
|
UNION ALL
|
2003-06-28 16:50:08 -04:00
|
|
|
SELECT table_schema, table_name, 'TABLE'::text, dtd_identifier FROM columns
|
2003-10-18 08:53:35 -04:00
|
|
|
UNION ALL
|
2003-06-28 16:50:08 -04:00
|
|
|
SELECT domain_schema, domain_name, 'DOMAIN'::text, dtd_identifier FROM domains
|
2003-10-18 08:53:35 -04:00
|
|
|
UNION ALL
|
2003-06-28 16:50:08 -04:00
|
|
|
SELECT specific_schema, specific_name, 'ROUTINE'::text, dtd_identifier FROM parameters
|
2003-10-18 08:53:35 -04:00
|
|
|
UNION ALL
|
2003-06-28 16:50:08 -04:00
|
|
|
SELECT specific_schema, specific_name, 'ROUTINE'::text, dtd_identifier FROM routines
|
|
|
|
|
) AS x (objschema, objname, objtype, objdtdid);
|
|
|
|
|
|
|
|
|
|
GRANT SELECT ON data_type_privileges TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-07-23 15:31:43 -04:00
|
|
|
* 5.30
|
2003-06-28 16:50:08 -04:00
|
|
|
* ELEMENT_TYPES view
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CREATE VIEW element_types AS
|
|
|
|
|
SELECT CAST(current_database() AS sql_identifier) AS object_catalog,
|
|
|
|
|
CAST(n.nspname AS sql_identifier) AS object_schema,
|
|
|
|
|
CAST(x.objname AS sql_identifier) AS object_name,
|
|
|
|
|
CAST(x.objtype AS character_data) AS object_type,
|
2006-04-02 13:38:13 -04:00
|
|
|
CAST(x.objdtdid AS sql_identifier) AS collection_type_identifier,
|
2003-06-28 16:50:08 -04:00
|
|
|
CAST(
|
|
|
|
|
CASE WHEN nbt.nspname = 'pg_catalog' THEN format_type(bt.oid, null)
|
|
|
|
|
ELSE 'USER-DEFINED' END AS character_data) AS data_type,
|
|
|
|
|
|
|
|
|
|
CAST(null AS cardinal_number) AS character_maximum_length,
|
|
|
|
|
CAST(null AS cardinal_number) AS character_octet_length,
|
|
|
|
|
CAST(null AS sql_identifier) AS character_set_catalog,
|
|
|
|
|
CAST(null AS sql_identifier) AS character_set_schema,
|
|
|
|
|
CAST(null AS sql_identifier) AS character_set_name,
|
2011-06-28 10:49:28 -04:00
|
|
|
CAST(CASE WHEN nco.nspname IS NOT NULL THEN current_database() END AS sql_identifier) AS collation_catalog,
|
|
|
|
|
CAST(nco.nspname AS sql_identifier) AS collation_schema,
|
|
|
|
|
CAST(co.collname AS sql_identifier) AS collation_name,
|
2003-06-28 16:50:08 -04:00
|
|
|
CAST(null AS cardinal_number) AS numeric_precision,
|
|
|
|
|
CAST(null AS cardinal_number) AS numeric_precision_radix,
|
|
|
|
|
CAST(null AS cardinal_number) AS numeric_scale,
|
|
|
|
|
CAST(null AS cardinal_number) AS datetime_precision,
|
|
|
|
|
CAST(null AS character_data) AS interval_type,
|
2011-07-11 11:49:44 -04:00
|
|
|
CAST(null AS cardinal_number) AS interval_precision,
|
2010-11-23 15:27:50 -05:00
|
|
|
|
2003-06-28 16:50:08 -04:00
|
|
|
CAST(null AS character_data) AS domain_default, -- XXX maybe a bug in the standard
|
|
|
|
|
|
|
|
|
|
CAST(current_database() AS sql_identifier) AS udt_catalog,
|
|
|
|
|
CAST(nbt.nspname AS sql_identifier) AS udt_schema,
|
|
|
|
|
CAST(bt.typname AS sql_identifier) AS udt_name,
|
|
|
|
|
|
|
|
|
|
CAST(null AS sql_identifier) AS scope_catalog,
|
|
|
|
|
CAST(null AS sql_identifier) AS scope_schema,
|
|
|
|
|
CAST(null AS sql_identifier) AS scope_name,
|
|
|
|
|
|
|
|
|
|
CAST(null AS cardinal_number) AS maximum_cardinality,
|
2007-02-27 13:49:43 -05:00
|
|
|
CAST('a' || CAST(x.objdtdid AS text) AS sql_identifier) AS dtd_identifier
|
2003-06-28 16:50:08 -04:00
|
|
|
|
|
|
|
|
FROM pg_namespace n, pg_type at, pg_namespace nbt, pg_type bt,
|
|
|
|
|
(
|
2011-06-28 09:07:23 -04:00
|
|
|
/* columns, attributes */
|
2003-10-18 15:06:10 -04:00
|
|
|
SELECT c.relnamespace, CAST(c.relname AS sql_identifier),
|
2011-06-28 09:07:23 -04:00
|
|
|
CASE WHEN c.relkind = 'c' THEN 'USER-DEFINED TYPE'::text ELSE 'TABLE'::text END,
|
2011-06-28 10:49:28 -04:00
|
|
|
a.attnum, a.atttypid, a.attcollation
|
2003-06-28 16:50:08 -04:00
|
|
|
FROM pg_class c, pg_attribute a
|
|
|
|
|
WHERE c.oid = a.attrelid
|
2017-03-10 13:15:47 -05:00
|
|
|
AND c.relkind IN ('r', 'v', 'f', 'c', 'p')
|
2003-06-28 16:50:08 -04:00
|
|
|
AND attnum > 0 AND NOT attisdropped
|
|
|
|
|
|
2003-10-18 08:53:35 -04:00
|
|
|
UNION ALL
|
2003-06-28 16:50:08 -04:00
|
|
|
|
|
|
|
|
/* domains */
|
2003-10-18 15:06:10 -04:00
|
|
|
SELECT t.typnamespace, CAST(t.typname AS sql_identifier),
|
2011-06-28 10:49:28 -04:00
|
|
|
'DOMAIN'::text, 1, t.typbasetype, t.typcollation
|
2003-06-28 16:50:08 -04:00
|
|
|
FROM pg_type t
|
|
|
|
|
WHERE t.typtype = 'd'
|
|
|
|
|
|
2003-10-18 08:53:35 -04:00
|
|
|
UNION ALL
|
2003-06-28 16:50:08 -04:00
|
|
|
|
|
|
|
|
/* parameters */
|
2018-12-20 15:58:58 -05:00
|
|
|
SELECT pronamespace,
|
|
|
|
|
CAST(nameconcatoid(proname, oid) AS sql_identifier),
|
2011-06-28 10:49:28 -04:00
|
|
|
'ROUTINE'::text, (ss.x).n, (ss.x).x, 0
|
2005-03-28 19:17:27 -05:00
|
|
|
FROM (SELECT p.pronamespace, p.proname, p.oid,
|
2005-05-30 23:36:24 -04:00
|
|
|
_pg_expandarray(coalesce(p.proallargtypes, p.proargtypes::oid[])) AS x
|
2005-03-28 19:17:27 -05:00
|
|
|
FROM pg_proc p) AS ss
|
2003-06-28 16:50:08 -04:00
|
|
|
|
2003-10-18 08:53:35 -04:00
|
|
|
UNION ALL
|
2003-06-28 16:50:08 -04:00
|
|
|
|
|
|
|
|
/* result types */
|
2018-12-20 15:58:58 -05:00
|
|
|
SELECT p.pronamespace,
|
|
|
|
|
CAST(nameconcatoid(p.proname, p.oid) AS sql_identifier),
|
2011-06-28 10:49:28 -04:00
|
|
|
'ROUTINE'::text, 0, p.prorettype, 0
|
2003-06-28 16:50:08 -04:00
|
|
|
FROM pg_proc p
|
|
|
|
|
|
2011-06-28 10:49:28 -04:00
|
|
|
) AS x (objschema, objname, objtype, objdtdid, objtypeid, objcollation)
|
|
|
|
|
LEFT JOIN (pg_collation co JOIN pg_namespace nco ON (co.collnamespace = nco.oid))
|
|
|
|
|
ON x.objcollation = co.oid AND (nco.nspname, co.collname) <> ('pg_catalog', 'default')
|
2003-06-28 16:50:08 -04:00
|
|
|
|
|
|
|
|
WHERE n.oid = x.objschema
|
|
|
|
|
AND at.oid = x.objtypeid
|
|
|
|
|
AND (at.typelem <> 0 AND at.typlen = -1)
|
|
|
|
|
AND at.typelem = bt.oid
|
|
|
|
|
AND nbt.oid = bt.typnamespace
|
|
|
|
|
|
2007-02-27 13:49:43 -05:00
|
|
|
AND (n.nspname, x.objname, x.objtype, CAST(x.objdtdid AS sql_identifier)) IN
|
2003-06-28 16:50:08 -04:00
|
|
|
( SELECT object_schema, object_name, object_type, dtd_identifier
|
|
|
|
|
FROM data_type_privileges );
|
|
|
|
|
|
|
|
|
|
GRANT SELECT ON element_types TO PUBLIC;
|
2008-12-19 11:25:19 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
-- SQL/MED views; these use section numbers from part 9 of the standard.
|
|
|
|
|
|
2011-08-05 13:24:03 -04:00
|
|
|
/* Base view for foreign table columns */
|
|
|
|
|
CREATE VIEW _pg_foreign_table_columns AS
|
|
|
|
|
SELECT n.nspname,
|
|
|
|
|
c.relname,
|
|
|
|
|
a.attname,
|
|
|
|
|
a.attfdwoptions
|
|
|
|
|
FROM pg_foreign_table t, pg_authid u, pg_namespace n, pg_class c,
|
|
|
|
|
pg_attribute a
|
|
|
|
|
WHERE u.oid = c.relowner
|
|
|
|
|
AND (pg_has_role(c.relowner, 'USAGE')
|
|
|
|
|
OR has_column_privilege(c.oid, a.attnum, 'SELECT, INSERT, UPDATE, REFERENCES'))
|
|
|
|
|
AND n.oid = c.relnamespace
|
|
|
|
|
AND c.oid = t.ftrelid
|
|
|
|
|
AND c.relkind = 'f'
|
|
|
|
|
AND a.attrelid = c.oid
|
|
|
|
|
AND a.attnum > 0;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 24.2
|
|
|
|
|
* COLUMN_OPTIONS view
|
|
|
|
|
*/
|
|
|
|
|
CREATE VIEW column_options AS
|
|
|
|
|
SELECT CAST(current_database() AS sql_identifier) AS table_catalog,
|
2016-08-03 14:41:01 -04:00
|
|
|
CAST(c.nspname AS sql_identifier) AS table_schema,
|
|
|
|
|
CAST(c.relname AS sql_identifier) AS table_name,
|
|
|
|
|
CAST(c.attname AS sql_identifier) AS column_name,
|
2011-08-05 13:24:03 -04:00
|
|
|
CAST((pg_options_to_table(c.attfdwoptions)).option_name AS sql_identifier) AS option_name,
|
|
|
|
|
CAST((pg_options_to_table(c.attfdwoptions)).option_value AS character_data) AS option_value
|
|
|
|
|
FROM _pg_foreign_table_columns c;
|
|
|
|
|
|
|
|
|
|
GRANT SELECT ON column_options TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
2008-12-19 11:25:19 -05:00
|
|
|
/* Base view for foreign-data wrappers */
|
|
|
|
|
CREATE VIEW _pg_foreign_data_wrappers AS
|
|
|
|
|
SELECT w.oid,
|
|
|
|
|
w.fdwowner,
|
|
|
|
|
w.fdwoptions,
|
|
|
|
|
CAST(current_database() AS sql_identifier) AS foreign_data_wrapper_catalog,
|
|
|
|
|
CAST(fdwname AS sql_identifier) AS foreign_data_wrapper_name,
|
|
|
|
|
CAST(u.rolname AS sql_identifier) AS authorization_identifier,
|
|
|
|
|
CAST('c' AS character_data) AS foreign_data_wrapper_language
|
|
|
|
|
FROM pg_foreign_data_wrapper w, pg_authid u
|
|
|
|
|
WHERE u.oid = w.fdwowner
|
|
|
|
|
AND (pg_has_role(fdwowner, 'USAGE')
|
|
|
|
|
OR has_foreign_data_wrapper_privilege(w.oid, 'USAGE'));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 24.4
|
|
|
|
|
* FOREIGN_DATA_WRAPPER_OPTIONS view
|
|
|
|
|
*/
|
|
|
|
|
CREATE VIEW foreign_data_wrapper_options AS
|
|
|
|
|
SELECT foreign_data_wrapper_catalog,
|
|
|
|
|
foreign_data_wrapper_name,
|
|
|
|
|
CAST((pg_options_to_table(w.fdwoptions)).option_name AS sql_identifier) AS option_name,
|
|
|
|
|
CAST((pg_options_to_table(w.fdwoptions)).option_value AS character_data) AS option_value
|
|
|
|
|
FROM _pg_foreign_data_wrappers w;
|
|
|
|
|
|
|
|
|
|
GRANT SELECT ON foreign_data_wrapper_options TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 24.5
|
|
|
|
|
* FOREIGN_DATA_WRAPPERS view
|
|
|
|
|
*/
|
|
|
|
|
CREATE VIEW foreign_data_wrappers AS
|
|
|
|
|
SELECT foreign_data_wrapper_catalog,
|
|
|
|
|
foreign_data_wrapper_name,
|
|
|
|
|
authorization_identifier,
|
2009-02-24 05:06:36 -05:00
|
|
|
CAST(NULL AS character_data) AS library_name,
|
2008-12-19 11:25:19 -05:00
|
|
|
foreign_data_wrapper_language
|
|
|
|
|
FROM _pg_foreign_data_wrappers w;
|
|
|
|
|
|
|
|
|
|
GRANT SELECT ON foreign_data_wrappers TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Base view for foreign servers */
|
|
|
|
|
CREATE VIEW _pg_foreign_servers AS
|
|
|
|
|
SELECT s.oid,
|
|
|
|
|
s.srvoptions,
|
|
|
|
|
CAST(current_database() AS sql_identifier) AS foreign_server_catalog,
|
|
|
|
|
CAST(srvname AS sql_identifier) AS foreign_server_name,
|
2009-01-20 04:10:20 -05:00
|
|
|
CAST(current_database() AS sql_identifier) AS foreign_data_wrapper_catalog,
|
|
|
|
|
CAST(w.fdwname AS sql_identifier) AS foreign_data_wrapper_name,
|
2008-12-19 11:25:19 -05:00
|
|
|
CAST(srvtype AS character_data) AS foreign_server_type,
|
|
|
|
|
CAST(srvversion AS character_data) AS foreign_server_version,
|
|
|
|
|
CAST(u.rolname AS sql_identifier) AS authorization_identifier
|
2009-01-20 04:10:20 -05:00
|
|
|
FROM pg_foreign_server s, pg_foreign_data_wrapper w, pg_authid u
|
2008-12-19 11:25:19 -05:00
|
|
|
WHERE w.oid = s.srvfdw
|
|
|
|
|
AND u.oid = s.srvowner
|
|
|
|
|
AND (pg_has_role(s.srvowner, 'USAGE')
|
|
|
|
|
OR has_server_privilege(s.oid, 'USAGE'));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 24.6
|
|
|
|
|
* FOREIGN_SERVER_OPTIONS view
|
|
|
|
|
*/
|
|
|
|
|
CREATE VIEW foreign_server_options AS
|
|
|
|
|
SELECT foreign_server_catalog,
|
|
|
|
|
foreign_server_name,
|
|
|
|
|
CAST((pg_options_to_table(s.srvoptions)).option_name AS sql_identifier) AS option_name,
|
|
|
|
|
CAST((pg_options_to_table(s.srvoptions)).option_value AS character_data) AS option_value
|
|
|
|
|
FROM _pg_foreign_servers s;
|
|
|
|
|
|
|
|
|
|
GRANT SELECT ON TABLE foreign_server_options TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 24.7
|
|
|
|
|
* FOREIGN_SERVERS view
|
|
|
|
|
*/
|
|
|
|
|
CREATE VIEW foreign_servers AS
|
|
|
|
|
SELECT foreign_server_catalog,
|
|
|
|
|
foreign_server_name,
|
|
|
|
|
foreign_data_wrapper_catalog,
|
|
|
|
|
foreign_data_wrapper_name,
|
|
|
|
|
foreign_server_type,
|
|
|
|
|
foreign_server_version,
|
|
|
|
|
authorization_identifier
|
|
|
|
|
FROM _pg_foreign_servers;
|
|
|
|
|
|
|
|
|
|
GRANT SELECT ON foreign_servers TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
2011-01-01 23:48:11 -05:00
|
|
|
/* Base view for foreign tables */
|
|
|
|
|
CREATE VIEW _pg_foreign_tables AS
|
|
|
|
|
SELECT
|
|
|
|
|
CAST(current_database() AS sql_identifier) AS foreign_table_catalog,
|
2016-08-03 14:41:01 -04:00
|
|
|
CAST(n.nspname AS sql_identifier) AS foreign_table_schema,
|
|
|
|
|
CAST(c.relname AS sql_identifier) AS foreign_table_name,
|
2011-01-01 23:48:11 -05:00
|
|
|
t.ftoptions AS ftoptions,
|
|
|
|
|
CAST(current_database() AS sql_identifier) AS foreign_server_catalog,
|
|
|
|
|
CAST(srvname AS sql_identifier) AS foreign_server_name,
|
|
|
|
|
CAST(u.rolname AS sql_identifier) AS authorization_identifier
|
|
|
|
|
FROM pg_foreign_table t, pg_foreign_server s, pg_foreign_data_wrapper w,
|
|
|
|
|
pg_authid u, pg_namespace n, pg_class c
|
|
|
|
|
WHERE w.oid = s.srvfdw
|
|
|
|
|
AND u.oid = c.relowner
|
|
|
|
|
AND (pg_has_role(c.relowner, 'USAGE')
|
2011-05-13 15:47:31 -04:00
|
|
|
OR has_table_privilege(c.oid, 'SELECT, INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER')
|
|
|
|
|
OR has_any_column_privilege(c.oid, 'SELECT, INSERT, UPDATE, REFERENCES'))
|
2011-01-01 23:48:11 -05:00
|
|
|
AND n.oid = c.relnamespace
|
|
|
|
|
AND c.oid = t.ftrelid
|
|
|
|
|
AND c.relkind = 'f'
|
|
|
|
|
AND s.oid = t.ftserver;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 24.8
|
|
|
|
|
* FOREIGN_TABLE_OPTIONS view
|
|
|
|
|
*/
|
|
|
|
|
CREATE VIEW foreign_table_options AS
|
|
|
|
|
SELECT foreign_table_catalog,
|
|
|
|
|
foreign_table_schema,
|
|
|
|
|
foreign_table_name,
|
|
|
|
|
CAST((pg_options_to_table(t.ftoptions)).option_name AS sql_identifier) AS option_name,
|
|
|
|
|
CAST((pg_options_to_table(t.ftoptions)).option_value AS character_data) AS option_value
|
|
|
|
|
FROM _pg_foreign_tables t;
|
|
|
|
|
|
|
|
|
|
GRANT SELECT ON TABLE foreign_table_options TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 24.9
|
|
|
|
|
* FOREIGN_TABLES view
|
|
|
|
|
*/
|
|
|
|
|
CREATE VIEW foreign_tables AS
|
|
|
|
|
SELECT foreign_table_catalog,
|
|
|
|
|
foreign_table_schema,
|
|
|
|
|
foreign_table_name,
|
|
|
|
|
foreign_server_catalog,
|
|
|
|
|
foreign_server_name
|
|
|
|
|
FROM _pg_foreign_tables;
|
|
|
|
|
|
|
|
|
|
GRANT SELECT ON foreign_tables TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-12-19 11:25:19 -05:00
|
|
|
/* Base view for user mappings */
|
|
|
|
|
CREATE VIEW _pg_user_mappings AS
|
|
|
|
|
SELECT um.oid,
|
|
|
|
|
um.umoptions,
|
2009-01-20 04:10:20 -05:00
|
|
|
um.umuser,
|
2008-12-19 11:25:19 -05:00
|
|
|
CAST(COALESCE(u.rolname,'PUBLIC') AS sql_identifier ) AS authorization_identifier,
|
|
|
|
|
s.foreign_server_catalog,
|
2009-01-20 04:10:20 -05:00
|
|
|
s.foreign_server_name,
|
|
|
|
|
s.authorization_identifier AS srvowner
|
2008-12-19 11:25:19 -05:00
|
|
|
FROM pg_user_mapping um LEFT JOIN pg_authid u ON (u.oid = um.umuser),
|
|
|
|
|
_pg_foreign_servers s
|
|
|
|
|
WHERE s.oid = um.umserver;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 24.12
|
|
|
|
|
* USER_MAPPING_OPTIONS view
|
|
|
|
|
*/
|
|
|
|
|
CREATE VIEW user_mapping_options AS
|
|
|
|
|
SELECT authorization_identifier,
|
|
|
|
|
foreign_server_catalog,
|
|
|
|
|
foreign_server_name,
|
Disallow set-returning functions inside CASE or COALESCE.
When we reimplemented SRFs in commit 69f4b9c85, our initial choice was
to allow the behavior to vary from historical practice in cases where a
SRF call appeared within a conditional-execution construct (currently,
only CASE or COALESCE). But that was controversial to begin with, and
subsequent discussion has resulted in a consensus that it's better to
throw an error instead of executing the query differently from before,
so long as we can provide a reasonably clear error message and a way to
rewrite the query.
Hence, add a parser mechanism to allow detection of such cases during
parse analysis. The mechanism just requires storing, in the ParseState,
a pointer to the set-returning FuncExpr or OpExpr most recently emitted
by parse analysis. Then the parsing functions for CASE and COALESCE can
detect the presence of a SRF in their arguments by noting whether this
pointer changes while analyzing their arguments. Furthermore, if it does,
it provides a suitable error cursor location for the complaint. (This
means that if there's more than one SRF in the arguments, the error will
point at the last one to be analyzed not the first. While connoisseurs of
parsing behavior might find that odd, it's unlikely the average user would
ever notice.)
While at it, we can also provide more specific error messages than before
about some pre-existing restrictions, such as no-SRFs-within-aggregates.
Also, reject at parse time cases where a NULLIF or IS DISTINCT FROM
construct would need to return a set. We've never supported that, but the
restriction is depended on in more subtle ways now, so it seems wise to
detect it at the start.
Also, provide some documentation about how to rewrite a SRF-within-CASE
query using a custom wrapper SRF.
It turns out that the information_schema.user_mapping_options view
contained an instance of exactly the behavior we're now forbidding; but
rewriting it makes it more clear and safer too.
initdb forced because of user_mapping_options change.
Patch by me, with error message suggestions from Alvaro Herrera and
Andres Freund, pursuant to a complaint from Regina Obe.
Discussion: https://postgr.es/m/000001d2d5de$d8d66170$8a832450$@pcorp.us
2017-06-13 23:46:39 -04:00
|
|
|
CAST(opts.option_name AS sql_identifier) AS option_name,
|
2009-01-20 04:10:20 -05:00
|
|
|
CAST(CASE WHEN (umuser <> 0 AND authorization_identifier = current_user)
|
|
|
|
|
OR (umuser = 0 AND pg_has_role(srvowner, 'USAGE'))
|
Disallow set-returning functions inside CASE or COALESCE.
When we reimplemented SRFs in commit 69f4b9c85, our initial choice was
to allow the behavior to vary from historical practice in cases where a
SRF call appeared within a conditional-execution construct (currently,
only CASE or COALESCE). But that was controversial to begin with, and
subsequent discussion has resulted in a consensus that it's better to
throw an error instead of executing the query differently from before,
so long as we can provide a reasonably clear error message and a way to
rewrite the query.
Hence, add a parser mechanism to allow detection of such cases during
parse analysis. The mechanism just requires storing, in the ParseState,
a pointer to the set-returning FuncExpr or OpExpr most recently emitted
by parse analysis. Then the parsing functions for CASE and COALESCE can
detect the presence of a SRF in their arguments by noting whether this
pointer changes while analyzing their arguments. Furthermore, if it does,
it provides a suitable error cursor location for the complaint. (This
means that if there's more than one SRF in the arguments, the error will
point at the last one to be analyzed not the first. While connoisseurs of
parsing behavior might find that odd, it's unlikely the average user would
ever notice.)
While at it, we can also provide more specific error messages than before
about some pre-existing restrictions, such as no-SRFs-within-aggregates.
Also, reject at parse time cases where a NULLIF or IS DISTINCT FROM
construct would need to return a set. We've never supported that, but the
restriction is depended on in more subtle ways now, so it seems wise to
detect it at the start.
Also, provide some documentation about how to rewrite a SRF-within-CASE
query using a custom wrapper SRF.
It turns out that the information_schema.user_mapping_options view
contained an instance of exactly the behavior we're now forbidding; but
rewriting it makes it more clear and safer too.
initdb forced because of user_mapping_options change.
Patch by me, with error message suggestions from Alvaro Herrera and
Andres Freund, pursuant to a complaint from Regina Obe.
Discussion: https://postgr.es/m/000001d2d5de$d8d66170$8a832450$@pcorp.us
2017-06-13 23:46:39 -04:00
|
|
|
OR (SELECT rolsuper FROM pg_authid WHERE rolname = current_user)
|
|
|
|
|
THEN opts.option_value
|
2009-01-20 04:10:20 -05:00
|
|
|
ELSE NULL END AS character_data) AS option_value
|
Disallow set-returning functions inside CASE or COALESCE.
When we reimplemented SRFs in commit 69f4b9c85, our initial choice was
to allow the behavior to vary from historical practice in cases where a
SRF call appeared within a conditional-execution construct (currently,
only CASE or COALESCE). But that was controversial to begin with, and
subsequent discussion has resulted in a consensus that it's better to
throw an error instead of executing the query differently from before,
so long as we can provide a reasonably clear error message and a way to
rewrite the query.
Hence, add a parser mechanism to allow detection of such cases during
parse analysis. The mechanism just requires storing, in the ParseState,
a pointer to the set-returning FuncExpr or OpExpr most recently emitted
by parse analysis. Then the parsing functions for CASE and COALESCE can
detect the presence of a SRF in their arguments by noting whether this
pointer changes while analyzing their arguments. Furthermore, if it does,
it provides a suitable error cursor location for the complaint. (This
means that if there's more than one SRF in the arguments, the error will
point at the last one to be analyzed not the first. While connoisseurs of
parsing behavior might find that odd, it's unlikely the average user would
ever notice.)
While at it, we can also provide more specific error messages than before
about some pre-existing restrictions, such as no-SRFs-within-aggregates.
Also, reject at parse time cases where a NULLIF or IS DISTINCT FROM
construct would need to return a set. We've never supported that, but the
restriction is depended on in more subtle ways now, so it seems wise to
detect it at the start.
Also, provide some documentation about how to rewrite a SRF-within-CASE
query using a custom wrapper SRF.
It turns out that the information_schema.user_mapping_options view
contained an instance of exactly the behavior we're now forbidding; but
rewriting it makes it more clear and safer too.
initdb forced because of user_mapping_options change.
Patch by me, with error message suggestions from Alvaro Herrera and
Andres Freund, pursuant to a complaint from Regina Obe.
Discussion: https://postgr.es/m/000001d2d5de$d8d66170$8a832450$@pcorp.us
2017-06-13 23:46:39 -04:00
|
|
|
FROM _pg_user_mappings um,
|
|
|
|
|
pg_options_to_table(um.umoptions) opts;
|
2008-12-19 11:25:19 -05:00
|
|
|
|
|
|
|
|
GRANT SELECT ON user_mapping_options TO PUBLIC;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 24.13
|
|
|
|
|
* USER_MAPPINGS view
|
|
|
|
|
*/
|
|
|
|
|
CREATE VIEW user_mappings AS
|
|
|
|
|
SELECT authorization_identifier,
|
|
|
|
|
foreign_server_catalog,
|
|
|
|
|
foreign_server_name
|
|
|
|
|
FROM _pg_user_mappings;
|
|
|
|
|
|
|
|
|
|
GRANT SELECT ON user_mappings TO PUBLIC;
|