Thread: Format Typmod?

Format Typmod?

From
"David E. Wheeler"
Date:
Hey Hackers,

I just had reason to want the way that format_type converts type names (e.g., varchar => character varying) in pgTAP,
butdidn't want the namespace qualification (used by format_type() when the type in question is not visible). I figured
outthat I could get that conversion by simply casting the OID argument to regtype, but then to get the typmod, I still
haveto use format_type() like so: 
   CREATE OR REPLACE FUNCTION display_type ( OID, INTEGER )   RETURNS TEXT AS $$       SELECT $1::regtype || COALESCE(
        substring(pg_catalog.format_type($1, $2), '[(][^)]+[)]$'),       '')   $$ LANGUAGE SQL; 

Is there a saner way to do it than this? That is, is there a better way to get the typmod than by munging the value
returnedby format_type()? 

Thanks,

David