Re: ALTER column TYPE varying question

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Paolo Negri" <hungrylist(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: ALTER column TYPE varying question
Date: 2007-03-12 16:20:30
Message-ID: 16573.1173716430@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Paolo Negri" <hungrylist(at)gmail(dot)com> writes:
> I need to increase the length of a string field using version 8.1

8.1.what?

> After executing
> ALTER TABLE mytable ALTER COLUMN mycolumn TYPE varchar(120)
> I can see the column definition correctly changes and I can insert
> rows with longer data in mycolumn.
> But when I try to update data which were in the table before the ALTER
> TABLE I get
> "ERROR: value too long for type character varying(60)"

Please provide a self-contained test case. It works in simple cases:

regression=# create table mytable (mycolumn varchar(60));
CREATE TABLE
regression=# insert into mytable values ('foo');
INSERT 0 1
regression=# ALTER TABLE mytable ALTER COLUMN mycolumn TYPE varchar(120);
ALTER TABLE
regression=# update mytable set mycolumn = repeat('x',100);
UPDATE 1
regression=#

It sounds like you have a case where the old table definition is still
reflected in a cached plan ...

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Harald Armin Massa 2007-03-12 16:22:22 Re: Tracking disk writes? (again)
Previous Message Erik Jones 2007-03-12 16:14:14 Tracking disk writes? (again)