Check if a user-defined type already exists in PostgreSQL

后端 未结 10 1582
离开以前
离开以前 2020-12-29 01:43

Say I have created some user-defined types in the DB,

i.e. CREATE TYPE abc ...

Is it then possible to determine if the user-defined type exists

10条回答
  •  旧时难觅i
    2020-12-29 02:45

    Indeed, Postgres does not have CREATE OR REPLACE functionality for types. So the best approach is to drop it:

    DROP TYPE IF EXISTS YOUR_TYPE;
    CREATE TYPE YOUR_TYPE AS (
        id      integer,
        field   varchar
    );
    

    Simple solution is always the best one.

提交回复
热议问题