I have two databases that I want to be able to transfer data between, so I want to import a large schema from one database to the other, where there is allot of enums. So I ran into the problem descripted here SQL: error when creating a foreign table that has an enum column.
So I though I would like to something like "pg_dump enum" to get the enums and transfer them to the other database. But I can't such a command. Can you help me ?
CodePudding user response:
You can export the definitions with a query like this:
SELECT format(
'CREATE TYPE %s AS ENUM (%s);',
enumtypid::regtype,
string_agg(quote_literal(enumlabel), ', ')
)
FROM pg_enum
GROUP BY enumtypid;