Changing the size of a varchar field

Started by Eric Ridgealmost 22 years ago3 messagesgeneral
Jump to latest
#1Eric Ridge
ebr@tcdi.com

Using PG 7.3.x, how stupid is this:

UPDATE pg_attribute SET atttypmod=<new size + 4> WHERE ....;

I had to do this on a database, and surprisingly it seems to have
worked just fine. The columns accept a larger value, the existing
values are still intact, and I've seen no other strange errors...

Am I living dangerously, or is this an "okay" thing to do?

eric

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Eric Ridge (#1)
Re: Changing the size of a varchar field

Eric Ridge <ebr@tcdi.com> writes:

Using PG 7.3.x, how stupid is this:
UPDATE pg_attribute SET atttypmod=<new size + 4> WHERE ....;

It'll work okay for a varchar column (not char) at least as far as the
table itself is concerned. I think there are some issues for views
referencing the column, possibly also indexes.

regards, tom lane

#3Eric Ridge
ebr@tcdi.com
In reply to: Tom Lane (#2)
Re: Changing the size of a varchar field

On May 6, 2004, at 12:40 PM, Tom Lane wrote:

Eric Ridge <ebr@tcdi.com> writes:

Using PG 7.3.x, how stupid is this:
UPDATE pg_attribute SET atttypmod=<new size + 4> WHERE ....;

It'll work okay for a varchar column (not char) at least as far as the
table itself is concerned. I think there are some issues for views
referencing the column, possibly also indexes.

We haven't discovered any issues. We do in fact have views sitting
infront of the these tables (w/ a bunch of update/insert rules too!)
and indexes. All seems to be well.

Can you speculate on what the issue would be? Perceived data loss (ie,
values that exceed the original size are truncated)? Inability to
update? Index scans not returning rows? Or would it be some kind of
fail-fast ERROR:?

eric