Hi!
Personally I'd also throw in "... and atttypid = 'bpchar'::regtype",because that atttypmod calculation will give you garbage for types other than bpchar and varchar.
I added this:
create or replace function public.ColWidth(p_namespace text,
p_table text, p_field text)
returns int as $f$
select atttypmod-4 from pg_namespace n, pg_class c, pg_attribute a
where n.nspname = p_namespace and
c.relnamespace = n.oid and
c.relname = p_table and
a.attrelid = c.oid and
atttypid = 'bpchar'::regtype and
a.attname = p_field;
$f$ LANGUAGE SQL ;
Tables with same name are in different schemas.
How to change this query so that it searches schemas in set
search_path order and returns column width from it ? In this case
p_namespace parameter can removed.
Or should it replaced with dynamic query like
execute 'select ' || p_field || ' from ' || p_table || ' limit 0'
and get column size from this query result somehow ?
Andrus.