tags:

views:

37

answers:

1

How do we copy a domain in old schema to new schema using a procedure in postgresql?

A: 

See the information in pg_type and just use another namespace (schema):

INSERT INTO pg_type 
SELECT 
    typname,
    (SELECT oid FROM pg_namespace WHERE nspname = 'your_schema_name'),
    typowner,
    typlen,
    typbyval,
    typtype,
    typcategory,
    typispreferred,
    typisdefined,
    typdelim,
    typrelid,
    typelem,
    typarray,
    typinput,
    typoutput,
    typreceive,
    typsend,
    typmodin,
    typmodout,
    typanalyze,
    typalign,
    typstorage,
    typnotnull,
    typbasetype,
    typtypmod,
    typndims,
    typdefaultbin,
    typdefault
FROM 
    pg_type 
WHERE 
    typname = 'name_of_your_domain'
AND
    typnamespace = 2200 -- oid of schema public
;

Wrap it in a procedure and you're done.

Frank Heikens