Re: [HACKERS] How to modify type in table?

From: "Oliver Elphick" <olly(at)lfix(dot)co(dot)uk>
To: "Jaruwan Laongmal" <jaruwan(at)gits(dot)net(dot)th>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: [HACKERS] How to modify type in table?
Date: 2001-01-30 12:22:05
Message-ID: 200101301222.f0UCM5F17760@linda.lfix.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"Jaruwan Laongmal" wrote:
>Would you like to inform me how to modify type in table?
>For example , I define type as varchar(14) , but I want to modify to varcha=
>r(120). How to do this.

There is no facility to do this directly. (Allowing columns to change
their type would possibly involve rewriting the entire table.)

You can use pg_dump to dump either a database or a particular table. Then
you can edit the CREATE TABLE command in the dump output and then create a
new database or table from the dump.

If the table in question is not referenced by any other objects, dump
it (pg_dump -t table database >dump); edit the dump; delete or rename the
old table; and finally restore the dump (psql -d database <dump).

If the table is the target of RI references, triggers, rules and so on, it
is easiest to use pg_dump to dump the whole database, (This is because the
table is referenced by oid, not by name, and recreating the table will
make it seem to disappear from all those references.)

--
Oliver Elphick Oliver(dot)Elphick(at)lfix(dot)co(dot)uk
Isle of Wight http://www.lfix.co.uk/oliver
PGP: 1024R/32B8FAA1: 97 EA 1D 47 72 3F 28 47 6B 7E 39 CC 56 E4 C1 47
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C
========================================
"The Lord knoweth how to deliver the godly out of
temptations, and to reserve the unjust unto the day of
judgment to be punished;" II Peter 2:9

Browse pgsql-sql by date

  From Date Subject
Next Message Frederic Metoz 2001-01-30 15:12:17 binary operators
Previous Message David Richter 2001-01-30 12:14:49 PL/PGSQL function with parameters