From: Joe Conway <mail@joeconway.com>
To: nickf@ontko.com
Cc: pgsql-admin <pgsql-admin@postgresql.org>
Cc: Ray Ontko <rayo@ontko.com>
Subject: Re: Is it safe to increase pg_attribute.atttypmod ?
Date: Mon, 20 May 2002 17:49:03 -0700
Message-ID: <3CE9997F.4030307@joeconway.com> (raw)
References: <NEBBLAAHGLEEPCGOBHDGEEPDEPAA.nickf@ontko.com>
Nick Fankhauser wrote:
> Hi-
>
> We need to increase the length of a varchar field, and couldn't find
> a way to do it using "alter table". Since the alternative is copying
> & re-creating a very large table, we starting poking around under
> the hood & found that pg_attribute.atttypmod seems to be always
> equal to the length plus 4 in the case of varchar fields.
Yes, the first 4 bytes are for an integer which represents length, and
the rest is the data itself.
>
> We created a test table and altered the varchar length on a field by
> increasing pg_attribute.atttypmod, and the length seemed to change
> and act as expected.
>
> The update to change a varchar(10) field to varchar(40) looked like
> this:
>
> update pg_attribute set atttypmod = 44 where attrelid = ( select oid
> from pg_class where relname = 'test' ) and attname = 'oldtest' ;
>
> Is this a smart thing to do?
>
> Are there other hidden related bits of data that will come back to
> haunt us later?
>
IIRC, this has been discussed a number of times before on one or another
of the PostgreSQL lists. The short answer, I think, is that the
procedure you describe should work just fine (but I do recommend you
take a look at the past threads on the subject). You may need to be a
bit more careful if you were going the other direction, i.e. varchar(40)
to varchar(10).
There was some talk of embedding this knowledge in an ALTER TABLE ALTER
COLUMN command for 7.3, but I haven't seen anything on that recently.
HTH,
Joe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-admin@postgresql.org
Cc: mail@joeconway.com, nickf@ontko.com, rayo@ontko.com
Subject: Re: Is it safe to increase pg_attribute.atttypmod ?
In-Reply-To: <3CE9997F.4030307@joeconway.com>
References: <NEBBLAAHGLEEPCGOBHDGEEPDEPAA.nickf@ontko.com> <3CE9997F.4030307@joeconway.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox