From f89c972ac82dcb20a492e551f846be97690b2002 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Sun, 18 May 2003 20:55:57 +0000 Subject: [PATCH] Add documentation for information schema, and some corrections on some views. --- doc/src/sgml/filelist.sgml | 3 +- doc/src/sgml/information_schema.sgml | 1735 ++++++++++++++++++++ doc/src/sgml/postgres.sgml | 3 +- src/backend/catalog/information_schema.sql | 52 +- 4 files changed, 1776 insertions(+), 17 deletions(-) create mode 100644 doc/src/sgml/information_schema.sgml diff --git a/doc/src/sgml/filelist.sgml b/doc/src/sgml/filelist.sgml index ed4d13223c..4ba2bd9e51 100644 --- a/doc/src/sgml/filelist.sgml +++ b/doc/src/sgml/filelist.sgml @@ -1,4 +1,4 @@ - + @@ -63,6 +63,7 @@ + diff --git a/doc/src/sgml/information_schema.sgml b/doc/src/sgml/information_schema.sgml new file mode 100644 index 0000000000..dd58a9e330 --- /dev/null +++ b/doc/src/sgml/information_schema.sgml @@ -0,0 +1,1735 @@ + + + + The Information Schema + + + information schema + + + + The information schema consists of a set of views that contain + information about the objects defined in the current database. The + information schema is defined in the SQL standard and can therefore + be expected to be portable and remain stable --- unlike the system + catalogs, which are specific to PostgreSQL and are modelled after + implementation concerns. The information schema views do not, + however, contain information about PostgreSQL-specific features; to + inquire about those you need to query the system catalogs or other + PostgreSQL-specific views. + + + + The Schema + + + The information schema itself is a schema named + information_schema. This schema automatically + exists in all databases. The owner of this schema is the initial + database user in the cluster, and that user naturally has all the + privileges on this schema, including the ability to drop it (but + the space savings achieved by this are minuscule). + + + + By default, the information schema is not in the schema search + path, so you need to access all objects in it through qualified + names. Since the names of some of the objects in the information + schema are generic names that might occur in user applications, you + should be careful if you want to put the information schema in the + path. + + + + + Data Types + + + The columns of the information schema views use special data types + that are defined in the information schema. These are defined as + simple domains over ordinary built-in types. You should not use + these types for work outside the information schema, but your + applications must be prepared for them if they select from the + information schema. + + + + These types are: + + + + cardinal_number + + + A nonnegative integer. + + + + + + character_data + + + A character string (without specific maximum length). + + + + + + sql_identifier + + + A character string. This type is used for SQL identifiers, the + type character_data is used for any other kind of + text data. + + + + + + time_stamp + + + A domain over the type timestamp + + + + + + Every column in the information schema has one of these four types. + + + + Boolean (true/false) data is represented in the information schema + by a column of type character_data that contains + either YES or NO. (The + information schema was invented before the type + boolean was added to the SQL standard, so this + convention is necessary to keep the information schema backward + compatible.) + + + + + <literal>information_schema_catalog_name</literal> + + + information_schema_catalog_name is a table that + always contains one row and one column containing the name of the + current database (current catalog, in SQL terminology). + + + + <literal>information_schema_catalog_name</literal> Columns + + + + + Name + Data Type + Description + + + + + + catalog_name + sql_identifier + Name of the database that contains this information schema + + + +
+
+ + + <literal>check_constraints</literal> + + + The view check_constraints contains all check + constraints, either defined on a table or on a domain, that are + owned by the current user. + + + + <literal>check_constraints</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 + + + + check_clause + character_data + The check expression of the check constraint + + + +
+
+ + + <literal>column_domain_usage</literal> + + + 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. + + + + <literal>column_domain_usage</literal> Columns + + + + + Name + Data Type + Description + + + + + + domain_catalog + sql_identifier + Name of the database containing the domain (always the current database) + + + + domain_schema + sql_identifier + Name of the schema containing the domain + + + + domain_name + sql_identifier + Name of the domain + + + + table_catalog + sql_identifier + Name of the database containing the table (always the current database) + + + + table_schema + sql_identifier + Name of the schema containing the table + + + + table_name + sql_identifier + Name of the table + + + + column_name + sql_identifier + Name of the column + + + +
+
+ + + <literal>columns</literal> + + + The view columns contains information about all + table columns (or view columns) in the database. System columns + (oid, etc.) are not included. + + + + <literal>columns</literal> Columns + + + + + Name + Data Type + Description + + + + + + table_catalog + sql_identifier + Name of the database containing the table (always the current database) + + + + table_schema + sql_identifier + Name of the schema containing the table + + + + table_name + sql_identifier + Name of the table + + + + column_name + sql_identifier + Name of the column + + + + ordinal_position + cardinal_number + Ordinal position of the column within the table (count starts at 1) + + + + column_default + character_data + + Default expression of the column (null if the current user is + not the owner of the table containing the column) + + + + + is_nullable + character_data + + YES if the column is possibly nullable, + NO if it is known not nullable. A not-null + constraint is one way a column can be known not nullable, but + there may be others. + + + + + data_type + character_data + Data type of the column + + + + character_maximum_length + cardinal_number + + If the column has 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 the column has 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 the column has a numeric type, this column contains the + (declared or implicit) precision of the type for this column. + 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 the column has 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 the column has an exact numeric type, this column contains + the (declared or implicit) scale of the type for this column. + 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 the column has 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 + + + + character_set_catalog + sql_identifier + Applies to a feature not available in PostgreSQL + + + + character_set_schema + sql_identifier + Applies to a feature not available in PostgreSQL + + + + character_set_name + sql_identifier + Applies to a feature not available in PostgreSQL + + + + collation_catalog + sql_identifier + Applies to a feature not available in PostgreSQL + + + + collation_schema + sql_identifier + Applies to a feature not available in PostgreSQL + + + + collation_name + sql_identifier + Applies to a feature not available in PostgreSQL + + + + domain_catalog + sql_identifier + + If the column has a domain type, the name of the database that + the domain is defined in (always the current database), else + null. + + + + + domain_schema + sql_identifier + + If the column has a domain type, the name of the schema that + the domain is defined in, else null. + + + + + domain_name + sql_identifier + If the column has a domain type, the name of the domain, else null. + + + + udt_catalog + sql_identifier + + Name of the database that the column data type is defined in + (always the current database), null if the column has a domain + type. + + + + + udt_schema + sql_identifier + + Name of the schema that the column data type is defined in, + null if the column has a domain type. + + + + + udt_name + sql_identifier + Name of the column data type, null if the column has a domain 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 + Applies to a feature not available in PostgreSQL + + + + dtd_identifier + sql_identifier + Applies to a feature not available in PostgreSQL + + + + is_self_referencing + character_data + Applies to a feature not available in PostgreSQL + + + +
+
+ + + <literal>domain_constraints</literal> + + + The view domain_constraints contains all + constraints belonging to domains. + + + + <literal>domain_constraints</literal> Columns + + + + + Name + Data Type + Description + + + + + + constraint_catalog + sql_identifier + Name of the database that contains the constraint (always the current database) + + + + constraint_schema + sql_identifier + Name of the schema that contains the constraint + + + + constraint_name + sql_identifier + Name of the constraint + + + + domain_catalog + sql_identifier + Name of the database that contains the domain (always the current database) + + + + domain_schema + sql_identifier + Name of the schema that contains the domain + + + + domain_name + sql_identifier + Name of the domain + + + + is_deferrable + character_data + YES if the constraint is deferrable, NO if not + + + + initially_deferred + character_data + YES if the constraint is deferrable and initially deferred, NO if not + + + +
+
+ + + <literal>domains</literal> + + + The view domains contains all domains defined in + the current database. + + + + <literal>domains</literal> Columns + + + + + Name + Data Type + Description + + + + + + domain_catalog + sql_identifier + Name of the database that contains the domain (always the current database) + + + + domain_schema + sql_identifier + Name of the schema that contains the domain + + + + domain_name + sql_identifier + Name of the domain + + + + data_type + character_data + Data type of the domain + + + + character_maximum_length + cardinal_number + + If the domain has 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 the domain has 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. + + + + + character_set_catalog + sql_identifier + Applies to a feature not available in PostgreSQL + + + + character_set_schema + sql_identifier + Applies to a feature not available in PostgreSQL + + + + character_set_name + sql_identifier + Applies to a feature not available in PostgreSQL + + + + collation_catalog + sql_identifier + Applies to a feature not available in PostgreSQL + + + + collation_schema + sql_identifier + Applies to a feature not available in PostgreSQL + + + + collation_name + sql_identifier + Applies to a feature not available in PostgreSQL + + + + numeric_precision + cardinal_number + + If the domain has a numeric type, this column contains the + (declared or implicit) precision of the type for this column. + 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 the domain has 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 the domain has an exact numeric type, this column contains + the (declared or implicit) scale of the type for this column. + 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 the domain has 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 + + + + domain_default + character_data + Default expression of the domain + + + + udt_catalog + sql_identifier + Name of the database that the domain data type is defined in (always the current database) + + + + udt_schema + sql_identifier + Name of the schema that the domain data type is defined in + + + + udt_name + sql_identifier + Name of the domain 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 + Applies to a feature not available in PostgreSQL + + + + dtd_identifier + sql_identifier + Applies to a feature not available in PostgreSQL + + + +
+
+ + + <literal>referential_constraints</literal> + + + The view referential_constraints contains all + referential (foreign key) constraints in the current database that + belong to a table owned by the current user. + + + + <literal>referential_constraints</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 + + + + unique_constraint_catalog + sql_identifier + Not yet implemented + + + + unique_constraint_schema + sql_identifier + Not yet implemented + + + + unique_constraint_name + sql_identifier + Not yet implemented + + + + match_option + character_data + + Match option of the referential constraint: + FULL, PARTIAL, or + NONE. + + + + + update_rule + character_data + + Update rule of the referential constraint: + CASCADE, SET NULL, + SET DEFAULT, RESTRICT,or + NO ACTION. + + + + + delete_rule + character_data + + Delete rule of the referential constraint: + CASCADE, SET NULL, + SET DEFAULT, RESTRICT,or + NO ACTION. + + + + +
+
+ + + <literal>schemata</literal> + + + The view schemata contains all schemas in the + current database. + + + + <literal>schemata</literal> Columns + + + + + Name + Data Type + Description + + + + + + catalog_name + sql_identifier + Name of the database that the schema is contained in (always the current database) + + + + schema_name + sql_identifier + Name of the schema + + + + schema_owner + sql_identifier + Name of the owner of the schema + + + + default_character_set_catalog + sql_identifier + Applies to a feature not available in PostgreSQL + + + + default_character_set_schema + sql_identifier + Applies to a feature not available in PostgreSQL + + + + default_character_set_name + sql_identifier + Applies to a feature not available in PostgreSQL + + + + sql_path + character_data + Applies to a feature not available in PostgreSQL + + + +
+
+ + + <literal>sql_features</literal> + + + The table sql_features contains information + about which formal features defined in the SQL standard are + supported by PostgreSQL. This is the same information that is + presented in . There you can also find + some additional background information. + + + + <literal>sql_features</literal> Columns + + + + + Name + Data Type + Description + + + + + + feature_id + character_data + Identifier string of the feature + + + + feature_name + character_data + Descriptive name of the feature + + + + sub_feature_id + character_data + Identifier string of the subfeature, or a zero-length string if not a subfeature + + + + sub_feature_name + character_data + Descriptive name of the subfeature, or a zero-length string if not a subfeature + + + + is_supported + character_data + + YES if the feature 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 feature + + + +
+
+ + + <literal>sql_implementation_info</literal> + + + The table sql_information_info contains + information about various aspects that are left + implementation-defined by the SQL standard. This information is + primarily intended for use in the context of the ODBC interface; + users of other interfaces will probably find this information to be + of little use. For this reason, the individual implementation + information items are not described here; you will find them in the + description of the ODBC interface. + + + + <literal>sql_implementation_info</literal> Columns + + + + + Name + Data Type + Description + + + + + + implementation_info_id + character_data + Identifier string of the implementation information item + + + + implementation_info_name + character_data + Descriptive name of the implementation information item + + + + integer_value + cardinal_number + + Value of the implementation information item, or null if the + value is contained in the column + character_value + + + + + character_value + character_data + + Value of the implementation information item, or null if the + value is contained in the column + integer_value + + + + + comments + character_data + Possibly a comment pertaining to the implementation information item + + + +
+
+ + + <literal>sql_languages</literal> + + + The table sql_languages contains one row for + each SQL language binding that is supported by PostgreSQL. + PostgreSQL supports direct SQL and embedded SQL in C; that is all + you will learn from this table. + + + + <literal>sql_languages</literal> Columns + + + + + Name + Data Type + Description + + + + + + sql_language_source + character_data + + The name of the source of the language definition; always + ISO 9075, that is, the SQL standard + + + + + sql_language_year + character_data + + The year the standard referenced in + sql_language_source was approved; currently + 1999 + + + + + sql_language_comformance + character_data + + The standard conformance level for the language binding. For + ISO 9075:1999 this is always CORE. + + + + + sql_language_integrity + character_data + Always null (This value is relevant to an earlier version of the SQL standard.) + + + + sql_language_implementation + character_data + Always null + + + + sql_language_binding_style + character_data + + The language binding style, either DIRECT or + EMBEDDED + + + + + sql_language_programming_language + character_data + + The programming language, if the binding style is + EMBEDDED, else null. PostgreSQL only + supports the language C. + + + + +
+
+ + + <literal>sql_packages</literal> + + + The table sql_packages contains information + about which features packages defined in the SQL standard are + supported by PostgreSQL. Refer to for + background information on feature packages. + + + + <literal>sql_packages</literal> Columns + + + + + Name + Data Type + Description + + + + + + feature_id + character_data + Identifier string of the package + + + + feature_name + character_data + Descriptive name of the package + + + + is_supported + character_data + + YES if the package 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 package + + + +
+
+ + + <literal>sql_sizing</literal> + + + The table sql_sizing contains information about + various size limits and maximum values in PostgreSQL. This + information is primarily intended for use in the context of the + ODBC interface; users of other interfaces will probably find this + information to be of little use. For this reason, the individual + sizing items are not described here; you will find them in the + description of the ODBC interface. + + + + <literal>sql_sizing</literal> Columns + + + + + Name + Data Type + Description + + + + + + sizing_id + cardinal_number + Identifier of the sizing item + + + + sizing_name + character_data + Descriptive name of the sizing item + + + + supported_value + cardinal_number + + Value of the sizing item, or 0 if the size is unlimited or + cannot be determined, or null if the features for which the + sizing item is applicable are not supported + + + + + comments + character_data + Possibly a comment pertaining to the sizing item + + + +
+
+ + + <literal>sql_sizing_profiles</literal> + + + The table sql_sizing_profiles contains + information about the sql_sizing values that are + required by various profiles of the SQL standard. PostgreSQL does + not track any SQL profiles, so this table is empty. + + + + <literal>sql_sizing_profiles</literal> Columns + + + + + Name + Data Type + Description + + + + + + sizing_id + cardinal_number + Identifier of the sizing item + + + + sizing_name + character_data + Descriptive name of the sizing item + + + + profile_id + character_data + Identifier string of a profile + + + + required_value + cardinal_number + + The value required by the SQL profile for the sizing item, or 0 + if the profile places no limit on the sizing item, or null if + the profile does not require any of the features for which the + sizing item is applicable + + + + + comments + character_data + Possibly a comment pertaining to the sizing item within the profile + + + +
+
+ + + <literal>table_constraints</literal> + + + The view table_constraints contains all + constraints belonging to tables. + + + + <literal>table_constraints</literal> Columns + + + + + Name + Data Type + Description + + + + + + constraint_catalog + sql_identifier + Name of the database that contains the constraint (always the current database) + + + + constraint_schema + sql_identifier + Name of the schema that contains the constraint + + + + constraint_name + sql_identifier + Name of the constraint + + + + table_catalog + sql_identifier + Name of the database that contains the table (always the current database) + + + + table_schema + sql_identifier + Name of the schema that contains the table + + + + table_name + sql_identifier + Name of the table + + + + constraint_type + character_data + + Type of the constraint: CHECK, + FOREIGN KEY, PRIMARY KEY, + or UNIQUE + + + + + is_deferrable + character_data + YES if the constraint is deferrable, NO if not + + + + initially_deferred + character_data + YES if the constraint is deferrable and initially deferred, NO if not + + + +
+
+ + + <literal>table_privileges</literal> + + + The view table_privileges identifies all + privileges granted on tables to the current user or by the current + user. There is one row for each combination of table, grantor, and + grantee. + + + + <literal>table_privileges</literal> Columns + + + + + Name + Data Type + Description + + + + + + grantor + sql_identifier + Name of the user that granted the privileges + + + + grantee + sql_identifier + Name of the user that the privilege was granted to + + + + table_catalog + sql_identifier + Name of the database that contains the table (always the current database) + + + + table_schema + sql_identifier + Name of the schema that contains the table + + + + table_name + sql_identifier + Name of the table + + + + privilege_type + character_data + + Type of the privilege: SELECT, + DELETE, INSERT, + UPDATE, REFERENCES, or + TRIGGER + + + + + is_grantable + character_data + YES if the privilege is grantable, NO if not + + + + with_hierarchy + character_data + Applies to a feature not available in PostgreSQL + + + +
+
+ + + <literal>tables</literal> + + + The view tables contains all tables and views + defined in the current database. + + + + <literal>tables</literal> Columns + + + + + Name + Data Type + Description + + + + + + table_catalog + sql_identifier + Name of the database that contains the table (always the current database) + + + + table_schema + sql_identifier + Name of the schema that contains the table + + + + table_name + sql_identifier + Name of the table + + + + table_type + character_data + + Type of the table: BASE TABLE for a + persistent base table (the normal table type), + VIEW for a view, or LOCAL + TEMPORARY for a temporary table + + + + + self_referencing_column_name + sql_identifier + Applies to a feature not available in PostgreSQL + + + + reference_generation + character_data + Applies to a feature not available in PostgreSQL + + + + user_defined_type_catalog + sql_identifier + Applies to a feature not available in PostgreSQL + + + + user_defined_type_schema + sql_identifier + Applies to a feature not available in PostgreSQL + + + + user_defined_type_name + sql_identifier + Applies to a feature not available in PostgreSQL + + + +
+
+ + + <literal>views</literal> + + + The view views contains all views defined in the + current database. + + + + <literal>views</literal> Columns + + + + + Name + Data Type + Description + + + + + + table_catalog + sql_identifier + Name of the database that contains the view (always the current database) + + + + table_schema + sql_identifier + Name of the schema that contains the view + + + + table_name + sql_identifier + Name of the view + + + + view definition + character_data + + Query expression defining the view (null if the current user is + not the owner of the view) + + + + + check_option + character_data + Applies to a feature not available in PostgreSQL + + + + is_updatable + character_data + Not yet implemented + + + + is_insertable_into + character_data + Not yet implemented + + + +
+
+ +
diff --git a/doc/src/sgml/postgres.sgml b/doc/src/sgml/postgres.sgml index aecfede20e..e11292967f 100644 --- a/doc/src/sgml/postgres.sgml +++ b/doc/src/sgml/postgres.sgml @@ -1,5 +1,5 @@ diff --git a/src/backend/catalog/information_schema.sql b/src/backend/catalog/information_schema.sql index d63e645915..0fb1abe471 100644 --- a/src/backend/catalog/information_schema.sql +++ b/src/backend/catalog/information_schema.sql @@ -4,7 +4,7 @@ * * Copyright 2002, PostgreSQL Global Development Group * - * $Id: information_schema.sql,v 1.4 2003/03/20 05:06:55 momjian Exp $ + * $Id: information_schema.sql,v 1.5 2003/05/18 20:55:57 petere Exp $ */ @@ -169,17 +169,28 @@ CREATE VIEW columns AS AS character_octet_length, CAST( - CASE WHEN a.atttypid IN (1700) THEN ((a.atttypmod - 4) >> 16) & 65535 ELSE null END + CASE a.atttypid + WHEN 21 /*int2*/ THEN 16 + WHEN 23 /*int4*/ THEN 32 + WHEN 20 /*int8*/ THEN 64 + WHEN 1700 /*numeric*/ THEN ((a.atttypmod - 4) >> 16) & 65535 + WHEN 700 /*float4*/ THEN 24 /*FLT_MANT_DIG*/ + WHEN 701 /*float8*/ THEN 53 /*DBL_MANT_DIG*/ + ELSE null END AS cardinal_number) AS numeric_precision, CAST( - CASE WHEN a.atttypid IN (1700) THEN 10 ELSE null END + CASE WHEN a.atttypid IN (21, 23, 20, 700, 701) THEN 2 + WHEN a.atttypid IN (1700) THEN 10 + ELSE null END AS cardinal_number) AS numeric_precision_radix, CAST( - CASE WHEN a.atttypid IN (1700) THEN (a.atttypmod - 4) & 65535 ELSE null END + CASE WHEN a.atttypid IN (21, 23, 20) THEN 0 + WHEN a.atttypid IN (1700) THEN (a.atttypmod - 4) & 65535 + ELSE null END AS cardinal_number) AS numeric_scale, @@ -203,18 +214,18 @@ CREATE VIEW columns AS CAST(null AS sql_identifier) AS collation_schema, CAST(null AS sql_identifier) AS collation_name, - CAST(CASE WHEN t.typbasetype <> 0 THEN current_database() ELSE null END + CAST(CASE WHEN t.typtype = 'd' THEN current_database() ELSE null END AS sql_identifier) AS domain_catalog, - CAST(CASE WHEN t.typbasetype <> 0 THEN nt.nspname ELSE null END + CAST(CASE WHEN t.typtype = 'd' THEN nt.nspname ELSE null END AS sql_identifier) AS domain_schema, - CAST(CASE WHEN t.typbasetype <> 0 THEN t.typname ELSE null END + CAST(CASE WHEN t.typtype = 'd' THEN t.typname ELSE null END AS sql_identifier) AS domain_name, - CAST(CASE WHEN t.typbasetype = 0 THEN current_database() ELSE null END + CAST(CASE WHEN t.typtype <> 'd' THEN current_database() ELSE null END AS sql_identifier) AS udt_catalog, - CAST(CASE WHEN t.typbasetype = 0 THEN nt.nspname ELSE null END + CAST(CASE WHEN t.typtype <> 'd' THEN nt.nspname ELSE null END AS sql_identifier) AS udt_schema, - CAST(CASE WHEN t.typbasetype = 0 THEN t.typname ELSE null END + CAST(CASE WHEN t.typtype <> 'd' THEN t.typname ELSE null END AS sql_identifier) AS udt_name, CAST(null AS sql_identifier) AS scope_catalog, @@ -298,17 +309,28 @@ CREATE VIEW domains AS CAST(null AS sql_identifier) AS collation_name, CAST( - CASE WHEN t.typbasetype IN (1700) THEN ((t.typtypmod - 4) >> 16) & 65535 ELSE null END + CASE t.typbasetype + WHEN 21 /*int2*/ THEN 16 + WHEN 23 /*int4*/ THEN 32 + WHEN 20 /*int8*/ THEN 64 + WHEN 1700 /*numeric*/ THEN ((t.typtypmod - 4) >> 16) & 65535 + WHEN 700 /*float4*/ THEN 24 /*FLT_MANT_DIG*/ + WHEN 701 /*float8*/ THEN 53 /*DBL_MANT_DIG*/ + ELSE null END AS cardinal_number) AS numeric_precision, CAST( - CASE WHEN t.typbasetype IN (1700) THEN 10 ELSE null END + CASE WHEN t.typbasetype IN (21, 23, 20, 700, 701) THEN 2 + WHEN t.typbasetype IN (1700) THEN 10 + ELSE null END AS cardinal_number) AS numeric_precision_radix, CAST( - CASE WHEN t.typbasetype IN (1700) THEN (t.typtypmod - 4) & 65535 ELSE null END + CASE WHEN t.typbasetype IN (21, 23, 20) THEN 0 + WHEN t.typbasetype IN (1700) THEN (t.typtypmod - 4) & 65535 + ELSE null END AS cardinal_number) AS numeric_scale, @@ -347,11 +369,11 @@ CREATE VIEW domains AS WHERE rs.oid = t.typnamespace AND t.typtype = 'd' AND t.typowner = u.usesysid - AND (u.usename = CURRENT_USER + AND (u.usename = current_user OR EXISTS (SELECT 1 FROM pg_user AS u2 WHERE rs.nspowner = u2.usesysid - AND u2.usename = CURRENT_USER) + AND u2.usename = current_user) OR EXISTS (SELECT 1 FROM pg_user AS u3, pg_attribute AS a3,