create function create_newtype_text(qualified_name text) returns void language plpgsql as $$ begin execute concat('create type ', qualified_name, ' as (str text);'); execute concat( 'create function ' , qualified_name || '_to_string(val ' || qualified_name || ')' , E' returns text language sql as \'select (val.str);\';' ); execute concat( 'create function ' , qualified_name || '_of_string(val text)' , ' returns ' || qualified_name || E' language sql as \'select row(val);\';' ); end; $$;