diff --git a/doc/src/sgml/information_schema.sgml b/doc/src/sgml/information_schema.sgml index 57d9e1a248..6f3498f3be 100644 --- a/doc/src/sgml/information_schema.sgml +++ b/doc/src/sgml/information_schema.sgml @@ -1,4 +1,4 @@ - + The Information Schema @@ -92,7 +92,7 @@ time_stamp - A domain over the type timestamp + A domain over the type timestamp with time zone @@ -144,15 +144,65 @@ + + <literal>administrable_role_authorizations</literal> + + + The view administrable_role_authorizations + identifies all roles that the current user has the admin option + for. + + + + <literal>administrable_role_authorizations</literal> Columns + + + + + Name + Data Type + Description + + + + + + grantee + sql_identifier + + Name of the role to which this role membership was granted (may + be the current user, or a different role in case of nested role + memberships) + + + + + role_name + sql_identifier + Name of a role + + + + is_grantable + character_data + Always YES + + + +
+
+ <literal>applicable_roles</literal> - The view applicable_roles identifies all groups - that the current user is a member of. (A role is the same thing as - a group.) Generally, it is better to use the view - enabled_roles instead of this one; see also - there. + The view applicable_roles identifies all roles + whose privileges the current user can use. This means there is + some chain of role grants from the current user to the role in + question. The current user itself is also an applicable role. The + set of applicable roles is generally used for permission checking. + applicable role + roleapplicable @@ -171,20 +221,336 @@ grantee sql_identifier - Always the name of the current user + + Name of the role to which this role membership was granted (may + be the current user, or a different role in case of nested role + memberships) + role_name sql_identifier - Name of a group + Name of a role is_grantable character_data + + YES if the grantee has the admin option on + the role, NO if not + + + + +
+
+ + + <literal>attributes</literal> + + + The view attributes contains information about + the attributes of composite data types defined in the database. + (Note that the view does not give information about table columns, + which are sometimes called attributes in PostgreSQL contexts.) + + + + <literal>attributes</literal> Columns + + + + + Name + Data Type + Description + + + + + + udt_catalog + sql_identifier + Name of the database containing the data type (always the current database) + + + + udt_schema + sql_identifier + Name of the schema containing the data type + + + + udt_name + sql_identifier + Name of the data type + + + + attribute_name + sql_identifier + Name of the attribute + + + + ordinal_position + cardinal_number + Ordinal position of the attribute within the data type (count starts at 1) + + + + attribute_default + character_data + Default expression of the attribute + + + + is_nullable + character_data + + YES if the attribute is possibly nullable, + NO if it is known not nullable. + + + + + data_type + character_data + + Data type of the attribute, if it is a built-in type, or + ARRAY if it is some array (in that case, see + the view element_types), else + USER-DEFINED (in that case, the type is + identified in attribute_udt_name and + associated columns). + + + + + character_maximum_length + cardinal_number + + If data_type identifies a character or bit + string type, the declared maximum length; null for all other + data types or if no maximum length was declared. + + + + + character_octet_length + cardinal_number + + If data_type identifies a character type, + the maximum possible length in octets (bytes) of a datum (this + should not be of concern to + PostgreSQL users); null for all + other data types. + + + + + numeric_precision + cardinal_number + + If data_type identifies a numeric type, this + column contains the (declared or implicit) precision of the + type for this attribute. The precision indicates the number of + significant digits. It may be expressed in decimal (base 10) + or binary (base 2) terms, as specified in the column + numeric_precision_radix. For all other data + types, this column is null. + + + + + numeric_precision_radix + cardinal_number + + If data_type identifies a numeric type, this + column indicates in which base the values in the columns + numeric_precision and + numeric_scale are expressed. The value is + either 2 or 10. For all other data types, this column is null. + + + + + numeric_scale + cardinal_number + + If data_type identifies an exact numeric + type, this column contains the (declared or implicit) scale of + the type for this attribute. The scale indicates the number of + significant digits to the right of the decimal point. It may + be expressed in decimal (base 10) or binary (base 2) terms, as + specified in the column + numeric_precision_radix. For all other data + types, this column is null. + + + + + datetime_precision + cardinal_number + + If data_type identifies a date, time, or + interval type, the declared precision; null for all other data + types or if no precision was declared. + + + + + interval_type + character_data + Not yet implemented + + + + interval_precision + character_data + Not yet implemented + + + + attribute_udt_catalog + sql_identifier + + Name of the database that the attribute data type is defined in + (always the current database) + + + + + attribute_udt_schema + sql_identifier + + Name of the schema that the attribute data type is defined in + + + + + attribute_udt_name + sql_identifier + + Name of the attribute data type + + + + + scope_catalog + sql_identifier Applies to a feature not available in PostgreSQL + + + scope_schema + sql_identifier + Applies to a feature not available in PostgreSQL + + + + scope_name + sql_identifier + Applies to a feature not available in PostgreSQL + + + + maximum_cardinality + cardinal_number + Always null, because arrays always have unlimited maximum cardinality in PostgreSQL + + + + dtd_identifier + sql_identifier + + An identifier of the data type descriptor of the column, unique + among the data type descriptors pertaining to the table. This + is mainly useful for joining with other instances of such + identifiers. (The specific format of the identifier is not + defined and not guaranteed to remain the same in future + versions.) + + + + + is_derived_reference_attribute + character_data + Applies to a feature not available in PostgreSQL + + + +
+ + + See also under , a similarly + structured view, for further information on some of the columns. + +
+ + + <literal>check_constraint_routine_usage</literal> + + + The view check_constraint_routine_usage + identifies routines (functions and procedures) that are used by a + check constraint. Only those routines are shown that are owned by + a currently enabled role. + + + + <literal>check_constraint_routine_usage</literal> Columns + + + + + Name + Data Type + Description + + + + + + constraint_catalog + sql_identifier + Name of the database containing the constraint (always the current database) + + + + constraint_schema + sql_identifier + Name of the schema containing the constraint + + + + constraint_name + sql_identifier + Name of the constraint + + + + specific_catalog + sql_identifier + Name of the database containing the function (always the current database) + + + + specific_schema + sql_identifier + Name of the schema containing the function + + + + specific_name + sql_identifier + + The specific name of the function. See for more information. + +
@@ -196,8 +562,8 @@ The view check_constraints contains all check constraints, either defined on a table or on a domain, that are - owned by the current user. (The owner of the table or domain is - the owner of the constraint.) + owned by a currently enabled role. (The owner of the table or + domain is the owner of the constraint.) @@ -247,7 +613,7 @@ The view column_domain_usage identifies all columns (of a table or a view) that make use of some domain defined - in the current database and owned by the current user. + in the current database and owned by a currently enabled role.
@@ -314,10 +680,9 @@ The view column_privileges identifies all - privileges granted on columns to the current user or by the current - user. There is one row for each combination of column, grantor, - and grantee. Privileges granted to groups are identified in the - view role_column_grants. + privileges granted on columns to a currently enabled role or by a + currently enabled role. There is one row for each combination of + column, grantor, and grantee. @@ -351,13 +716,13 @@ grantor sql_identifier - Name of the user that granted the privilege + Name of the role that granted the privilege grantee sql_identifier - Name of the user or group that the privilege was granted to + Name of the role that the privilege was granted to @@ -402,14 +767,6 @@
- - - Note that the column grantee makes no - distinction between users and groups. If you have users and groups - with the same name, there is unfortunately no way to distinguish - them. A future version of PostgreSQL - will possibly prohibit having users and groups with the same name. -
@@ -417,7 +774,7 @@ The view column_udt_usage identifies all columns - that use data types owned by the current user. Note that in + that use data types owned by a currently enabled role. Note that in PostgreSQL, built-in data types behave like user-defined types, so they are included here as well. See also for details. @@ -549,10 +906,7 @@ column_default character_data - - Default expression of the column (null if the current user is - not the owner of the table containing the column) - + Default expression of the column @@ -797,6 +1151,70 @@ character_data Applies to a feature not available in PostgreSQL + + + is_identity + character_data + Applies to a feature not available in PostgreSQL + + + + identity_generation + character_data + Applies to a feature not available in PostgreSQL + + + + identity_start + character_data + Applies to a feature not available in PostgreSQL + + + + identity_increment + character_data + Applies to a feature not available in PostgreSQL + + + + identity_maximum + character_data + Applies to a feature not available in PostgreSQL + + + + identity_minimum + character_data + Applies to a feature not available in PostgreSQL + + + + identity_cycle + character_data + Applies to a feature not available in PostgreSQL + + + + is_generated + character_data + Applies to a feature not available in PostgreSQL + + + + generation_expression + character_data + Applies to a feature not available in PostgreSQL + + + + is_updatable + character_data + + YES if the column is updatable, + NO if not (Columns in base tables are always + updatable, columns in views not necessarily) + + @@ -837,12 +1255,12 @@ The view constraint_column_usage identifies all columns in the current database that are used by some constraint. - Only those columns are shown that are contained in a table owned - the current user. For a check constraint, this view identifies the - columns that are used in the check expression. For a foreign key - constraint, this view identifies the columns that the foreign key - references. For a unique or primary key constraint, this view - identifies the constrained columns. + Only those columns are shown that are contained in a table owned by + a currently enabled role. For a check constraint, this view + identifies the columns that are used in the check expression. For + a foreign key constraint, this view identifies the columns that the + foreign key references. For a unique or primary key constraint, + this view identifies the constrained columns. @@ -922,9 +1340,9 @@ The view constraint_table_usage identifies all tables in the current database that are used by some constraint and - are owned by the current user. (This is different from the view - table_constraints, which identifies all table - constraints along with the table they are defined on.) For a + are owned by a currently enabled role. (This is different from the + view table_constraints, which identifies all + table constraints along with the table they are defined on.) For a foreign key constraint, this view identifies the table that the foreign key references. For a unique or primary key constraint, this view simply identifies the table the constraint belongs to. @@ -1072,7 +1490,7 @@ The view domain_constraints contains all - constraints belonging to domains owned by the current user. + constraints belonging to domains defined in the current database.
@@ -1144,10 +1562,11 @@ <literal>domain_udt_usage</literal> - The view domain_udt_usage identifies all columns - that use data types owned by the current user. Note that in - PostgreSQL, built-in data types behave - like user-defined types, so they are included here as well. + The view domain_udt_usage identifies all domains + that are based on data types owned by a currently enabled role. + Note that in PostgreSQL, built-in data + types behave like user-defined types, so they are included here as + well.
@@ -1695,15 +2114,23 @@ ORDER BY c.ordinal_position; <literal>enabled_roles</literal> - The view enabled_roles identifies all groups - that the current user is a member of. (A role is the same thing as - a group.) The difference between this view and - applicable_roles is that in the future there may - be a mechanism to enable and disable groups during a session. In - that case this view identifies those groups that are currently - enabled. + The view enabled_roles identifies the currently + enabled roles. The enabled roles are recursively + defined as the current user together with all roles that have been + granted to the enabled roles with automatic inheritance. In other + words, these are all roles that the current user has direct or + indirect, automatically inheriting membership in. + enabled role + roleenabled + + For permission checking, the set of applicable roles + is applied, which may be broader than the set of enabled roles. So + generally, it is better to use the view + applicable_roles instead of this one; see also + there. +
<literal>enabled_roles</literal> Columns @@ -1720,7 +2147,7 @@ ORDER BY c.ordinal_position; role_name sql_identifier - Name of a group + Name of a role @@ -1734,8 +2161,8 @@ ORDER BY c.ordinal_position; The view key_column_usage identifies all columns in the current database that are restricted by some unique, primary key, or foreign key constraint. Check constraints are not included - in this view. Only those columns are shown that are contained in a - table owned by the current user. + in this view. Only those columns are shown that the current user + has access to, by way of being the owner or having some privilege.
@@ -1813,6 +2240,14 @@ ORDER BY c.ordinal_position; starts at 1) + + + position_in_unique_constraint + cardinal_number + + Not yet implemented + +
@@ -2069,7 +2504,7 @@ ORDER BY c.ordinal_position; The view referential_constraints contains all referential (foreign key) constraints in the current database that - belong to a table owned by the current user. + belong to a table owned by a currently enabled role. @@ -2172,8 +2607,8 @@ ORDER BY c.ordinal_position; The view role_column_grants identifies all - privileges granted on columns to a group that the current user is a - member of. Further information can be found under + privileges granted on columns where the grantor or grantee is a + currently enabled role. Further information can be found under column_privileges. @@ -2193,13 +2628,13 @@ ORDER BY c.ordinal_position; grantor sql_identifier - Name of the user that granted the privilege + Name of the role that granted the privilege grantee sql_identifier - Name of the group that the privilege was granted to + Name of the role that the privilege was granted to @@ -2251,8 +2686,8 @@ ORDER BY c.ordinal_position; The view role_routine_grants identifies all - privileges granted on functions to a group that the current user is - a member of. Further information can be found under + privileges granted on functions where the grantor or grantee is a + currently enabled role. Further information can be found under routine_privileges. @@ -2272,13 +2707,13 @@ ORDER BY c.ordinal_position; grantor sql_identifier - Name of the user that granted the privilege + Name of the role that granted the privilege grantee sql_identifier - Name of the group that the privilege was granted to + Name of the role that the privilege was granted to @@ -2341,9 +2776,9 @@ ORDER BY c.ordinal_position; The view role_table_grants identifies all - privileges granted on tables or views to a group that the current - user is a member of. Further information can be found under - table_privileges. + privileges granted on tables or views where the grantor or grantee + is a currently enabled role. Further information can be found + under table_privileges.
@@ -2362,13 +2797,13 @@ ORDER BY c.ordinal_position; grantor sql_identifier - Name of the user that granted the privilege + Name of the role that granted the privilege grantee sql_identifier - Name of the group that the privilege was granted to + Name of the role that the privilege was granted to @@ -2422,12 +2857,13 @@ ORDER BY c.ordinal_position; The view role_usage_grants is meant to identify USAGE privileges granted on various kinds of - objects to a group that the current user is a member of. In - PostgreSQL, this currently only applies - to domains, and since domains do not have real privileges in - PostgreSQL, this view is empty. Further - information can be found under usage_privileges. - In the future, this view may contain more useful information. + objects to a currently enabled role or by a currently enabled role. + In PostgreSQL, this currently only + applies to domains, and since domains do not have real privileges + in PostgreSQL, this view is empty. + Further information can be found under + usage_privileges. In the future, this view may + contain more useful information.
@@ -2446,13 +2882,13 @@ ORDER BY c.ordinal_position; grantor sql_identifier - In the future, the name of the user that granted the privilege + In the future, the name of the role that granted the privilege grantee sql_identifier - In the future, the name of the group that the privilege was granted to + In the future, the name of the role that the privilege was granted to @@ -2500,10 +2936,9 @@ ORDER BY c.ordinal_position; The view routine_privileges identifies all - privileges granted on functions to the current user or by the - current user. There is one row for each combination of function, - grantor, and grantee. Privileges granted to groups are identified - in the view role_routine_grants. + privileges granted to a currently enabled role or by a currently + enabled role. There is one row for each combination of function, + grantor, and grantee.
@@ -2522,13 +2957,13 @@ ORDER BY c.ordinal_position; grantor sql_identifier - Name of the user that granted the privilege + Name of the role that granted the privilege grantee sql_identifier - Name of the user or group that the privilege was granted to + Name of the role that the privilege was granted to @@ -2584,14 +3019,6 @@ ORDER BY c.ordinal_position;
- - - Note that the column grantee makes no - distinction between users and groups. If you have users and groups - with the same name, there is unfortunately no way to distinguish - them. A future version of PostgreSQL - will possibly prohibit having users and groups with the same name. -
@@ -2877,8 +3304,8 @@ ORDER BY c.ordinal_position; routine_definition character_data - The source text of the function (null if the current user is - not the owner of the function). (According to the SQL + The source text of the function (null if the function is not + owned by a currently enabled role). (According to the SQL standard, this column is only applicable if routine_body is SQL, but in PostgreSQL it will contain @@ -3012,6 +3439,174 @@ ORDER BY c.ordinal_position; character_data Applies to a feature not available in PostgreSQL + + + created + time_stamp + Applies to a feature not available in PostgreSQL + + + + last_altered + time_stamp + Applies to a feature not available in PostgreSQL + + + + new_savepoint_level + character_data + Applies to a feature not available in PostgreSQL + + + + is_udt_dependent + character_data + Applies to a feature not available in PostgreSQL + + + + result_cast_from_data_type + character_data + Applies to a feature not available in PostgreSQL + + + + result_cast_as_locator + character_data + Applies to a feature not available in PostgreSQL + + + + result_cast_char_max_length + cardinal_number + Applies to a feature not available in PostgreSQL + + + + result_cast_char_octet_length + character_data + Applies to a feature not available in PostgreSQL + + + + result_cast_char_set_catalog + sql_identifier + Applies to a feature not available in PostgreSQL + + + + result_cast_char_set_schema + sql_identifier + Applies to a feature not available in PostgreSQL + + + + result_cast_char_set_name + sql_identifier + Applies to a feature not available in PostgreSQL + + + + result_cast_collation_catalog + sql_identifier + Applies to a feature not available in PostgreSQL + + + + result_cast_collation_schema + sql_identifier + Applies to a feature not available in PostgreSQL + + + + result_cast_collation_name + sql_identifier + Applies to a feature not available in PostgreSQL + + + + result_cast_numeric_precision + cardinal_number + Applies to a feature not available in PostgreSQL + + + + result_cast_numeric_precision_radix + cardinal_number + Applies to a feature not available in PostgreSQL + + + + result_cast_numeric_scale + cardinal_number + Applies to a feature not available in PostgreSQL + + + + result_cast_datetime_precision + character_data + Applies to a feature not available in PostgreSQL + + + + result_cast_interval_type + character_data + Applies to a feature not available in PostgreSQL + + + + result_cast_interval_precision + character_data + Applies to a feature not available in PostgreSQL + + + + result_cast_type_udt_catalog + sql_identifier + Applies to a feature not available in PostgreSQL + + + + result_cast_type_udt_schema + sql_identifier + Applies to a feature not available in PostgreSQL + + + + result_cast_type_udt_name + sql_identifier + Applies to a feature not available in PostgreSQL + + + + result_cast_scope_catalog + sql_identifier + Applies to a feature not available in PostgreSQL + + + + result_cast_scope_schema + sql_identifier + Applies to a feature not available in PostgreSQL + + + + result_cast_scope_name + sql_identifier + Applies to a feature not available in PostgreSQL + + + + result_cast_maximum_cardinality + cardinal_number + Applies to a feature not available in PostgreSQL + + + + result_cast_dtd_identifier + sql_identifier + Applies to a feature not available in PostgreSQL + @@ -3022,7 +3617,7 @@ ORDER BY c.ordinal_position; The view schemata contains all schemas in the - current database that are owned by the current user. + current database that are owned by a currently enabled role. @@ -3084,6 +3679,121 @@ ORDER BY c.ordinal_position;
+ + <literal>sequences</literal> + + + The view sequences contains all sequences + defined in the current database. Only those sequences are shown + that the current user has access to (by way of being the owner or + having some privilege). + + + + <literal>sequences</literal> Columns + + + + + Name + Data Type + Description + + + + + + sequence_catalog + sql_identifier + Name of the database that contains the sequence (always the current database) + + + + sequence_schema + sql_identifier + Name of the schema that contains the sequence + + + + sequence_name + sql_identifier + Name of the sequence + + + + data_type + character_data + + The data type of the sequence. In + PostgreSQL, this is currently always + bigint. + + + + + numeric_precision + cardinal_number + + This column contains the (declared or implicit) precision of + the sequence data type (see above). The precision indicates + the number of significant digits. It may be expressed in + decimal (base 10) or binary (base 2) terms, as specified in the + column numeric_precision_radix. + + + + + numeric_precision_radix + cardinal_number + + This column indicates in which base the values in the columns + numeric_precision and + numeric_scale are expressed. The value is + either 2 or 10. + + + + + numeric_scale + cardinal_number + + This column contains the (declared or implicit) scale of the + sequence data type (see above). The scale indicates the number + of significant digits to the right of the decimal point. It + may be expressed in decimal (base 10) or binary (base 2) terms, + as specified in the column + numeric_precision_radix. + + + + + maximum_value + cardinal_number + Not yet implemented + + + + minimum_value + cardinal_number + Not yet implemented + + + + increment + cardinal_number + Not yet implemented + + + + cycle_option + character_data + Not yet implemented + + + +
+
+ <literal>sql_features</literal> @@ -3379,6 +4089,69 @@ ORDER BY c.ordinal_position; + + <literal>sql_parts</literal> + + + The table sql_parts contains information about + which of the several parts of the SQL standard are supported by + PostgreSQL. + + + + <literal>sql_parts</literal> Columns + + + + + Name + Data Type + Description + + + + + + feature_id + character_data + An identifier string containing the number of the part + + + + feature_name + character_data + Descriptive name of the part + + + + is_supported + character_data + + YES if the part is fully supported by the + current version of PostgreSQL, + NO if not + + + + + is_verified_by + character_data + + Always null, since the PostgreSQL development group does not + perform formal testing of feature conformance + + + + + comments + character_data + Possibly a comment about the supported status of the part + + + +
+
+ <literal>sql_sizing</literal> @@ -3505,7 +4278,8 @@ ORDER BY c.ordinal_position; The view table_constraints contains all - constraints belonging to tables owned by the current user. + constraints belonging to tables that the current user owns or has + some privilege on. @@ -3588,10 +4362,9 @@ ORDER BY c.ordinal_position; The view table_privileges identifies all - privileges granted on tables or views to the current user or by the - current user. There is one row for each combination of table, - grantor, and grantee. Privileges granted to groups are identified - in the view role_table_grants. + privileges granted on tables or views to a currently enabled role + or by a currently enabled role. There is one row for each + combination of table, grantor, and grantee.
@@ -3610,13 +4383,13 @@ ORDER BY c.ordinal_position; grantor sql_identifier - Name of the user that granted the privilege + Name of the role that granted the privilege grantee sql_identifier - Name of the user or group that the privilege was granted to + Name of the role that the privilege was granted to @@ -3662,14 +4435,6 @@ ORDER BY c.ordinal_position;
- - - Note that the column grantee makes no - distinction between users and groups. If you have users and groups - with the same name, there is unfortunately no way to distinguish - them. A future version of PostgreSQL - will possibly prohibit having users and groups with the same name. -
@@ -3753,6 +4518,33 @@ ORDER BY c.ordinal_position; sql_identifier Applies to a feature not available in PostgreSQL + + + is_insertable_into + character_data + + YES if the table is insertable into, + NO if not (Base tables are always insertable + into, views not necessarily.) + + + + + is_typed + character_data + Applies to a feature not available in PostgreSQL + + + + commit_action + character_data + + If the table is a temporary table, then + PRESERVE, else null. (The SQL standard + defines other commit actions for temporary tables, which are + not supported by PostgreSQL.) + + @@ -3763,8 +4555,8 @@ ORDER BY c.ordinal_position; The view triggers contains all triggers defined - in the current database that are owned by the current user. (The - owner of the table is the owner of the trigger.) + in the current database on tables that the current user owns or has + some privilege on. @@ -3880,6 +4672,24 @@ ORDER BY c.ordinal_position; sql_identifierApplies to a feature not available in PostgreSQL + + + condition_reference_old_row + sql_identifier + Applies to a feature not available in PostgreSQL + + + + condition_reference_new_row + sql_identifier + Applies to a feature not available in PostgreSQL + + + + created + time_stamp + Applies to a feature not available in PostgreSQL +
@@ -3917,10 +4727,10 @@ ORDER BY c.ordinal_position; The view usage_privileges is meant to identify USAGE privileges granted on various kinds of - objects to the current user or by the current user. In - PostgreSQL, this currently only applies - to domains, and since domains do not have real privileges in - PostgreSQL, this view shows implicit + objects to a currently enabled role or by a currently enabled role. + In PostgreSQL, this currently only + applies to domains, and since domains do not have real privileges + in PostgreSQL, this view shows implicit USAGE privileges granted to PUBLIC for all domains. In the future, this view may contain more useful information. @@ -3998,8 +4808,8 @@ ORDER BY c.ordinal_position; The view view_column_usage identifies all columns that are used in the query expression of a view (the SELECT statement that defines the view). A - column is only included if the current user is the owner of the - table that contains the column. + column is only included if the table that contains the column is + owned by a currently enabled role. @@ -4077,6 +4887,73 @@ ORDER BY c.ordinal_position;
+ + <literal>view_routine_usage</literal> + + + The view view_routine_usage identifies all + routines (functions and procedures) that are used in the query + expression of a view (the SELECT statement that + defines the view). A routine is only included if that routine is + owned by a currently enabled role. + + + + <literal>view_routine_usage</literal> Columns + + + + + Name + Data Type + Description + + + + + + table_catalog + sql_identifier + Name of the database containing the view (always the current database) + + + + table_schema + sql_identifier + Name of the schema containing the view + + + + table_name + sql_identifier + Name of the view + + + + specific_catalog + sql_identifier + Name of the database containing the function (always the current database) + + + + specific_schema + sql_identifier + Name of the schema containing the function + + + + specific_name + sql_identifier + + The specific name of the function. See for more information. + + + + +
+
+ <literal>view_table_usage</literal> @@ -4084,8 +4961,8 @@ ORDER BY c.ordinal_position; The view view_table_usage identifies all tables that are used in the query expression of a view (the SELECT statement that defines the view). A - table is only included if the current user is the owner of that - table. + table is only included if that table is owned by a currently + enabled role. @@ -4199,8 +5076,8 @@ ORDER BY c.ordinal_position; view definition character_data - Query expression defining the view (null if the current user is - not the owner of the view) + Query expression defining the view (null if the view is not + owned by a currently enabled role) @@ -4213,13 +5090,20 @@ ORDER BY c.ordinal_position; is_updatable character_data - Not yet implemented + + YES if the view is updatable (allows + UPDATE and DELETE), + NO if not + is_insertable_into character_data - Not yet implemented + + YES if the view is insertable into (allows + INSERT), NO if not + diff --git a/src/backend/catalog/information_schema.sql b/src/backend/catalog/information_schema.sql index 9e02d8f31f..0faa3a0cd0 100644 --- a/src/backend/catalog/information_schema.sql +++ b/src/backend/catalog/information_schema.sql @@ -1,10 +1,10 @@ /* * SQL Information Schema - * as defined in ISO 9075-2:1999 chapter 20 + * as defined in ISO/IEC 9075-11:2003 * * Copyright (c) 2003-2006, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/backend/catalog/information_schema.sql,v 1.32 2006/03/05 15:58:22 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/catalog/information_schema.sql,v 1.33 2006/04/02 17:38:13 petere Exp $ */ /* @@ -18,7 +18,7 @@ /* - * 20.2 + * 5.1 * INFORMATION_SCHEMA schema */ @@ -26,6 +26,7 @@ CREATE SCHEMA information_schema; GRANT USAGE ON SCHEMA information_schema TO PUBLIC; SET search_path TO information_schema, public; + /* * A few supporting functions first ... */ @@ -155,11 +156,11 @@ $$SELECT END$$; --- 20.3 INFORMATION_SCHEMA_CATALOG_NAME view appears later. +-- 5.2 INFORMATION_SCHEMA_CATALOG_NAME view appears later. /* - * 20.4 + * 5.3 * CARDINAL_NUMBER domain */ @@ -168,7 +169,7 @@ CREATE DOMAIN cardinal_number AS integer /* - * 20.5 + * 5.4 * CHARACTER_DATA domain */ @@ -176,7 +177,7 @@ CREATE DOMAIN character_data AS character varying; /* - * 20.6 + * 5.5 * SQL_IDENTIFIER domain */ @@ -184,7 +185,7 @@ CREATE DOMAIN sql_identifier AS character varying; /* - * 20.3 + * 5.2 * INFORMATION_SCHEMA_CATALOG_NAME view */ @@ -195,16 +196,19 @@ GRANT SELECT ON information_schema_catalog_name TO PUBLIC; /* - * 20.7 + * 5.6 * TIME_STAMP domain */ -CREATE DOMAIN time_stamp AS timestamp(2) +CREATE DOMAIN time_stamp AS timestamp(2) with time zone DEFAULT current_timestamp(2); +-- 5.7 ADMINISTRABLE_ROLE_AUTHORIZATIONS view appears later. + + /* - * 20.9 + * 5.8 * APPLICABLE_ROLES view */ @@ -215,13 +219,156 @@ CREATE VIEW applicable_roles AS FROM pg_auth_members m JOIN pg_authid a ON (m.member = a.oid) JOIN pg_authid b ON (m.roleid = b.oid) - WHERE pg_has_role(a.oid, 'MEMBER'); + WHERE pg_has_role(a.oid, 'USAGE'); GRANT SELECT ON applicable_roles TO PUBLIC; /* - * 20.13 + * 5.7 + * 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; + + +/* + * 5.9 + * ASSERTIONS view + */ + +-- feature not supported + + +/* + * 5.10 + * 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 + AS character_data) + AS is_nullable, + + 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, + + 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( + _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, + + CAST(null AS character_data) AS interval_type, -- FIXME + CAST(null AS character_data) AS interval_precision, -- FIXME + + 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, + CAST('NO' AS character_data) AS is_derived_reference_attribute + + FROM (pg_attribute a LEFT JOIN pg_attrdef ad ON attrelid = adrelid AND attnum = adnum), + pg_class c, pg_namespace nc, + (pg_type t JOIN pg_namespace nt ON (t.typnamespace = nt.oid)) + + WHERE a.attrelid = c.oid + AND a.atttypid = t.oid + AND nc.oid = c.relnamespace + AND a.attnum > 0 AND NOT a.attisdropped + AND c.relkind in ('c'); + +GRANT SELECT ON attributes TO PUBLIC; + + +/* + * 5.11 + * CHARACTER_SETS view + */ + +-- feature not supported + + +/* + * 5.12 + * CHECK_CONSTRAINT_ROUTINE_USAGE view + */ + +CREATE VIEW check_constraint_routine_usage 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 specific_catalog, + CAST(np.nspname AS sql_identifier) AS specific_schema, + CAST(p.proname || '_' || CAST(p.oid AS text) AS sql_identifier) AS specific_name + 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; + + +/* + * 5.13 * CHECK_CONSTRAINTS view */ @@ -235,14 +382,54 @@ CREATE VIEW check_constraints AS LEFT OUTER JOIN pg_namespace rs ON (rs.oid = con.connamespace) LEFT OUTER JOIN pg_class c ON (c.oid = con.conrelid) LEFT OUTER JOIN pg_type t ON (t.oid = con.contypid) - WHERE pg_has_role(coalesce(c.relowner, t.typowner), 'MEMBER') - AND con.contype = 'c'; + 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, + CAST(n.oid || '_' || r.oid || '_' || a.attnum || '_not_null' AS sql_identifier) AS constraint_name, -- XXX + 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 + AND r.relkind = 'r' + AND pg_has_role(r.relowner, 'USAGE'); GRANT SELECT ON check_constraints TO PUBLIC; /* - * 20.15 + * 5.14 + * COLLATIONS view + */ + +-- feature not supported + +/* + * 5.15 + * COLLATION_CHARACTER_SET_APPLICABILITY view + */ + +-- feature not supported + + +/* + * 5.16 + * COLUMN_COLUMN_USAGE view + */ + +-- feature not supported + + +/* + * 5.17 * COLUMN_DOMAIN_USAGE view */ @@ -266,13 +453,13 @@ CREATE VIEW column_domain_usage AS AND c.relkind IN ('r', 'v') AND a.attnum > 0 AND NOT a.attisdropped - AND pg_has_role(t.typowner, 'MEMBER'); + AND pg_has_role(t.typowner, 'USAGE'); GRANT SELECT ON column_domain_usage TO PUBLIC; /* - * 20.16 + * 5.18 * COLUMN_PRIVILEGES */ @@ -310,15 +497,15 @@ CREATE VIEW column_privileges AS AND c.relkind IN ('r', 'v') AND aclcontains(c.relacl, makeaclitem(grantee.oid, u_grantor.oid, pr.type, false)) - AND (pg_has_role(u_grantor.oid, 'MEMBER') - OR pg_has_role(grantee.oid, 'MEMBER') + AND (pg_has_role(u_grantor.oid, 'USAGE') + OR pg_has_role(grantee.oid, 'USAGE') OR grantee.rolname = 'PUBLIC'); GRANT SELECT ON column_privileges TO PUBLIC; /* - * 20.17 + * 5.19 * COLUMN_UDT_USAGE view */ @@ -340,13 +527,13 @@ CREATE VIEW column_udt_usage AS AND a.atttypid = t.oid AND nc.oid = c.relnamespace AND a.attnum > 0 AND NOT a.attisdropped AND c.relkind in ('r', 'v') - AND pg_has_role(coalesce(bt.typowner, t.typowner), 'MEMBER'); + AND pg_has_role(coalesce(bt.typowner, t.typowner), 'USAGE'); GRANT SELECT ON column_udt_usage TO PUBLIC; /* - * 20.18 + * 5.20 * COLUMNS view */ @@ -356,11 +543,7 @@ CREATE VIEW columns AS 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, - CAST( - CASE WHEN pg_has_role(c.relowner, 'MEMBER') THEN pg_get_expr(ad.adbin, ad.adrelid) - ELSE null END - AS character_data) - AS column_default, + CAST(pg_get_expr(ad.adbin, ad.adrelid) AS character_data) AS column_default, CAST(CASE WHEN a.attnotnull OR (t.typtype = 'd' AND t.typnotnull) THEN 'NO' ELSE 'YES' END AS character_data) AS is_nullable, @@ -408,8 +591,8 @@ CREATE VIEW columns AS AS cardinal_number) AS datetime_precision, - CAST(null AS character_data) AS interval_type, -- XXX - CAST(null AS character_data) AS interval_precision, -- XXX + CAST(null AS character_data) AS interval_type, -- FIXME + CAST(null AS character_data) AS interval_precision, -- FIXME CAST(null AS sql_identifier) AS character_set_catalog, CAST(null AS sql_identifier) AS character_set_schema, @@ -436,7 +619,21 @@ CREATE VIEW columns AS CAST(null AS cardinal_number) AS maximum_cardinality, CAST(a.attnum AS sql_identifier) AS dtd_identifier, - CAST('NO' AS character_data) AS is_self_referencing + CAST('NO' AS character_data) AS is_self_referencing, + + CAST('NO' AS character_data) AS is_identity, + CAST(null AS character_data) AS identity_generation, + CAST(null AS character_data) AS identity_start, + CAST(null AS character_data) AS identity_increment, + CAST(null AS character_data) AS identity_maximum, + CAST(null AS character_data) AS identity_minimum, + CAST(null AS character_data) AS identity_cycle, + + CAST('NEVER' AS character_data) AS is_generated, + CAST(null AS character_data) AS generation_expression, + + CAST(CASE WHEN c.relkind = 'r' + THEN 'YES' ELSE 'NO' END AS character_data) AS is_updatable FROM (pg_attribute a LEFT JOIN pg_attrdef ad ON attrelid = adrelid AND attnum = adnum), pg_class c, pg_namespace nc, @@ -450,7 +647,7 @@ CREATE VIEW columns AS AND a.attnum > 0 AND NOT a.attisdropped AND c.relkind in ('r', 'v') - AND (pg_has_role(c.relowner, 'MEMBER') + AND (pg_has_role(c.relowner, 'USAGE') OR has_table_privilege(c.oid, 'SELECT') OR has_table_privilege(c.oid, 'INSERT') OR has_table_privilege(c.oid, 'UPDATE') @@ -460,7 +657,7 @@ GRANT SELECT ON columns TO PUBLIC; /* - * 20.19 + * 5.21 * CONSTRAINT_COLUMN_USAGE view */ @@ -506,13 +703,13 @@ CREATE VIEW constraint_column_usage AS ) AS x (tblschema, tblname, tblowner, colname, cstrschema, cstrname) - WHERE pg_has_role(x.tblowner, 'MEMBER'); + WHERE pg_has_role(x.tblowner, 'USAGE'); GRANT SELECT ON constraint_column_usage TO PUBLIC; /* - * 20.20 + * 5.22 * CONSTRAINT_TABLE_USAGE view */ @@ -531,16 +728,32 @@ CREATE VIEW constraint_table_usage AS AND ( (c.contype = 'f' AND c.confrelid = r.oid) OR (c.contype IN ('p', 'u') AND c.conrelid = r.oid) ) AND r.relkind = 'r' - AND pg_has_role(r.relowner, 'MEMBER'); + AND pg_has_role(r.relowner, 'USAGE'); GRANT SELECT ON constraint_table_usage TO PUBLIC; --- 20.21 DATA_TYPE_PRIVILEGES view appears later. +-- 5.23 DATA_TYPE_PRIVILEGES view appears later. /* - * 20.24 + * 5.24 + * DIRECT_SUPERTABLES view + */ + +-- feature not supported + + +/* + * 5.25 + * DIRECT_SUPERTYPES view + */ + +-- feature not supported + + +/* + * 5.26 * DOMAIN_CONSTRAINTS view */ @@ -558,15 +771,14 @@ CREATE VIEW domain_constraints AS FROM pg_namespace rs, pg_namespace n, pg_constraint con, pg_type t WHERE rs.oid = con.connamespace AND n.oid = t.typnamespace - AND t.oid = con.contypid - AND pg_has_role(t.typowner, 'MEMBER'); + AND t.oid = con.contypid; GRANT SELECT ON domain_constraints TO PUBLIC; /* - * 20.25 * DOMAIN_UDT_USAGE view + * apparently removed in SQL:2003 */ CREATE VIEW domain_udt_usage AS @@ -584,13 +796,13 @@ CREATE VIEW domain_udt_usage AS AND t.typbasetype = bt.oid AND bt.typnamespace = nbt.oid AND t.typtype = 'd' - AND pg_has_role(bt.typowner, 'MEMBER'); + AND pg_has_role(bt.typowner, 'USAGE'); GRANT SELECT ON domain_udt_usage TO PUBLIC; /* - * 20.26 + * 5.27 * DOMAINS view */ @@ -644,8 +856,8 @@ CREATE VIEW domains AS AS cardinal_number) AS datetime_precision, - CAST(null AS character_data) AS interval_type, -- XXX - CAST(null AS character_data) AS interval_precision, -- XXX + CAST(null AS character_data) AS interval_type, -- FIXME + CAST(null AS character_data) AS interval_precision, -- FIXME CAST(t.typdefault AS character_data) AS domain_default, @@ -671,24 +883,32 @@ CREATE VIEW domains AS GRANT SELECT ON domains TO PUBLIC; --- 20.27 ELEMENT_TYPES view appears later. +-- 5.28 ELEMENT_TYPES view appears later. /* - * 20.28 + * 5.29 * ENABLED_ROLES view */ CREATE VIEW enabled_roles AS SELECT CAST(a.rolname AS sql_identifier) AS role_name FROM pg_authid a - WHERE pg_has_role(a.oid, 'MEMBER'); + WHERE pg_has_role(a.oid, 'USAGE'); GRANT SELECT ON enabled_roles TO PUBLIC; /* - * 20.30 + * 5.30 + * FIELDS view + */ + +-- feature not supported + + +/* + * 5.31 * KEY_COLUMN_USAGE view */ @@ -700,8 +920,8 @@ CREATE VIEW key_column_usage AS CAST(nr_nspname AS sql_identifier) AS table_schema, CAST(relname AS sql_identifier) AS table_name, CAST(a.attname AS sql_identifier) AS column_name, - CAST((ss.x).n AS cardinal_number) AS ordinal_position - + CAST((ss.x).n AS cardinal_number) AS ordinal_position, + CAST(null AS cardinal_number) AS position_in_unique_constraint -- FIXME FROM pg_attribute a, (SELECT r.oid, nc.nspname AS nc_nspname, c.conname, nr.nspname AS nr_nspname, r.relname, @@ -713,7 +933,11 @@ CREATE VIEW key_column_usage AS AND nc.oid = c.connamespace AND c.contype IN ('p', 'u', 'f') AND r.relkind = 'r' - AND pg_has_role(r.relowner, 'MEMBER')) AS ss + AND (pg_has_role(r.relowner, 'USAGE') + OR has_table_privilege(c.oid, 'SELECT') + OR has_table_privilege(c.oid, 'INSERT') + OR has_table_privilege(c.oid, 'UPDATE') + OR has_table_privilege(c.oid, 'REFERENCES')) ) AS ss WHERE ss.oid = a.attrelid AND a.attnum = (ss.x).x AND NOT a.attisdropped; @@ -722,7 +946,23 @@ GRANT SELECT ON key_column_usage TO PUBLIC; /* - * 20.33 + * 5.32 + * METHOD_SPECIFICATION_PARAMETERS view + */ + +-- feature not supported + + +/* + * 5.33 + * METHOD_SPECIFICATIONS view + */ + +-- feature not supported + + +/* + * 5.34 * PARAMETERS view */ @@ -774,7 +1014,7 @@ CREATE VIEW parameters AS _pg_expandarray(coalesce(p.proallargtypes, p.proargtypes::oid[])) AS x FROM pg_namespace n, pg_proc p WHERE n.oid = p.pronamespace - AND (pg_has_role(p.proowner, 'MEMBER') OR + AND (pg_has_role(p.proowner, 'USAGE') OR has_function_privilege(p.oid, 'EXECUTE'))) AS ss WHERE t.oid = (ss.x).x AND t.typnamespace = nt.oid; @@ -782,7 +1022,15 @@ GRANT SELECT ON parameters TO PUBLIC; /* - * 20.35 + * 5.35 + * REFERENCED_TYPES view + */ + +-- feature not supported + + +/* + * 5.36 * REFERENTIAL_CONSTRAINTS view */ @@ -831,13 +1079,13 @@ CREATE VIEW referential_constraints AS WHERE c.relkind = 'r' AND con.contype = 'f' AND (pkc.contype IN ('p', 'u') OR pkc.contype IS NULL) - AND pg_has_role(c.relowner, 'MEMBER'); + AND pg_has_role(c.relowner, 'USAGE'); GRANT SELECT ON referential_constraints TO PUBLIC; /* - * 20.36 + * 5.37 * ROLE_COLUMN_GRANTS view */ @@ -871,13 +1119,14 @@ CREATE VIEW role_column_grants AS AND c.relkind IN ('r', 'v') AND aclcontains(c.relacl, makeaclitem(g_grantee.oid, u_grantor.oid, pr.type, false)) - AND g_grantee.rolname IN (SELECT role_name FROM enabled_roles); + AND (u_grantor.rolname IN (SELECT role_name FROM enabled_roles) + OR g_grantee.rolname IN (SELECT role_name FROM enabled_roles)); GRANT SELECT ON role_column_grants TO PUBLIC; /* - * 20.37 + * 5.38 * ROLE_ROUTINE_GRANTS view */ @@ -904,13 +1153,14 @@ CREATE VIEW role_routine_grants AS WHERE p.pronamespace = n.oid AND aclcontains(p.proacl, makeaclitem(g_grantee.oid, u_grantor.oid, 'EXECUTE', false)) - AND g_grantee.rolname IN (SELECT role_name FROM enabled_roles); + AND (u_grantor.rolname IN (SELECT role_name FROM enabled_roles) + OR g_grantee.rolname IN (SELECT role_name FROM enabled_roles)); GRANT SELECT ON role_routine_grants TO PUBLIC; /* - * 20.38 + * 5.39 * ROLE_TABLE_GRANTS view */ @@ -943,13 +1193,22 @@ CREATE VIEW role_table_grants AS AND c.relkind IN ('r', 'v') AND aclcontains(c.relacl, makeaclitem(g_grantee.oid, u_grantor.oid, pr.type, false)) - AND g_grantee.rolname IN (SELECT role_name FROM enabled_roles); + AND (u_grantor.rolname IN (SELECT role_name FROM enabled_roles) + OR g_grantee.rolname IN (SELECT role_name FROM enabled_roles)); GRANT SELECT ON role_table_grants TO PUBLIC; /* - * 20.40 + * 5.40 + * ROLE_TABLE_METHOD_GRANTS view + */ + +-- feature not supported + + +/* + * 5.41 * ROLE_USAGE_GRANTS view */ @@ -971,7 +1230,23 @@ GRANT SELECT ON role_usage_grants TO PUBLIC; /* - * 20.43 + * 5.42 + * ROLE_UDT_GRANTS view + */ + +-- feature not supported + + +/* + * 5.43 + * ROUTINE_COLUMN_USAGE view + */ + +-- not tracked by PostgreSQL + + +/* + * 5.44 * ROUTINE_PRIVILEGES view */ @@ -1002,15 +1277,39 @@ CREATE VIEW routine_privileges AS WHERE p.pronamespace = n.oid AND aclcontains(p.proacl, makeaclitem(grantee.oid, u_grantor.oid, 'EXECUTE', false)) - AND (pg_has_role(u_grantor.oid, 'MEMBER') - OR pg_has_role(grantee.oid, 'MEMBER') + AND (pg_has_role(u_grantor.oid, 'USAGE') + OR pg_has_role(grantee.oid, 'USAGE') OR grantee.rolname = 'PUBLIC'); GRANT SELECT ON routine_privileges TO PUBLIC; /* - * 20.45 + * 5.45 + * ROUTINE_ROUTINE_USAGE view + */ + +-- not tracked by PostgreSQL + + +/* + * 5.46 + * ROUTINE_SEQUENCE_USAGE view + */ + +-- not tracked by PostgreSQL + + +/* + * 5.47 + * ROUTINE_TABLE_USAGE view + */ + +-- not tracked by PostgreSQL + + +/* + * 5.48 * ROUTINES view */ @@ -1060,7 +1359,7 @@ CREATE VIEW routines AS CAST(CASE WHEN l.lanname = 'sql' THEN 'SQL' ELSE 'EXTERNAL' END AS character_data) AS routine_body, CAST( - CASE WHEN pg_has_role(p.proowner, 'MEMBER') THEN p.prosrc ELSE null END + CASE WHEN pg_has_role(p.proowner, 'USAGE') THEN p.prosrc ELSE null END AS character_data) AS routine_definition, CAST( CASE WHEN l.lanname = 'c' THEN p.prosrc ELSE null END @@ -1080,21 +1379,50 @@ CREATE VIEW routines AS 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, - CAST('NO' AS character_data) AS as_locator + CAST('NO' AS character_data) AS as_locator, + CAST(null AS time_stamp) AS created, + CAST(null AS time_stamp) AS last_altered, + CAST(null AS character_data) AS new_savepoint_level, + CAST('YES' AS character_data) AS is_udt_dependent, -- FIXME? + + CAST(null AS character_data) AS result_cast_from_data_type, + CAST(null AS character_data) AS result_cast_as_locator, + 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, + CAST(null AS sql_identifier) AS result_cast_character_set_name, + 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, + CAST(null AS character_data) AS result_cast_interval_precision, + 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, + CAST(null AS sql_identifier) AS result_cast_dtd_identifier FROM pg_namespace n, pg_proc p, pg_language l, pg_type t, pg_namespace nt WHERE n.oid = p.pronamespace AND p.prolang = l.oid AND p.prorettype = t.oid AND t.typnamespace = nt.oid - AND (pg_has_role(p.proowner, 'MEMBER') + AND (pg_has_role(p.proowner, 'USAGE') OR has_function_privilege(p.oid, 'EXECUTE')); GRANT SELECT ON routines TO PUBLIC; /* - * 20.46 + * 5.49 * SCHEMATA view */ @@ -1107,13 +1435,40 @@ CREATE VIEW schemata AS CAST(null AS sql_identifier) AS default_character_set_name, CAST(null AS character_data) AS sql_path FROM pg_namespace n, pg_authid u - WHERE n.nspowner = u.oid AND pg_has_role(n.nspowner, 'MEMBER'); + WHERE n.nspowner = u.oid AND pg_has_role(n.nspowner, 'USAGE'); GRANT SELECT ON schemata TO PUBLIC; /* - * 20.47 + * 5.50 + * 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, + CAST('bigint' AS character_data) AS data_type, + CAST(64 AS cardinal_number) AS numeric_precision, + CAST(2 AS cardinal_number) AS numeric_precision_radix, + CAST(0 AS cardinal_number) AS numeric_scale, + CAST(null AS cardinal_number) AS maximum_value, -- FIXME + CAST(null AS cardinal_number) AS minimum_value, -- FIXME + CAST(null AS cardinal_number) AS increment, -- FIXME + CAST(null AS character_data) AS cycle_option -- FIXME + FROM pg_namespace nc, pg_class c + WHERE c.relnamespace = nc.oid + AND c.relkind = 's' + AND (pg_has_role(c.relowner, 'USAGE') + OR has_table_privilege(c.oid, 'SELECT') + OR has_table_privilege(c.oid, 'UPDATE') ); + +GRANT SELECT ON sequences TO PUBLIC; + + +/* + * 5.51 * SQL_FEATURES table */ @@ -1133,11 +1488,11 @@ GRANT SELECT ON sql_features TO PUBLIC; /* - * 20.48 + * 5.52 * SQL_IMPLEMENTATION_INFO table */ --- Note: Implementation information items are defined in ISO 9075-3:1999, +-- Note: Implementation information items are defined in ISO/IEC 9075-3:2003, -- clause 7.1. CREATE TABLE sql_implementation_info ( @@ -1165,7 +1520,7 @@ GRANT SELECT ON sql_implementation_info TO PUBLIC; /* - * 20.49 + * 5.53 * SQL_LANGUAGES table */ @@ -1179,6 +1534,8 @@ CREATE TABLE sql_languages ( sql_language_programming_language character_data ) WITHOUT OIDS; +INSERT INTO sql_languages VALUES ('ISO 9075', '1999', 'CORE', NULL, NULL, 'DIRECT', NULL); +INSERT INTO sql_languages VALUES ('ISO 9075', '1999', 'CORE', NULL, NULL, 'EMBEDDED', 'C'); INSERT INTO sql_languages VALUES ('ISO 9075', '2003', 'CORE', NULL, NULL, 'DIRECT', NULL); INSERT INTO sql_languages VALUES ('ISO 9075', '2003', 'CORE', NULL, NULL, 'EMBEDDED', 'C'); @@ -1186,7 +1543,7 @@ GRANT SELECT ON sql_languages TO PUBLIC; /* - * 20.50 + * 5.54 * SQL_PACKAGES table */ @@ -1213,11 +1570,35 @@ GRANT SELECT ON sql_packages TO PUBLIC; /* - * 20.51 + * 5.55 + * SQL_PARTS table + */ + +CREATE TABLE sql_parts ( + feature_id character_data, + feature_name character_data, + is_supported character_data, + is_verified_by character_data, + comments character_data +) WITHOUT OIDS; + +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, ''); +INSERT INTO sql_parts VALUES ('4', 'Persistent Stored Modules (SQL/PSM)', NULL, ''); +INSERT INTO sql_parts VALUES ('9', 'Management of External Data (SQL/MED)', NULL, ''); +INSERT INTO sql_parts VALUES ('10', 'Object Language Bindings (SQL/OLB)', NULL, ''); +INSERT INTO sql_parts VALUES ('11', 'Information and Definition Schema (SQL/Schemata)', NULL, ''); +INSERT INTO sql_parts VALUES ('13', 'Routines and Types Using the Java Programming Language (SQL/JRT)', NULL, ''); +INSERT INTO sql_parts VALUES ('14', 'XML-Related Specifications (SQL/XML)', NULL, ''); + + +/* + * 5.56 * SQL_SIZING table */ --- Note: Sizing items are defined in ISO 9075-3:1999, clause 7.2. +-- Note: Sizing items are defined in ISO/IEC 9075-3:2003, clause 7.2. CREATE TABLE sql_sizing ( sizing_id cardinal_number, @@ -1259,7 +1640,7 @@ GRANT SELECT ON sql_sizing TO PUBLIC; /* - * 20.52 + * 5.57 * SQL_SIZING_PROFILES table */ @@ -1279,7 +1660,7 @@ GRANT SELECT ON sql_sizing_profiles TO PUBLIC; /* - * 20.53 + * 5.58 * TABLE_CONSTRAINTS view */ @@ -1309,15 +1690,61 @@ CREATE VIEW table_constraints AS WHERE nc.oid = c.connamespace AND nr.oid = r.relnamespace AND c.conrelid = r.oid AND r.relkind = 'r' - AND pg_has_role(r.relowner, 'MEMBER'); + AND (pg_has_role(r.relowner, 'USAGE') + -- SELECT privilege omitted, per SQL standard + OR has_table_privilege(r.oid, 'INSERT') + OR has_table_privilege(r.oid, 'UPDATE') + OR has_table_privilege(r.oid, 'DELETE') + OR has_table_privilege(r.oid, 'RULE') + OR has_table_privilege(r.oid, 'REFERENCES') + OR has_table_privilege(r.oid, 'TRIGGER') ) --- FIXME: Not-null constraints are missing here. + UNION + + -- not-null constraints + + SELECT CAST(current_database() AS sql_identifier) AS constraint_catalog, + CAST(nr.nspname AS sql_identifier) AS constraint_schema, + CAST(nr.oid || '_' || r.oid || '_' || a.attnum || '_not_null' AS sql_identifier) AS constraint_name, -- XXX + 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, + CAST('NO' AS character_data) AS is_deferrable, + CAST('NO' AS character_data) AS initially_deferred + + 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 + AND r.relkind = 'r' + AND (pg_has_role(r.relowner, 'USAGE') + OR has_table_privilege(r.oid, 'SELECT') + OR has_table_privilege(r.oid, 'INSERT') + OR has_table_privilege(r.oid, 'UPDATE') + OR has_table_privilege(r.oid, 'DELETE') + OR has_table_privilege(r.oid, 'RULE') + OR has_table_privilege(r.oid, 'REFERENCES') + OR has_table_privilege(r.oid, 'TRIGGER') ); GRANT SELECT ON table_constraints TO PUBLIC; /* - * 20.55 + * 5.59 + * TABLE_METHOD_PRIVILEGES view + */ + +-- feature not supported + + +/* + * 5.60 * TABLE_PRIVILEGES view */ @@ -1354,15 +1781,15 @@ CREATE VIEW table_privileges AS AND c.relkind IN ('r', 'v') AND aclcontains(c.relacl, makeaclitem(grantee.oid, u_grantor.oid, pr.type, false)) - AND (pg_has_role(u_grantor.oid, 'MEMBER') - OR pg_has_role(grantee.oid, 'MEMBER') + AND (pg_has_role(u_grantor.oid, 'USAGE') + OR pg_has_role(grantee.oid, 'USAGE') OR grantee.rolname = 'PUBLIC'); GRANT SELECT ON table_privileges TO PUBLIC; /* - * 20.56 + * 5.61 * TABLES view */ @@ -1383,13 +1810,21 @@ CREATE VIEW tables AS CAST(null AS sql_identifier) AS user_defined_type_catalog, CAST(null AS sql_identifier) AS user_defined_type_schema, - CAST(null AS sql_identifier) AS user_defined_name + CAST(null AS sql_identifier) AS user_defined_type_name, + + CAST(CASE WHEN c.relkind = 'r' + THEN 'YES' ELSE 'NO' END AS character_data) AS is_insertable_into, + CAST('NO' AS character_data) AS is_typed, + CAST( + CASE WHEN nc.nspname LIKE 'pg!_temp!_%' ESCAPE '!' THEN 'PRESERVE' + ELSE null END + AS character_data) AS commit_action FROM pg_namespace nc, pg_class c WHERE c.relnamespace = nc.oid AND c.relkind IN ('r', 'v') - AND (pg_has_role(c.relowner, 'MEMBER') + AND (pg_has_role(c.relowner, 'USAGE') OR has_table_privilege(c.oid, 'SELECT') OR has_table_privilege(c.oid, 'INSERT') OR has_table_privilege(c.oid, 'UPDATE') @@ -1402,7 +1837,23 @@ GRANT SELECT ON tables TO PUBLIC; /* - * 20.59 + * 5.62 + * TRANSFORMS view + */ + +-- feature not supported + + +/* + * 5.63 + * TRANSLATIONS view + */ + +-- feature not supported + + +/* + * 5.64 * TRIGGERED_UPDATE_COLUMNS view */ @@ -1423,7 +1874,39 @@ GRANT SELECT ON triggered_update_columns TO PUBLIC; /* - * 20.62 + * 5.65 + * TRIGGER_COLUMN_USAGE view + */ + +-- not tracked by PostgreSQL + + +/* + * 5.66 + * TRIGGER_ROUTINE_USAGE view + */ + +-- not tracked by PostgreSQL + + +/* + * 5.67 + * TRIGGER_SEQUENCE_USAGE view + */ + +-- not tracked by PostgreSQL + + +/* + * 5.68 + * TRIGGER_TABLE_USAGE view + */ + +-- not tracked by PostgreSQL + + +/* + * 5.69 * TRIGGERS view */ @@ -1448,7 +1931,10 @@ CREATE VIEW triggers AS CASE WHEN t.tgtype & 2 = 2 THEN 'BEFORE' ELSE 'AFTER' END AS character_data) AS condition_timing, CAST(null AS sql_identifier) AS condition_reference_old_table, - CAST(null AS sql_identifier) AS condition_reference_new_table + CAST(null AS sql_identifier) AS condition_reference_new_table, + CAST(null AS sql_identifier) AS condition_reference_old_row, + CAST(null AS sql_identifier) AS condition_reference_new_row, + CAST(null AS time_stamp) AS created FROM pg_namespace n, pg_class c, pg_trigger t, (SELECT 4, 'INSERT' UNION ALL @@ -1459,13 +1945,28 @@ CREATE VIEW triggers AS AND c.oid = t.tgrelid AND t.tgtype & em.num <> 0 AND NOT t.tgisconstraint - AND pg_has_role(c.relowner, 'MEMBER'); + AND (pg_has_role(c.relowner, 'USAGE') + -- SELECT privilege omitted, per SQL standard + OR has_table_privilege(c.oid, 'INSERT') + OR has_table_privilege(c.oid, 'UPDATE') + OR has_table_privilege(c.oid, 'DELETE') + OR has_table_privilege(c.oid, 'RULE') + OR has_table_privilege(c.oid, 'REFERENCES') + OR has_table_privilege(c.oid, 'TRIGGER') ); GRANT SELECT ON triggers TO PUBLIC; /* - * 20.63 + * 5.70 + * UDT_PRIVILEGES view + */ + +-- feature not supported + + +/* + * 5.71 * USAGE_PRIVILEGES view */ @@ -1495,7 +1996,15 @@ GRANT SELECT ON usage_privileges TO PUBLIC; /* - * 20.65 + * 5.72 + * USER_DEFINED_TYPES view + */ + +-- feature not supported + + +/* + * 5.73 * VIEW_COLUMN_USAGE */ @@ -1528,13 +2037,46 @@ CREATE VIEW view_column_usage AS AND t.relkind IN ('r', 'v') AND t.oid = a.attrelid AND dt.refobjsubid = a.attnum - AND pg_has_role(t.relowner, 'MEMBER'); + AND pg_has_role(t.relowner, 'USAGE'); GRANT SELECT ON view_column_usage TO PUBLIC; /* - * 20.66 + * 5.74 + * 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, + CAST(p.proname || '_' || CAST(p.oid AS text) AS sql_identifier) AS specific_name + + 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; + + +/* + * 5.75 * VIEW_TABLE_USAGE */ @@ -1563,13 +2105,13 @@ CREATE VIEW view_table_usage AS AND dt.refobjid = t.oid AND t.relnamespace = nt.oid AND t.relkind IN ('r', 'v') - AND pg_has_role(t.relowner, 'MEMBER'); + AND pg_has_role(t.relowner, 'USAGE'); GRANT SELECT ON view_table_usage TO PUBLIC; /* - * 20.68 + * 5.76 * VIEWS view */ @@ -1579,20 +2121,29 @@ CREATE VIEW views AS CAST(c.relname AS sql_identifier) AS table_name, CAST( - CASE WHEN pg_has_role(c.relowner, 'MEMBER') + CASE WHEN pg_has_role(c.relowner, 'USAGE') THEN pg_get_viewdef(c.oid) ELSE null END AS character_data) AS view_definition, CAST('NONE' AS character_data) AS check_option, - CAST(null AS character_data) AS is_updatable, -- FIXME - CAST(null AS character_data) AS is_insertable_into -- FIXME + + CAST( + CASE WHEN EXISTS (SELECT 1 FROM pg_rewrite WHERE ev_class = c.oid AND ev_type = 2 AND is_instead) + AND EXISTS (SELECT 1 FROM pg_rewrite WHERE ev_class = c.oid AND ev_type = 4 AND is_instead) + THEN 'YES' ELSE 'NO' END + AS character_data) AS is_updatable, + + CAST( + CASE WHEN EXISTS (SELECT 1 FROM pg_rewrite WHERE ev_class = c.oid AND ev_type = 3 AND is_instead) + THEN 'YES' ELSE 'NO' END + AS character_data) AS is_insertable_into FROM pg_namespace nc, pg_class c WHERE c.relnamespace = nc.oid AND c.relkind = 'v' - AND (pg_has_role(c.relowner, 'MEMBER') + AND (pg_has_role(c.relowner, 'USAGE') OR has_table_privilege(c.oid, 'SELECT') OR has_table_privilege(c.oid, 'INSERT') OR has_table_privilege(c.oid, 'UPDATE') @@ -1607,7 +2158,7 @@ GRANT SELECT ON views TO PUBLIC; -- The following views have dependencies that force them to appear out of order. /* - * 20.21 + * 5.23 * DATA_TYPE_PRIVILEGES view */ @@ -1620,6 +2171,8 @@ CREATE VIEW data_type_privileges AS FROM ( + SELECT udt_schema, udt_name, 'USER-DEFINED TYPE'::text, dtd_identifier FROM attributes + UNION ALL SELECT table_schema, table_name, 'TABLE'::text, dtd_identifier FROM columns UNION ALL SELECT domain_schema, domain_name, 'DOMAIN'::text, dtd_identifier FROM domains @@ -1633,7 +2186,7 @@ GRANT SELECT ON data_type_privileges TO PUBLIC; /* - * 20.27 + * 5.28 * ELEMENT_TYPES view */ @@ -1642,7 +2195,7 @@ CREATE VIEW element_types AS 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, - CAST(x.objdtdid AS sql_identifier) AS array_type_identifier, + CAST(x.objdtdid AS sql_identifier) AS collection_type_identifier, CAST( CASE WHEN nbt.nspname = 'pg_catalog' THEN format_type(bt.oid, null) ELSE 'USER-DEFINED' END AS character_data) AS data_type,