Search code examples
postgresqluser-defined-types

How to show user's udt definition in postgresql?


I know the udt definition relies on pg_catalog.pg_type, but is there another table where I can get its columns/elements?


Solution

  • The columns of user defined types can be read from the pg_attribute table:

    SELECT *
    FROM   pg_attribute
    WHERE  attrelid::regclass = 'my_type_schema.my-type_name'::regclass
    

    Where the type name can optionally be schema-qualified. I wrote about pg_attribute and regclass in many related answers. Search for more ...