pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedIs it safe to increase pg_attribute.atttypmod ?
4+ messages / 3 participants
[nested] [flat]
* Is it safe to increase pg_attribute.atttypmod ?
@ 2002-05-20 20:56 Nick Fankhauser <nickf@ontko.com>
0 siblings, 2 replies; 4+ messages in thread
From: Nick Fankhauser @ 2002-05-20 20:56 UTC (permalink / raw)
To: pgsql-admin; +Cc: Ray Ontko <rayo@ontko.com>
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.
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?
-Nick
--------------------------------------------------------------------------
Nick Fankhauser nickf@ontko.com Phone 1.765.935.4283 Fax 1.765.962.9788
Ray Ontko & Co. Software Consulting Services http://www.ontko.com/
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Is it safe to increase pg_attribute.atttypmod ?
@ 2002-05-21 00:17 Tom Lane <tgl@sss.pgh.pa.us>
parent: Nick Fankhauser <nickf@ontko.com>
1 sibling, 1 reply; 4+ messages in thread
From: Tom Lane @ 2002-05-21 00:17 UTC (permalink / raw)
To: nickf@ontko.com; +Cc: pgsql-admin; Ray Ontko <rayo@ontko.com>
"Nick Fankhauser" <nickf@ontko.com> writes:
> 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?
Yup, that's the standard hack.
regards, tom lane
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Is it safe to increase pg_attribute.atttypmod ?
@ 2002-05-21 00:49 Joe Conway <mail@joeconway.com>
parent: Nick Fankhauser <nickf@ontko.com>
1 sibling, 0 replies; 4+ messages in thread
From: Joe Conway @ 2002-05-21 00:49 UTC (permalink / raw)
To: nickf@ontko.com; +Cc: pgsql-admin; Ray Ontko <rayo@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
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Is it safe to increase pg_attribute.atttypmod ?
@ 2002-05-21 13:33 Nick Fankhauser <nickf@ontko.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 4+ messages in thread
From: Nick Fankhauser @ 2002-05-21 13:33 UTC (permalink / raw)
To: mail@joeconway.com; Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-admin; Ray Ontko <rayo@ontko.com>
Tom, Joe:
> Yup, that's the standard hack.
Thanks very much! This saved us hours.
-Nick
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2002-05-21 13:33 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-05-20 20:56 Is it safe to increase pg_attribute.atttypmod ? Nick Fankhauser <nickf@ontko.com>
2002-05-21 00:17 ` Tom Lane <tgl@sss.pgh.pa.us>
2002-05-21 13:33 ` Nick Fankhauser <nickf@ontko.com>
2002-05-21 00:49 ` Joe Conway <mail@joeconway.com>
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