Check if a user-defined type already exists in PostgreSQL

后端 未结 10 1575
离开以前
离开以前 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条回答
  •  鱼传尺愫
    2020-12-29 02:27

    Another alternative

    WITH namespace AS(
        SELECT oid 
            FROM pg_namespace 
            WHERE nspname = 'my_schema'
    ),
    type_name AS (
        SELECT 1 type_exist  
            FROM pg_type 
            WHERE typname = 'my_type' AND typnamespace = (SELECT * FROM namespace)
    )
    SELECT EXISTS (SELECT * FROM type_name);
    

提交回复
热议问题