Let's say we've defined a postgresql type:
CREATE TYPE my_type AS ENUM('foo', 'bar');
Is there any way to show the type definition after creation ?
I would expect "\d my_type" to show me "ENUM('foo', 'bar')", but it says :
Did not find any relation named "my_type"
The pg_type table doesn't seem to give enough information.
When using PostgreSQL, each ENUM type is registered in the system catalogs and can be used anywhere PostgreSQL expects a type name. Internally, the ENUM values are stored as integers. It is important to realize that each ENUM type in PostgreSQL is registered in the system catalogs.
Enumerated (enum) types are data types that comprise a static, ordered set of values. They are equivalent to the enum types supported in a number of programming languages. An example of an enum type might be the days of the week, or a set of status values for a piece of data.
Postgres stores Enums in the pg_type catalog.
PostgreSQL enums should be used for values that directly impact application control flow. That is, they are for values that have specific meaning to the application code. They are not just data. For example, consider an image conversion system where users can convert images from one format to another.
Check this:
select enum_range(null::my_type)
I think this is a much simpler solution :).
It's \dT you're after, but it doesn't give it as a "CREATE" statement. You use \dD for domains.
\dT+ action.action_status List of data types Schema | Name | Internal name | Size | Elements | Description --------+----------------------+---------------+------+----------+------------- action | action.action_status | action_status | 4 | pending +| | | | | live +| | | | | done +| | | | | notdone | (1 row)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With