Skip to content

Commit

Permalink
sql: populate information_schema.user_defined_types and attributes
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
annrpom committed Oct 31, 2023
1 parent bc976da commit 12bbf3b
Show file tree
Hide file tree
Showing 4 changed files with 315 additions and 94 deletions.
96 changes: 78 additions & 18 deletions pkg/sql/information_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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") + `
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 12bbf3b

Please sign in to comment.