3

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 ?

Peter Mølgaard Pallesen
  • 1,470
  • 1
  • 15
  • 26

1 Answers1

7

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;
Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263