changing varchar limits

Поиск
Список
Период
Сортировка
Искать

changing varchar limits

От:
Jeff Davis <list-pgsql-general@empires.org>
Дата:
What's the easiest way to change the allowable length of a varchar attribute?

I looked in pg_attribute and noticed that the allowable length of the varchar 
(+4 bytes for the actual length, presumably) was the atttypemod attribute of 
the pg_attribute relation. Is it safe to change that? I would of course need 
to be a superuser.

Regards,
	Jeff

Re: changing varchar limits

От:
Stephan Szabo <sszabo@megazone23.bigpanda.com>
Дата:
On Thu, 1 Aug 2002, Jeff Davis wrote:

> What's the easiest way to change the allowable length of a varchar attribute?
>
> I looked in pg_attribute and noticed that the allowable length of the varchar
> (+4 bytes for the actual length, presumably) was the atttypemod attribute of
> the pg_attribute relation. Is it safe to change that? I would of course need
> to be a superuser.

That should be safe to change.  If you're lowering it, you should make
sure the data fits.

Re: changing varchar limits

От:
Kevin Brannen <kevinb@nurseamerica.net>
Дата:
Stephan Szabo wrote:
> On Thu, 1 Aug 2002, Jeff Davis wrote:
> 
> 
>>What's the easiest way to change the allowable length of a varchar attribute?
>>
>>I looked in pg_attribute and noticed that the allowable length of the varchar
>>(+4 bytes for the actual length, presumably) was the atttypemod attribute of
>>the pg_attribute relation. Is it safe to change that? I would of course need
>>to be a superuser.
> 
> 
> That should be safe to change.  If you're lowering it, you should make
> sure the data fits.

To easily change a column from nullable to not-nullable, is flipping the 
proper attribute all that's required?  Just asking, cause it would be 
very useful until there's an ALTER TABLE equivalent (in 7.3?).

Thanks,
Kevin

Re: changing varchar limits

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Kevin Brannen  writes:
> To easily change a column from nullable to not-nullable, is flipping the 
> proper attribute all that's required?  Just asking, cause it would be 
> very useful until there's an ALTER TABLE equivalent (in 7.3?).

Sure, just flip the bit (though if you're going to the not-nullable
state, it's your responsibility to make sure the existing data is in
fact not null).  This is basically what the 7.3 implementation does.

			regards, tom lane
FAQ