Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to show a user-defined postgresql enumerated type definition?

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.

like image 970
Stéphane Avatar asked Mar 02 '12 15:03

Stéphane


People also ask

Is there enum in Postgres?

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.

What is enumerated type in PostgreSQL?

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.

Where are enums stored Postgres?

Postgres stores Enums in the pg_type catalog.

Should I use Postgres enum?

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.


2 Answers

Check this:

select enum_range(null::my_type) 

I think this is a much simpler solution :).

like image 155
Adam111p Avatar answered Sep 23 '22 04:09

Adam111p


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) 
like image 36
Richard Huxton Avatar answered Sep 23 '22 04:09

Richard Huxton