tags:

views:

55

answers:

2

I am trying to find the equivalent SQL of \dT using the information_schema and can't seem to find anything. Does such a thing exist?

Example: If I add the following custom type enum, how can I see it in the information_schema?

CREATE TYPE communication.channels AS ENUM
   ('text_message',
    'email',
    'phone_call',
    'broadcast');

NOTE: I do have the exact SQL used by \dT (retrieved by turning up the logging) but I am looking specifically for a cleaner implementation using the information_schema

A: 

Have a look here: http://www.postgresql.org/docs/current/static/catalog-pg-enum.html

The pg_enum catalogue should have the data you are looking fore

DrColossos
Unfortunately the pg_enum catalog only contains the enum label and not the schema or anything else. So you have to do a join anyways to get the meaningful data
Collin Peters
A: 

For reference, here is the SQL from \dT (pgAdmin uses the same or similar)

SELECT      n.nspname as schema, t.typname as type 
FROM        pg_type t 
LEFT JOIN   pg_catalog.pg_namespace n ON n.oid = t.typnamespace 
WHERE       (t.typrelid = 0 OR (SELECT c.relkind = 'c' FROM pg_catalog.pg_class c WHERE c.oid = t.typrelid)) 
AND     NOT EXISTS(SELECT 1 FROM pg_catalog.pg_type el WHERE el.oid = t.typelem AND el.typarray = t.oid)
AND     n.nspname NOT IN ('pg_catalog', 'information_schema')
Collin Peters