From 315520cf66ba1e9369f2f2dbd0008b6c2a0cd262 Mon Sep 17 00:00:00 2001 From: Annie Pompa Date: Wed, 27 Sep 2023 22:44:48 -0400 Subject: [PATCH] sql: populate information_schema.user_defined_types and attributes This patch populates information_schema.user_defined_types with information about user defined types and information_schema.attributes with information about the attributes of composite data types. Epic: none Fixes: #109603 Release note (sql change): This patch populates information_schema.user_defined_types with information about user defined types and information_schema.attributes with information about the attributes of composite data types. --- pkg/sql/information_schema.go | 96 +++++++-- .../testdata/logic_test/crdb_internal_catalog | 4 +- .../testdata/logic_test/information_schema | 107 +++++++++- pkg/sql/vtable/information_schema.go | 202 ++++++++++++------ 4 files changed, 315 insertions(+), 94 deletions(-) diff --git a/pkg/sql/information_schema.go b/pkg/sql/information_schema.go index de24d0cbc8a5..11cc13678ec6 100644 --- a/pkg/sql/information_schema.go +++ b/pkg/sql/information_schema.go @@ -277,6 +277,46 @@ func populateRoleHierarchy( ) } +var informationSchemaAttributesTable = virtualSchemaView{ + comment: `attributes of composite data types in the current database` + + docs.URL("information-schema.html#attributes") + ` + https://www.postgresql.org/docs/16/infoschema-attributes.html`, + schema: vtable.InformationSchemaAttributes, + resultColumns: colinfo.ResultColumns{ + {Name: "udt_catalog", Typ: types.String}, + {Name: "udt_schema", Typ: types.String}, + {Name: "udt_name", Typ: types.String}, + {Name: "attribute_name", Typ: types.String}, + {Name: "ordinal_position", Typ: types.Int}, + {Name: "attribute_default", Typ: types.String}, + {Name: "is_nullable", Typ: types.String}, + {Name: "data_type", Typ: types.String}, + {Name: "character_maximum_length", Typ: types.Int}, + {Name: "character_octet_length", Typ: types.Int}, + {Name: "character_set_catalog", Typ: types.String}, + {Name: "character_set_schema", Typ: types.String}, + {Name: "character_set_name", Typ: types.String}, + {Name: "collation_catalog", Typ: types.String}, + {Name: "collation_schema", Typ: types.String}, + {Name: "collation_name", Typ: types.String}, + {Name: "numeric_precision", Typ: types.Int}, + {Name: "numeric_precision_radix", Typ: types.Int}, + {Name: "numeric_scale", Typ: types.Int}, + {Name: "datetime_precision", Typ: types.Int}, + {Name: "interval_type", Typ: types.String}, + {Name: "interval_precision", Typ: types.Int}, + {Name: "attribute_udt_catalog", Typ: types.String}, + {Name: "attribute_udt_schema", Typ: types.String}, + {Name: "attribute_udt_name", Typ: types.String}, + {Name: "scope_catalog", Typ: types.String}, + {Name: "scope_schema", Typ: types.String}, + {Name: "scope_name", Typ: types.String}, + {Name: "maximum_cardinality", Typ: types.Int}, + {Name: "dtd_identifier", Typ: types.String}, + {Name: "is_derived_reference_attribute", Typ: types.String}, + }, +} + var informationSchemaCharacterSets = virtualSchemaTable{ comment: `character sets available in the current database ` + docs.URL("information-schema.html#character_sets") + ` @@ -1478,6 +1518,44 @@ https://www.postgresql.org/docs/9.5/infoschema-table-constraints.html`, }, } +var informationSchemaUserDefinedTypesTable = virtualSchemaView{ + comment: `user-defined types` + + docs.URL("information-schema.html#user-defined-types") + ` + https://www.postgresql.org/docs/16/infoschema-user-defined-types.html`, + schema: vtable.InformationSchemaUserDefinedTypes, + resultColumns: colinfo.ResultColumns{ + {Name: "user_defined_type_catalog", Typ: types.String}, + {Name: "user_defined_type_schema", Typ: types.String}, + {Name: "user_defined_type_name", Typ: types.String}, + {Name: "user_defined_type_category", Typ: types.String}, + {Name: "is_instantiable", Typ: types.String}, + {Name: "is_final", Typ: types.String}, + {Name: "ordering_form", Typ: types.String}, + {Name: "ordering_category", Typ: types.String}, + {Name: "ordering_routine_catalog", Typ: types.String}, + {Name: "ordering_routine_schema", Typ: types.String}, + {Name: "ordering_routine_name", Typ: types.String}, + {Name: "reference_type", Typ: types.String}, + {Name: "data_type", Typ: types.String}, + {Name: "character_maximum_length", Typ: types.Int}, + {Name: "character_octet_length", Typ: types.Int}, + {Name: "character_set_catalog", Typ: types.String}, + {Name: "character_set_schema", Typ: types.String}, + {Name: "character_set_name", Typ: types.String}, + {Name: "collation_catalog", Typ: types.String}, + {Name: "collation_schema", Typ: types.String}, + {Name: "collation_name", Typ: types.String}, + {Name: "numeric_precision", Typ: types.Int}, + {Name: "numeric_precision_radix", Typ: types.Int}, + {Name: "numeric_scale", Typ: types.Int}, + {Name: "datetime_precision", Typ: types.Int}, + {Name: "interval_type", Typ: types.String}, + {Name: "interval_precision", Typ: types.Int}, + {Name: "source_dtd_identifier", Typ: types.String}, + {Name: "ref_dtd_identifier", Typ: types.String}, + }, +} + // Postgres: not provided // MySQL: https://dev.mysql.com/doc/refman/5.7/en/user-privileges-table.html // TODO(knz): this introspection facility is of dubious utility. @@ -1970,15 +2048,6 @@ var informationSchemaRoleColumnGrantsTable = virtualSchemaTable{ unimplemented: true, } -var informationSchemaAttributesTable = virtualSchemaTable{ - comment: "attributes was created for compatibility and is currently unimplemented", - schema: vtable.InformationSchemaAttributes, - populate: func(ctx context.Context, p *planner, _ catalog.DatabaseDescriptor, addRow func(...tree.Datum) error) error { - return nil - }, - unimplemented: true, -} - var informationSchemaDomainConstraintsTable = virtualSchemaTable{ comment: "domain_constraints was created for compatibility and is currently unimplemented", schema: vtable.InformationSchemaDomainConstraints, @@ -2267,15 +2336,6 @@ var informationSchemaColumnsExtensionsTable = virtualSchemaTable{ unimplemented: true, } -var informationSchemaUserDefinedTypesTable = virtualSchemaTable{ - comment: "user_defined_types was created for compatibility and is currently unimplemented", - schema: vtable.InformationSchemaUserDefinedTypes, - populate: func(ctx context.Context, p *planner, _ catalog.DatabaseDescriptor, addRow func(...tree.Datum) error) error { - return nil - }, - unimplemented: true, -} - var informationSchemaSQLFeaturesTable = virtualSchemaTable{ comment: "sql_features was created for compatibility and is currently unimplemented", schema: vtable.InformationSchemaSQLFeatures, diff --git a/pkg/sql/logictest/testdata/logic_test/crdb_internal_catalog b/pkg/sql/logictest/testdata/logic_test/crdb_internal_catalog index ba7435586854..dadf31a53cb8 100644 --- a/pkg/sql/logictest/testdata/logic_test/crdb_internal_catalog +++ b/pkg/sql/logictest/testdata/logic_test/crdb_internal_catalog @@ -316,7 +316,7 @@ SELECT id, strip_volatile(descriptor) FROM crdb_internal.kv_catalog_descriptor O 4294967114 {"table": {"columns": [{"id": 1, "name": "grantee", "type": {"family": "StringFamily", "oid": 25}}, {"id": 2, "name": "table_catalog", "type": {"family": "StringFamily", "oid": 25}}, {"id": 3, "name": "privilege_type", "type": {"family": "StringFamily", "oid": 25}}, {"id": 4, "name": "is_grantable", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}], "formatVersion": 3, "id": 4294967114, "name": "user_privileges", "nextColumnId": 5, "nextConstraintId": 2, "nextIndexId": 2, "nextMutationId": 1, "primaryIndex": {"constraintId": 1, "foreignKey": {}, "geoConfig": {}, "id": 1, "interleave": {}, "partitioning": {}, "sharded": {}}, "privileges": {"ownerProto": "node", "users": [{"privileges": "32", "userProto": "public"}], "version": 2}, "replacementOf": {"time": {}}, "unexposedParentSchemaId": 4294967196, "version": "1"}} 4294967115 {"table": {"columns": [{"id": 1, "name": "authorization_identifier", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 2, "name": "foreign_server_catalog", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 3, "name": "foreign_server_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}], "formatVersion": 3, "id": 4294967115, "name": "user_mappings", "nextColumnId": 4, "nextConstraintId": 2, "nextIndexId": 2, "nextMutationId": 1, "primaryIndex": {"constraintId": 1, "foreignKey": {}, "geoConfig": {}, "id": 1, "interleave": {}, "partitioning": {}, "sharded": {}}, "privileges": {"ownerProto": "node", "users": [{"privileges": "32", "userProto": "public"}], "version": 2}, "replacementOf": {"time": {}}, "unexposedParentSchemaId": 4294967196, "version": "1"}} 4294967116 {"table": {"columns": [{"id": 1, "name": "authorization_identifier", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 2, "name": "foreign_server_catalog", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 3, "name": "foreign_server_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 4, "name": "option_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 5, "name": "option_value", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}], "formatVersion": 3, "id": 4294967116, "name": "user_mapping_options", "nextColumnId": 6, "nextConstraintId": 2, "nextIndexId": 2, "nextMutationId": 1, "primaryIndex": {"constraintId": 1, "foreignKey": {}, "geoConfig": {}, "id": 1, "interleave": {}, "partitioning": {}, "sharded": {}}, "privileges": {"ownerProto": "node", "users": [{"privileges": "32", "userProto": "public"}], "version": 2}, "replacementOf": {"time": {}}, "unexposedParentSchemaId": 4294967196, "version": "1"}} -4294967117 {"table": {"columns": [{"id": 1, "name": "user_defined_type_catalog", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 2, "name": "user_defined_type_schema", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 3, "name": "user_defined_type_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 4, "name": "user_defined_type_category", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 5, "name": "is_instantiable", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 6, "name": "is_final", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 7, "name": "ordering_form", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 8, "name": "ordering_category", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 9, "name": "ordering_routine_catalog", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 10, "name": "ordering_routine_schema", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 11, "name": "ordering_routine_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 12, "name": "reference_type", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 13, "name": "data_type", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 14, "name": "character_maximum_length", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 15, "name": "character_octet_length", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 16, "name": "character_set_catalog", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 17, "name": "character_set_schema", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 18, "name": "character_set_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 19, "name": "collation_catalog", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 20, "name": "collation_schema", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 21, "name": "collation_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 22, "name": "numeric_precision", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 23, "name": "numeric_precision_radix", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 24, "name": "numeric_scale", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 25, "name": "datetime_precision", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 26, "name": "interval_type", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 27, "name": "interval_precision", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 28, "name": "source_dtd_identifier", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 29, "name": "ref_dtd_identifier", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}], "formatVersion": 3, "id": 4294967117, "name": "user_defined_types", "nextColumnId": 30, "nextConstraintId": 2, "nextIndexId": 2, "nextMutationId": 1, "primaryIndex": {"constraintId": 1, "foreignKey": {}, "geoConfig": {}, "id": 1, "interleave": {}, "partitioning": {}, "sharded": {}}, "privileges": {"ownerProto": "node", "users": [{"privileges": "32", "userProto": "public"}], "version": 2}, "replacementOf": {"time": {}}, "unexposedParentSchemaId": 4294967196, "version": "1"}} +4294967117 {"table": {"columns": [{"id": 1, "name": "user_defined_type_catalog", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 2, "name": "user_defined_type_schema", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 3, "name": "user_defined_type_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 4, "name": "user_defined_type_category", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 5, "name": "is_instantiable", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 6, "name": "is_final", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 7, "name": "ordering_form", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 8, "name": "ordering_category", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 9, "name": "ordering_routine_catalog", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 10, "name": "ordering_routine_schema", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 11, "name": "ordering_routine_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 12, "name": "reference_type", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 13, "name": "data_type", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 14, "name": "character_maximum_length", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 15, "name": "character_octet_length", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 16, "name": "character_set_catalog", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 17, "name": "character_set_schema", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 18, "name": "character_set_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 19, "name": "collation_catalog", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 20, "name": "collation_schema", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 21, "name": "collation_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 22, "name": "numeric_precision", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 23, "name": "numeric_precision_radix", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 24, "name": "numeric_scale", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 25, "name": "datetime_precision", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 26, "name": "interval_type", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 27, "name": "interval_precision", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 28, "name": "source_dtd_identifier", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 29, "name": "ref_dtd_identifier", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}], "formatVersion": 3, "id": 4294967117, "name": "user_defined_types", "nextColumnId": 30, "nextConstraintId": 1, "nextMutationId": 1, "primaryIndex": {"foreignKey": {}, "geoConfig": {}, "interleave": {}, "partitioning": {}, "sharded": {}}, "privileges": {"ownerProto": "node", "users": [{"privileges": "32", "userProto": "public"}], "version": 2}, "replacementOf": {"time": {}}, "unexposedParentSchemaId": 4294967196, "version": "1", "viewQuery": "SELECT CAST(current_database() AS STRING) AS user_defined_type_catalog, CAST(n.nspname AS STRING) AS user_defined_type_schema, CAST(c.relname AS STRING) AS user_defined_type_name, CAST('STRUCTURED' AS STRING) AS user_defined_type_category, CAST('YES' AS STRING) AS is_instantiable, CAST(NULL AS STRING) AS is_final, CAST(NULL AS STRING) AS ordering_form, CAST(NULL AS STRING) AS ordering_category, CAST(NULL AS STRING) AS ordering_routine_catalog, CAST(NULL AS STRING) AS ordering_routine_schema, CAST(NULL AS STRING) AS ordering_routine_name, CAST(NULL AS STRING) AS reference_type, CAST(NULL AS STRING) AS data_type, CAST(NULL AS INT8) AS character_maximum_length, CAST(NULL AS INT8) AS character_octet_length, CAST(NULL AS STRING) AS character_set_catalog, CAST(NULL AS STRING) AS character_set_schema, CAST(NULL AS STRING) AS character_set_name, CAST(NULL AS STRING) AS collation_catalog, CAST(NULL AS STRING) AS collation_schema, CAST(NULL AS STRING) AS collation_name, CAST(NULL AS INT8) AS numeric_precision, CAST(NULL AS INT8) AS numeric_precision_radix, CAST(NULL AS INT8) AS numeric_scale, CAST(NULL AS INT8) AS datetime_precision, CAST(NULL AS STRING) AS interval_type, CAST(NULL AS INT8) AS interval_precision, CAST(NULL AS STRING) AS source_dtd_identifier, CAST(NULL AS STRING) AS ref_dtd_identifier FROM pg_namespace AS n, pg_class AS c, pg_type AS t WHERE (((n.oid = c.relnamespace) AND (t.typrelid = c.oid)) AND (c.relkind = 'c')) AND (pg_has_role(t.typowner, 'USAGE') OR has_type_privilege(t.oid, 'USAGE'))"}} 4294967118 {"table": {"columns": [{"id": 1, "name": "attribute", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 2, "name": "host", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 3, "name": "user", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}], "formatVersion": 3, "id": 4294967118, "name": "user_attributes", "nextColumnId": 4, "nextConstraintId": 2, "nextIndexId": 2, "nextMutationId": 1, "primaryIndex": {"constraintId": 1, "foreignKey": {}, "geoConfig": {}, "id": 1, "interleave": {}, "partitioning": {}, "sharded": {}}, "privileges": {"ownerProto": "node", "users": [{"privileges": "32", "userProto": "public"}], "version": 2}, "replacementOf": {"time": {}}, "unexposedParentSchemaId": 4294967196, "version": "1"}} 4294967119 {"table": {"columns": [{"id": 1, "name": "grantor", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 2, "name": "grantee", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 3, "name": "object_catalog", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 4, "name": "object_schema", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 5, "name": "object_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 6, "name": "object_type", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 7, "name": "privilege_type", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 8, "name": "is_grantable", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}], "formatVersion": 3, "id": 4294967119, "name": "usage_privileges", "nextColumnId": 9, "nextConstraintId": 2, "nextIndexId": 2, "nextMutationId": 1, "primaryIndex": {"constraintId": 1, "foreignKey": {}, "geoConfig": {}, "id": 1, "interleave": {}, "partitioning": {}, "sharded": {}}, "privileges": {"ownerProto": "node", "users": [{"privileges": "32", "userProto": "public"}], "version": 2}, "replacementOf": {"time": {}}, "unexposedParentSchemaId": 4294967196, "version": "1"}} 4294967120 {"table": {"columns": [{"id": 1, "name": "grantor", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 2, "name": "grantee", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 3, "name": "udt_catalog", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 4, "name": "udt_schema", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 5, "name": "udt_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 6, "name": "privilege_type", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 7, "name": "is_grantable", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}], "formatVersion": 3, "id": 4294967120, "name": "udt_privileges", "nextColumnId": 8, "nextConstraintId": 2, "nextIndexId": 2, "nextMutationId": 1, "primaryIndex": {"constraintId": 1, "foreignKey": {}, "geoConfig": {}, "id": 1, "interleave": {}, "partitioning": {}, "sharded": {}}, "privileges": {"ownerProto": "node", "users": [{"privileges": "32", "userProto": "public"}], "version": 2}, "replacementOf": {"time": {}}, "unexposedParentSchemaId": 4294967196, "version": "1"}} @@ -392,7 +392,7 @@ SELECT id, strip_volatile(descriptor) FROM crdb_internal.kv_catalog_descriptor O 4294967190 {"table": {"columns": [{"id": 1, "name": "constraint_catalog", "type": {"family": "StringFamily", "oid": 25}}, {"id": 2, "name": "constraint_schema", "type": {"family": "StringFamily", "oid": 25}}, {"id": 3, "name": "constraint_name", "type": {"family": "StringFamily", "oid": 25}}, {"id": 4, "name": "check_clause", "type": {"family": "StringFamily", "oid": 25}}], "formatVersion": 3, "id": 4294967190, "name": "check_constraints", "nextColumnId": 5, "nextConstraintId": 2, "nextIndexId": 2, "nextMutationId": 1, "primaryIndex": {"constraintId": 1, "foreignKey": {}, "geoConfig": {}, "id": 1, "interleave": {}, "partitioning": {}, "sharded": {}}, "privileges": {"ownerProto": "node", "users": [{"privileges": "32", "userProto": "public"}], "version": 2}, "replacementOf": {"time": {}}, "unexposedParentSchemaId": 4294967196, "version": "1"}} 4294967191 {"table": {"columns": [{"id": 1, "name": "constraint_catalog", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 2, "name": "constraint_schema", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 3, "name": "constraint_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 4, "name": "specific_catalog", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 5, "name": "specific_schema", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 6, "name": "specific_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}], "formatVersion": 3, "id": 4294967191, "name": "check_constraint_routine_usage", "nextColumnId": 7, "nextConstraintId": 2, "nextIndexId": 2, "nextMutationId": 1, "primaryIndex": {"constraintId": 1, "foreignKey": {}, "geoConfig": {}, "id": 1, "interleave": {}, "partitioning": {}, "sharded": {}}, "privileges": {"ownerProto": "node", "users": [{"privileges": "32", "userProto": "public"}], "version": 2}, "replacementOf": {"time": {}}, "unexposedParentSchemaId": 4294967196, "version": "1"}} 4294967192 {"table": {"columns": [{"id": 1, "name": "character_set_catalog", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 2, "name": "character_set_schema", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 3, "name": "character_set_name", "type": {"family": "StringFamily", "oid": 25}}, {"id": 4, "name": "character_repertoire", "type": {"family": "StringFamily", "oid": 25}}, {"id": 5, "name": "form_of_use", "type": {"family": "StringFamily", "oid": 25}}, {"id": 6, "name": "default_collate_catalog", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 7, "name": "default_collate_schema", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 8, "name": "default_collate_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}], "formatVersion": 3, "id": 4294967192, "name": "character_sets", "nextColumnId": 9, "nextConstraintId": 2, "nextIndexId": 2, "nextMutationId": 1, "primaryIndex": {"constraintId": 1, "foreignKey": {}, "geoConfig": {}, "id": 1, "interleave": {}, "partitioning": {}, "sharded": {}}, "privileges": {"ownerProto": "node", "users": [{"privileges": "32", "userProto": "public"}], "version": 2}, "replacementOf": {"time": {}}, "unexposedParentSchemaId": 4294967196, "version": "1"}} -4294967193 {"table": {"columns": [{"id": 1, "name": "udt_catalog", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 2, "name": "udt_schema", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 3, "name": "udt_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 4, "name": "attribute_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 5, "name": "ordinal_position", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 6, "name": "attribute_default", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 7, "name": "is_nullable", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 8, "name": "data_type", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 9, "name": "character_maximum_length", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 10, "name": "character_octet_length", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 11, "name": "character_set_catalog", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 12, "name": "character_set_schema", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 13, "name": "character_set_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 14, "name": "collation_catalog", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 15, "name": "collation_schema", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 16, "name": "collation_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 17, "name": "numeric_precision", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 18, "name": "numeric_precision_radix", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 19, "name": "numeric_scale", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 20, "name": "datetime_precision", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 21, "name": "interval_type", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 22, "name": "interval_precision", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 23, "name": "attribute_udt_catalog", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 24, "name": "attribute_udt_schema", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 25, "name": "attribute_udt_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 26, "name": "scope_catalog", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 27, "name": "scope_schema", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 28, "name": "scope_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 29, "name": "maximum_cardinality", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 30, "name": "dtd_identifier", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 31, "name": "is_derived_reference_attribute", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}], "formatVersion": 3, "id": 4294967193, "name": "attributes", "nextColumnId": 32, "nextConstraintId": 2, "nextIndexId": 2, "nextMutationId": 1, "primaryIndex": {"constraintId": 1, "foreignKey": {}, "geoConfig": {}, "id": 1, "interleave": {}, "partitioning": {}, "sharded": {}}, "privileges": {"ownerProto": "node", "users": [{"privileges": "32", "userProto": "public"}], "version": 2}, "replacementOf": {"time": {}}, "unexposedParentSchemaId": 4294967196, "version": "1"}} +4294967193 {"table": {"columns": [{"id": 1, "name": "udt_catalog", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 2, "name": "udt_schema", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 3, "name": "udt_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 4, "name": "attribute_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 5, "name": "ordinal_position", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 6, "name": "attribute_default", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 7, "name": "is_nullable", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 8, "name": "data_type", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 9, "name": "character_maximum_length", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 10, "name": "character_octet_length", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 11, "name": "character_set_catalog", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 12, "name": "character_set_schema", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 13, "name": "character_set_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 14, "name": "collation_catalog", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 15, "name": "collation_schema", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 16, "name": "collation_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 17, "name": "numeric_precision", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 18, "name": "numeric_precision_radix", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 19, "name": "numeric_scale", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 20, "name": "datetime_precision", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 21, "name": "interval_type", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 22, "name": "interval_precision", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 23, "name": "attribute_udt_catalog", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 24, "name": "attribute_udt_schema", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 25, "name": "attribute_udt_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 26, "name": "scope_catalog", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 27, "name": "scope_schema", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 28, "name": "scope_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 29, "name": "maximum_cardinality", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 30, "name": "dtd_identifier", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 31, "name": "is_derived_reference_attribute", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}], "formatVersion": 3, "id": 4294967193, "name": "attributes", "nextColumnId": 32, "nextConstraintId": 1, "nextMutationId": 1, "primaryIndex": {"foreignKey": {}, "geoConfig": {}, "interleave": {}, "partitioning": {}, "sharded": {}}, "privileges": {"ownerProto": "node", "users": [{"privileges": "32", "userProto": "public"}], "version": 2}, "replacementOf": {"time": {}}, "unexposedParentSchemaId": 4294967196, "version": "1", "viewQuery": "SELECT CAST(current_database() AS STRING) AS udt_catalog, CAST(nc.nspname AS STRING) AS udt_schema, CAST(c.relname AS STRING) AS udt_name, CAST(a.attname AS STRING) AS attribute_name, CAST(a.attnum AS INT8) AS ordinal_position, CAST(pg_get_expr(ad.adbin, ad.adrelid) AS STRING) AS attribute_default, CAST(CASE WHEN a.attnotnull OR ((t.typtype = 'd') AND t.typnotnull) THEN 'NO' ELSE 'YES' END AS STRING) 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 STRING) AS data_type, CAST(information_schema._pg_char_max_length(information_schema._pg_truetypid(a, t), information_schema._pg_truetypmod(a, t)) AS INT8) AS character_maximum_length, CAST(information_schema._pg_char_octet_length(information_schema._pg_truetypid(a, t), information_schema._pg_truetypmod(a, t)) AS INT8) AS character_octet_length, CAST(NULL AS STRING) AS character_set_catalog, CAST(NULL AS STRING) AS character_set_schema, CAST(NULL AS STRING) AS character_set_name, CAST(CASE WHEN nco.nspname IS NOT NULL THEN current_database() END AS STRING) AS collation_catalog, CAST(nco.nspname AS STRING) AS collation_schema, CAST(co.collname AS STRING) AS collation_name, CAST(information_schema._pg_numeric_precision(information_schema._pg_truetypid(a, t), information_schema._pg_truetypmod(a, t)) AS INT8) AS numeric_precision, CAST(information_schema._pg_numeric_precision_radix(information_schema._pg_truetypid(a, t), information_schema._pg_truetypmod(a, t)) AS INT8) AS numeric_precision_radix, CAST(information_schema._pg_numeric_scale(information_schema._pg_truetypid(a, t), information_schema._pg_truetypmod(a, t)) AS INT8) AS numeric_scale, CAST(information_schema._pg_datetime_precision(information_schema._pg_truetypid(a, t), information_schema._pg_truetypmod(a, t)) AS INT8) AS datetime_precision, CAST(information_schema._pg_interval_type(information_schema._pg_truetypid(a, t), information_schema._pg_truetypmod(a, t)) AS STRING) AS interval_type, CAST(NULL AS INT8) AS interval_precision, CAST(current_database() AS STRING) AS attribute_udt_catalog, CAST(nt.nspname AS STRING) AS attribute_udt_schema, CAST(t.typname AS STRING) AS attribute_udt_name, CAST(NULL AS STRING) AS scope_catalog, CAST(NULL AS STRING) AS scope_schema, CAST(NULL AS STRING) AS scope_name, CAST(NULL AS INT8) AS maximum_cardinality, CAST(a.attnum AS STRING) AS dtd_identifier, CAST('NO' AS STRING) AS is_derived_reference_attribute FROM (pg_attribute AS a LEFT JOIN pg_attrdef AS ad ON (attrelid = adrelid) AND (attnum = adnum)) JOIN (pg_class AS c JOIN pg_namespace AS nc ON (c.relnamespace = nc.oid)) ON a.attrelid = c.oid JOIN (pg_type AS t JOIN pg_namespace AS nt ON (t.typnamespace = nt.oid)) ON a.atttypid = t.oid LEFT JOIN (pg_collation AS co JOIN pg_namespace AS nco ON (co.collnamespace = nco.oid)) ON (a.attcollation = co.oid) AND ((nco.nspname, co.collname) != ('pg_catalog', 'default')) WHERE (((a.attnum > 0) AND (NOT a.attisdropped)) AND (c.relkind IN ('c',))) AND (pg_has_role(c.relowner, 'USAGE') OR has_type_privilege(c.reltype, 'USAGE'))"}} 4294967194 {"table": {"columns": [{"id": 1, "name": "grantee", "type": {"family": "StringFamily", "oid": 25}}, {"id": 2, "name": "role_name", "type": {"family": "StringFamily", "oid": 25}}, {"id": 3, "name": "is_grantable", "type": {"family": "StringFamily", "oid": 25}}], "formatVersion": 3, "id": 4294967194, "name": "applicable_roles", "nextColumnId": 4, "nextConstraintId": 2, "nextIndexId": 2, "nextMutationId": 1, "primaryIndex": {"constraintId": 1, "foreignKey": {}, "geoConfig": {}, "id": 1, "interleave": {}, "partitioning": {}, "sharded": {}}, "privileges": {"ownerProto": "node", "users": [{"privileges": "32", "userProto": "public"}], "version": 2}, "replacementOf": {"time": {}}, "unexposedParentSchemaId": 4294967196, "version": "1"}} 4294967195 {"table": {"columns": [{"id": 1, "name": "grantee", "type": {"family": "StringFamily", "oid": 25}}, {"id": 2, "name": "role_name", "type": {"family": "StringFamily", "oid": 25}}, {"id": 3, "name": "is_grantable", "type": {"family": "StringFamily", "oid": 25}}], "formatVersion": 3, "id": 4294967195, "name": "administrable_role_authorizations", "nextColumnId": 4, "nextConstraintId": 2, "nextIndexId": 2, "nextMutationId": 1, "primaryIndex": {"constraintId": 1, "foreignKey": {}, "geoConfig": {}, "id": 1, "interleave": {}, "partitioning": {}, "sharded": {}}, "privileges": {"ownerProto": "node", "users": [{"privileges": "32", "userProto": "public"}], "version": 2}, "replacementOf": {"time": {}}, "unexposedParentSchemaId": 4294967196, "version": "1"}} 4294967196 {"schema": {"defaultPrivileges": {"type": "SCHEMA"}, "id": 4294967196, "name": "information_schema", "privileges": {"ownerProto": "node", "users": [{"privileges": "512", "userProto": "public"}], "version": 2}, "version": "1"}} diff --git a/pkg/sql/logictest/testdata/logic_test/information_schema b/pkg/sql/logictest/testdata/logic_test/information_schema index b20942a5f973..5686ecf4fbf8 100644 --- a/pkg/sql/logictest/testdata/logic_test/information_schema +++ b/pkg/sql/logictest/testdata/logic_test/information_schema @@ -20,7 +20,7 @@ SHOW TABLES FROM information_schema ---- information_schema administrable_role_authorizations table node NULL NULL information_schema applicable_roles table node NULL NULL -information_schema attributes table node NULL NULL +information_schema attributes view node NULL NULL information_schema character_sets table node NULL NULL information_schema check_constraint_routine_usage table node NULL NULL information_schema check_constraints table node NULL NULL @@ -96,7 +96,7 @@ information_schema type_privileges table node NULL NU information_schema udt_privileges table node NULL NULL information_schema usage_privileges table node NULL NULL information_schema user_attributes table node NULL NULL -information_schema user_defined_types table node NULL NULL +information_schema user_defined_types view node NULL NULL information_schema user_mapping_options table node NULL NULL information_schema user_mappings table node NULL NULL information_schema user_privileges table node NULL NULL @@ -235,7 +235,7 @@ SHOW TABLES FROM test.information_schema ---- information_schema administrable_role_authorizations table node NULL NULL information_schema applicable_roles table node NULL NULL -information_schema attributes table node NULL NULL +information_schema attributes view node NULL NULL information_schema character_sets table node NULL NULL information_schema check_constraint_routine_usage table node NULL NULL information_schema check_constraints table node NULL NULL @@ -311,7 +311,7 @@ information_schema type_privileges table node NULL NU information_schema udt_privileges table node NULL NULL information_schema usage_privileges table node NULL NULL information_schema user_attributes table node NULL NULL -information_schema user_defined_types table node NULL NULL +information_schema user_defined_types view node NULL NULL information_schema user_mapping_options table node NULL NULL information_schema user_mappings table node NULL NULL information_schema user_privileges table node NULL NULL @@ -6119,3 +6119,102 @@ NULL public test pg_catalog covar_pop_49 test NULL root test pg_catalog covar_pop_49 test pg_catalog covar_pop EXECUTE NO subtest end + +subtest user_defined_types + +statement ok +CREATE TYPE u AS (ufoo int, ubar int); + +query TTBTTTB colnames,rowsort +SHOW COLUMNS FROM information_schema.user_defined_types +---- +column_name data_type is_nullable column_default generation_expression indices is_hidden +user_defined_type_catalog STRING true NULL · {} false +user_defined_type_schema STRING true NULL · {} false +user_defined_type_name STRING true NULL · {} false +user_defined_type_category STRING true NULL · {} false +is_instantiable STRING true NULL · {} false +is_final STRING true NULL · {} false +ordering_form STRING true NULL · {} false +ordering_category STRING true NULL · {} false +ordering_routine_catalog STRING true NULL · {} false +ordering_routine_schema STRING true NULL · {} false +ordering_routine_name STRING true NULL · {} false +reference_type STRING true NULL · {} false +data_type STRING true NULL · {} false +character_maximum_length INT8 true NULL · {} false +character_octet_length INT8 true NULL · {} false +character_set_catalog STRING true NULL · {} false +character_set_schema STRING true NULL · {} false +character_set_name STRING true NULL · {} false +collation_catalog STRING true NULL · {} false +collation_schema STRING true NULL · {} false +collation_name STRING true NULL · {} false +numeric_precision INT8 true NULL · {} false +numeric_precision_radix INT8 true NULL · {} false +numeric_scale INT8 true NULL · {} false +datetime_precision INT8 true NULL · {} false +interval_type STRING true NULL · {} false +interval_precision INT8 true NULL · {} false +source_dtd_identifier STRING true NULL · {} false +ref_dtd_identifier STRING true NULL · {} false + +query TTTTTTTTTTTTTIITTTTTTIIIITITT colnames,rowsort +SELECT * FROM information_schema.user_defined_types WHERE user_defined_type_name = 'u' +---- +user_defined_type_catalog user_defined_type_schema user_defined_type_name user_defined_type_category is_instantiable is_final ordering_form ordering_category ordering_routine_catalog ordering_routine_schema ordering_routine_name reference_type data_type character_maximum_length character_octet_length character_set_catalog character_set_schema character_set_name collation_catalog collation_schema collation_name numeric_precision numeric_precision_radix numeric_scale datetime_precision interval_type interval_precision source_dtd_identifier ref_dtd_identifier +test public u STRUCTURED YES NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL + +query TTTTTTTTTTTTTIITTTTTTIIIITITT colnames,rowsort +SELECT * FROM information_schema.user_defined_types WHERE user_defined_type_name = 'dne' +---- +user_defined_type_catalog user_defined_type_schema user_defined_type_name user_defined_type_category is_instantiable is_final ordering_form ordering_category ordering_routine_catalog ordering_routine_schema ordering_routine_name reference_type data_type character_maximum_length character_octet_length character_set_catalog character_set_schema character_set_name collation_catalog collation_schema collation_name numeric_precision numeric_precision_radix numeric_scale datetime_precision interval_type interval_precision source_dtd_identifier ref_dtd_identifier + +subtest end + +subtest attributes + +query TTBTTTB colnames,rowsort +SHOW COLUMNS FROM information_schema.attributes +---- +column_name data_type is_nullable column_default generation_expression indices is_hidden +udt_catalog STRING true NULL · {} false +udt_schema STRING true NULL · {} false +udt_name STRING true NULL · {} false +attribute_name STRING true NULL · {} false +ordinal_position INT8 true NULL · {} false +attribute_default STRING true NULL · {} false +is_nullable STRING true NULL · {} false +data_type STRING true NULL · {} false +character_maximum_length INT8 true NULL · {} false +character_octet_length INT8 true NULL · {} false +character_set_catalog STRING true NULL · {} false +character_set_schema STRING true NULL · {} false +character_set_name STRING true NULL · {} false +collation_catalog STRING true NULL · {} false +collation_schema STRING true NULL · {} false +collation_name STRING true NULL · {} false +numeric_precision INT8 true NULL · {} false +numeric_precision_radix INT8 true NULL · {} false +numeric_scale INT8 true NULL · {} false +datetime_precision INT8 true NULL · {} false +interval_type STRING true NULL · {} false +interval_precision INT8 true NULL · {} false +attribute_udt_catalog STRING true NULL · {} false +attribute_udt_schema STRING true NULL · {} false +attribute_udt_name STRING true NULL · {} false +scope_catalog STRING true NULL · {} false +scope_schema STRING true NULL · {} false +scope_name STRING true NULL · {} false +maximum_cardinality INT8 true NULL · {} false +dtd_identifier STRING true NULL · {} false +is_derived_reference_attribute STRING true NULL · {} false + +query TTTTITTTIITTTTTTIIIITITTTTTTITT colnames,rowsort +SELECT * FROM information_schema.attributes WHERE udt_name = 'u' +---- +udt_catalog udt_schema udt_name attribute_name ordinal_position attribute_default is_nullable data_type character_maximum_length character_octet_length character_set_catalog character_set_schema character_set_name collation_catalog collation_schema collation_name numeric_precision numeric_precision_radix numeric_scale datetime_precision interval_type interval_precision attribute_udt_catalog attribute_udt_schema attribute_udt_name scope_catalog scope_schema scope_name maximum_cardinality dtd_identifier is_derived_reference_attribute +test public u ufoo 1 NULL YES integer NULL NULL NULL NULL NULL NULL NULL NULL 32 2 0 NULL NULL NULL test pg_catalog int4 NULL NULL NULL NULL 1 NO +test public u ubar 2 NULL YES integer NULL NULL NULL NULL NULL NULL NULL NULL 32 2 0 NULL NULL NULL test pg_catalog int4 NULL NULL NULL NULL 2 NO + +subtest end diff --git a/pkg/sql/vtable/information_schema.go b/pkg/sql/vtable/information_schema.go index b8a54caf743f..0bfbaa73baf7 100755 --- a/pkg/sql/vtable/information_schema.go +++ b/pkg/sql/vtable/information_schema.go @@ -10,6 +10,95 @@ package vtable +// InformationSchemaAttributes describes the schema of the +// information_schema.attributes view. +// Postgres: https://www.postgresql.org/docs/16/infoschema-attributes.html +const InformationSchemaAttributes = ` +CREATE VIEW attributes AS + SELECT CAST(current_database() AS TEXT) AS udt_catalog, + CAST(nc.nspname AS TEXT) AS udt_schema, + CAST(c.relname AS TEXT) AS udt_name, + CAST(a.attname AS TEXT) AS attribute_name, + CAST(a.attnum AS INT) AS ordinal_position, + CAST(pg_get_expr(ad.adbin, ad.adrelid) AS TEXT) AS attribute_default, + CAST(CASE WHEN a.attnotnull OR (t.typtype = 'd' AND t.typnotnull) THEN 'NO' ELSE 'YES' END + AS TEXT) + 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 TEXT) + AS data_type, + + CAST( + information_schema._pg_char_max_length(information_schema._pg_truetypid(a, t), information_schema._pg_truetypmod(a, t)) + AS INT) + AS character_maximum_length, + + CAST( + information_schema._pg_char_octet_length(information_schema._pg_truetypid(a, t), information_schema._pg_truetypmod(a, t)) + AS INT) + AS character_octet_length, + + CAST(null AS TEXT) AS character_set_catalog, + CAST(null AS TEXT) AS character_set_schema, + CAST(null AS TEXT) AS character_set_name, + + CAST(CASE WHEN nco.nspname IS NOT NULL THEN current_database() END AS TEXT) AS collation_catalog, + CAST(nco.nspname AS TEXT) AS collation_schema, + CAST(co.collname AS TEXT) AS collation_name, + + CAST( + information_schema._pg_numeric_precision(information_schema._pg_truetypid(a, t), information_schema._pg_truetypmod(a, t)) + AS INT) + AS numeric_precision, + + CAST( + information_schema._pg_numeric_precision_radix(information_schema._pg_truetypid(a, t), information_schema._pg_truetypmod(a, t)) + AS INT) + AS numeric_precision_radix, + + CAST( + information_schema._pg_numeric_scale(information_schema._pg_truetypid(a, t), information_schema._pg_truetypmod(a, t)) + AS INT) + AS numeric_scale, + + CAST( + information_schema._pg_datetime_precision(information_schema._pg_truetypid(a, t), information_schema._pg_truetypmod(a, t)) + AS INT) + AS datetime_precision, + + CAST( + information_schema._pg_interval_type(information_schema._pg_truetypid(a, t), information_schema._pg_truetypmod(a, t)) + AS TEXT) + AS interval_type, + CAST(null AS INT) AS interval_precision, + + CAST(current_database() AS TEXT) AS attribute_udt_catalog, + CAST(nt.nspname AS TEXT) AS attribute_udt_schema, + CAST(t.typname AS TEXT) AS attribute_udt_name, + + CAST(null AS TEXT) AS scope_catalog, + CAST(null AS TEXT) AS scope_schema, + CAST(null AS TEXT) AS scope_name, + + CAST(null AS INT) AS maximum_cardinality, + CAST(a.attnum AS TEXT) AS dtd_identifier, + CAST('NO' AS TEXT) AS is_derived_reference_attribute + + FROM (pg_attribute a LEFT JOIN pg_attrdef ad ON attrelid = adrelid AND attnum = adnum) + JOIN (pg_class c JOIN pg_namespace nc ON (c.relnamespace = nc.oid)) ON a.attrelid = c.oid + JOIN (pg_type t JOIN pg_namespace nt ON (t.typnamespace = nt.oid)) ON a.atttypid = t.oid + LEFT JOIN (pg_collation co JOIN pg_namespace nco ON (co.collnamespace = nco.oid)) + ON a.attcollation = co.oid AND (nco.nspname, co.collname) <> ('pg_catalog', 'default') + + WHERE a.attnum > 0 AND NOT a.attisdropped + AND c.relkind IN ('c') + AND (pg_has_role(c.relowner, 'USAGE') + OR has_type_privilege(c.reltype, 'USAGE'));` + // InformationSchemaColumnUDTUsage describes the schema of the // information_schema.column_udt_usage table. // Postgres: https://www.postgresql.org/docs/current/infoschema-column-udt-usage.html @@ -516,6 +605,49 @@ CREATE TABLE information_schema.table_constraints ( INITIALLY_DEFERRED STRING NOT NULL )` +// InformationSchemaUserDefinedTypes describes the schema of the +// information_schema.user_defined_types view. +const InformationSchemaUserDefinedTypes = ` +CREATE VIEW user_defined_types AS + SELECT CAST(current_database() AS TEXT) AS user_defined_type_catalog, + CAST(n.nspname AS TEXT) AS user_defined_type_schema, + CAST(c.relname AS TEXT) AS user_defined_type_name, + CAST('STRUCTURED' AS TEXT) AS user_defined_type_category, + CAST('YES' AS TEXT) AS is_instantiable, + CAST(null AS TEXT) AS is_final, + CAST(null AS TEXT) AS ordering_form, + CAST(null AS TEXT) AS ordering_category, + CAST(null AS TEXT) AS ordering_routine_catalog, + CAST(null AS TEXT) AS ordering_routine_schema, + CAST(null AS TEXT) AS ordering_routine_name, + CAST(null AS TEXT) AS reference_type, + CAST(null AS TEXT) AS data_type, + CAST(null AS INT) AS character_maximum_length, + CAST(null AS INT) AS character_octet_length, + CAST(null AS TEXT) AS character_set_catalog, + CAST(null AS TEXT) AS character_set_schema, + CAST(null AS TEXT) AS character_set_name, + CAST(null AS TEXT) AS collation_catalog, + CAST(null AS TEXT) AS collation_schema, + CAST(null AS TEXT) AS collation_name, + CAST(null AS INT) AS numeric_precision, + CAST(null AS INT) AS numeric_precision_radix, + CAST(null AS INT) AS numeric_scale, + CAST(null AS INT) AS datetime_precision, + CAST(null AS TEXT) AS interval_type, + CAST(null AS INT) AS interval_precision, + CAST(null AS TEXT) AS source_dtd_identifier, + CAST(null AS TEXT) AS ref_dtd_identifier + + FROM pg_namespace n, pg_class c, pg_type t + + WHERE n.oid = c.relnamespace + AND t.typrelid = c.oid + AND c.relkind = 'c' + AND (pg_has_role(t.typowner, 'USAGE') + OR has_type_privilege(t.oid, 'USAGE')); +` + // InformationSchemaUserPrivileges describes the schema of the // information_schema.user_privileges table. const InformationSchemaUserPrivileges = ` @@ -757,42 +889,6 @@ CREATE TABLE information_schema.role_column_grants ( is_grantable STRING )` -// InformationSchemaAttributes is an empty table in the information_schema that is not implemented yet -const InformationSchemaAttributes = ` -CREATE TABLE information_schema.attributes ( - udt_catalog STRING, - udt_schema STRING, - udt_name STRING, - attribute_name STRING, - ordinal_position INT, - attribute_default STRING, - is_nullable STRING, - data_type STRING, - character_maximum_length INT, - character_octet_length INT, - character_set_catalog STRING, - character_set_schema STRING, - character_set_name STRING, - collation_catalog STRING, - collation_schema STRING, - collation_name STRING, - numeric_precision INT, - numeric_precision_radix INT, - numeric_scale INT, - datetime_precision INT, - interval_type STRING, - interval_precision INT, - attribute_udt_catalog STRING, - attribute_udt_schema STRING, - attribute_udt_name STRING, - scope_catalog STRING, - scope_schema STRING, - scope_name STRING, - maximum_cardinality INT, - dtd_identifier STRING, - is_derived_reference_attribute STRING -)` - // InformationSchemaDomainConstraints is an empty table in the information_schema that is not implemented yet const InformationSchemaDomainConstraints = ` CREATE TABLE information_schema.domain_constraints ( @@ -1034,40 +1130,6 @@ CREATE TABLE information_schema.processlist ( db STRING )` -// InformationSchemaUserDefinedTypes is an empty table in the information_schema that is not implemented yet -const InformationSchemaUserDefinedTypes = ` -CREATE TABLE information_schema.user_defined_types ( - user_defined_type_catalog STRING, - user_defined_type_schema STRING, - user_defined_type_name STRING, - user_defined_type_category STRING, - is_instantiable STRING, - is_final STRING, - ordering_form STRING, - ordering_category STRING, - ordering_routine_catalog STRING, - ordering_routine_schema STRING, - ordering_routine_name STRING, - reference_type STRING, - data_type STRING, - character_maximum_length INT, - character_octet_length INT, - character_set_catalog STRING, - character_set_schema STRING, - character_set_name STRING, - collation_catalog STRING, - collation_schema STRING, - collation_name STRING, - numeric_precision INT, - numeric_precision_radix INT, - numeric_scale INT, - datetime_precision INT, - interval_type STRING, - interval_precision INT, - source_dtd_identifier STRING, - ref_dtd_identifier STRING -)` - // InformationSchemaTriggeredUpdateColumns is an empty table in the information_schema that is not implemented yet const InformationSchemaTriggeredUpdateColumns = ` CREATE TABLE information_schema.triggered_update_columns (