Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include udt and domain information in TypeInfo #134

Open
JonathanLorimer opened this issue Dec 17, 2023 · 1 comment
Open

Include udt and domain information in TypeInfo #134

JonathanLorimer opened this issue Dec 17, 2023 · 1 comment

Comments

@JonathanLorimer
Copy link

JonathanLorimer commented Dec 17, 2023

It would be nice if TypeInfo contained the domain name of a type as well as the underlying udt_name. This would allow better runtime type checking. This information can be retrieved from information_schema.columns:

testdb=# \d information_schema.columns
                               View "information_schema.columns"
          Column          |                Type                | Collation | Nullable | Default
--------------------------+------------------------------------+-----------+----------+---------
 table_catalog            | information_schema.sql_identifier  |           |          |
 table_schema             | information_schema.sql_identifier  |           |          |
 table_name               | information_schema.sql_identifier  |           |          |
 column_name              | information_schema.sql_identifier  |           |          |
 ordinal_position         | information_schema.cardinal_number |           |          |
 column_default           | information_schema.character_data  |           |          |
 is_nullable              | information_schema.yes_or_no       |           |          |
 data_type                | information_schema.character_data  |           |          |
 character_maximum_length | information_schema.cardinal_number |           |          |
 character_octet_length   | information_schema.cardinal_number |           |          |
 numeric_precision        | information_schema.cardinal_number |           |          |
 numeric_precision_radix  | information_schema.cardinal_number |           |          |
 numeric_scale            | information_schema.cardinal_number |           |          |
 datetime_precision       | information_schema.cardinal_number |           |          |
 interval_type            | information_schema.character_data  |           |          |
 interval_precision       | information_schema.cardinal_number |           |          |
 character_set_catalog    | information_schema.sql_identifier  |           |          |
 character_set_schema     | information_schema.sql_identifier  |           |          |
 character_set_name       | information_schema.sql_identifier  |           |          |
 collation_catalog        | information_schema.sql_identifier  |           |          |
 collation_schema         | information_schema.sql_identifier  |           |          |
 collation_name           | information_schema.sql_identifier  |           |          |
 domain_catalog           | information_schema.sql_identifier  |           |          |
 domain_schema            | information_schema.sql_identifier  |           |          |
 domain_name              | information_schema.sql_identifier  |           |          |
 udt_catalog              | information_schema.sql_identifier  |           |          |
 udt_schema               | information_schema.sql_identifier  |           |          |
 udt_name                 | information_schema.sql_identifier  |           |          |
 scope_catalog            | information_schema.sql_identifier  |           |          |
 scope_schema             | information_schema.sql_identifier  |           |          |
 scope_name               | information_schema.sql_identifier  |           |          |
 maximum_cardinality      | information_schema.cardinal_number |           |          |
 dtd_identifier           | information_schema.sql_identifier  |           |          |
 is_self_referencing      | information_schema.yes_or_no       |           |          |
 is_identity              | information_schema.yes_or_no       |           |          |
 identity_generation      | information_schema.character_data  |           |          |
 identity_start           | information_schema.character_data  |           |          |
 identity_increment       | information_schema.character_data  |           |          |
 identity_maximum         | information_schema.character_data  |           |          |
 identity_minimum         | information_schema.character_data  |           |          |
 identity_cycle           | information_schema.yes_or_no       |           |          |
 is_generated             | information_schema.character_data  |           |          |
 generation_expression    | information_schema.character_data  |           |          |
 is_updatable             | information_schema.yes_or_no       |           |          |
@JonathanLorimer
Copy link
Author

We could replicate the behaviour in getTypeInfo' with a query like this:

SELECT 
  pt.oid, 
  pt.typname, 
  pt.typcategory,  
  pt.typdelim, 
  pt.typelem, 
  pt.typrelid, 
  pt2.oid as "domain_id", 
  pt2.typname as "domain_name" 
FROM information_schema.columns c 
JOIN pg_class pc ON pc.relname = c.table_name 
JOIN pg_type pt ON pt.typname = c.udt_name 
LEFT JOIN pg_type pt2 ON pt2.typname = c.domain_name 
WHERE pc.relkind = 'r' AND pc.oid = ?

where ? is the table oid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant