From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Robert Treat <xzilla(at)users(dot)sourceforge(dot)net> |
Cc: | Steve Atkins <steve(at)blighty(dot)com>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: Converting varchar() to text |
Date: | 2004-09-17 14:56:36 |
Message-ID: | 21848.1095432996@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Robert Treat <xzilla(at)users(dot)sourceforge(dot)net> writes:
> On Wednesday 15 September 2004 12:29, Steve Atkins wrote:
>> Is there a safe way to convert varchar(n) to text, other than create
>> a new column, update, delete column, rename?
> I wouldn't say it's impossible to do it, but several people have reported
> corruption issues in things like indexes when doing this type of thing in
> 7.4.x.
My recollection is that the things that break worst are views that
reference the changed column; you'll need to drop and recreate those,
with possibly cascading effects to other views.
Indexes and foreign keys involving the changed column should also be
dropped and remade, but that's at least fairly localized.
If you have functions that take or return the table rowtype, you might
have some issues there too.
If you want to try it, I'd suggest making a schema dump of your DB
(pg_dump -s) and trying the process on that in a scratch database.
The actual magic is along the lines of
update pg_attribute set atttypid = 'text'::regtype, atttypmod = -1
where attrelid = 'mytable'::regclass and attname = 'mycol';
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Lars Kellogg-Stedman | 2004-09-17 15:03:48 | Default value if query returns 0 rows? |
Previous Message | John Sidney-Woollett | 2004-09-17 14:47:47 | Re: psql + autocommit |