Forum OpenACS Q&A: Response to resizing (var)char columns in pg

Collapse
Posted by Andrei Popov on
I also suppose that one could define a function like:
create function varchar_resize (
  varchar(100),
  varchar(100),
  integer
) returns integer as '
declare
  p_table_name      alias for $1;
  p_col_name        alias for $2;
  p_desired_length  alias for $3;
  v_dummy           integer;
begin
  update pg_attribute
  set atttypmod = p_desired_length + 4
  where attrelid = (select oid 
                    from pg_class 
                    where relname = p_table_name)
        and attname = p_col_name;
  return 0;
end;
' language 'plpgsql';