list Postgres ENUM type

前端 未结 9 2191
一个人的身影
一个人的身影 2020-12-12 11:57

The suggested query to list ENUM types is great. But, it merely lists of the schema and the typname. How do I list out the actual ENUM values? For

9条回答
  •  南方客
    南方客 (楼主)
    2020-12-12 12:03

    This lists all enum-typed columns and their potential values:

    SELECT
      table_schema || '.' || table_name || '.' || column_name as field_name,
      pg_enum.enumlabel as value
    FROM pg_type
      JOIN pg_enum ON pg_enum.enumtypid = pg_type.oid
      JOIN pg_namespace on pg_type.typnamespace = pg_namespace.oid
      JOIN information_schema.columns ON (information_schema.columns.udt_name = pg_type.typname AND information_schema.columns.udt_schema = pg_namespace.nspname)
    WHERE pg_type.typtype = 'e'
    ORDER BY field_name, pg_enum.enumsortorder;
    

提交回复
热议问题