Re: Alter definition of a column

From: "Shoaib Mir" <shoaibmir(at)gmail(dot)com>
To: "Kelly Burkhart" <kelly(dot)burkhart(at)gmail(dot)com>
Cc: "Martijn van Oosterhout" <kleptog(at)svana(dot)org>, af300wsm(at)gmail(dot)com, pgsql-general(at)postgresql(dot)org
Subject: Re: Alter definition of a column
Date: 2007-01-20 20:32:14
Message-ID: bf54be870701201232k7c7f961m28ec5e450a83e53e@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I haven't used it this way, anyone else who did might be able to comment on
it. Why will you not like to use the ALTER table command? I think a text
should be use in case you don't know the limit for characters (much faster
too in that case I guess) in a column but if you know the limits then you
should be using varchar(n).

-----------------
Shoaib Mir
EnterpriseDB (www.enterprisedb.com)

On 1/20/07, Kelly Burkhart <kelly(dot)burkhart(at)gmail(dot)com> wrote:
>
> On 1/20/07, Shoaib Mir <shoaibmir(at)gmail(dot)com> wrote:
> > Should help --> ALTER TABLE tablename ALTER columname TYPE text;
>
> I was looking for a way to alter a column from varchar(n) to text
> without using the alter command and consequently touching every single
> row. Below is sql which seems to work, but is it advisable to do such
> shenanigans? (are varchar and text the same thing)?
>
> kelly=# create table foo( c1 varchar(4) not null, c2 text not null );
> CREATE TABLE
> kelly=#
> kelly=# update pg_attribute set atttypid=25, atttypmod=-1
> kelly-# where attname = 'c1' and attrelid =
> kelly-# (select oid from pg_class where relname = 'foo');
> UPDATE 1
> kelly=#
> kelly=# \d foo
> Table "public.foo"
> Column | Type | Modifiers
> --------+------+-----------
> c1 | text | not null
> c2 | text | not null
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Josh Williams 2007-01-20 21:12:41 Re: Alter definition of a column
Previous Message Ron Johnson 2007-01-20 19:05:42 Re: Help : Microsoft SQL Server equivalents in