From: | "Patrick Hatcher" <PHatcher(at)macys(dot)com> |
---|---|
To: | bhuvan(at)symonds(dot)net |
Cc: | pgsql-novice(at)postgresql(dot)org, pgsql-novice-owner(at)postgresql(dot)org, Ravi AVK <ravi_nunet(at)rediffmail(dot)com> |
Subject: | Re: Need clarifications...... |
Date: | 2003-07-23 16:00:31 |
Message-ID: | OF27EB5784.5FB71FC7-ON88256D6C.005798AA-88256D6C.0058676B@fds.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
Hey thanks for the tip bhuvaneswaran. I don't know how many times we've
had to change the length of a column after a table is in product because of
a management decision. In the past, we've always had to drop the table and
all its related views and recreate them.
Patrick Hatcher
"A.Bhuvaneswaran"
<bhuvan(at)symonds(dot)net> To: Ravi AVK <ravi_nunet(at)rediffmail(dot)com>
Sent by: cc: pgsql-novice(at)postgresql(dot)org
pgsql-novice-owner(at)post Subject: Re: [NOVICE] Need clarifications......
gresql.org
07/23/2003 02:38 AM
> 1. I have created a table by giving varchar(100).
>
> Now if i want to increase or decrease the value, i am unable to do
IMO, there are two methods.
First method:
Update pg_attribute system table and set atttypmod appropriately. Let us
assume your table is 'foo' and column is 'bar' and new length is 100. The
sql is:
=# update pg_attribute set atttymod = 100 + 4 where attname = 'bar' and
attrelid = pg_class.oid and pg_class.relname = 'foo';
Second method:
1) Create new column, bar1 with desired length.
2) Set bar1 = bar.
3) Drop column bar.
4) Rename bar1 to bar.
> 2. Is there any way to change the datatype ie., i want to change
> from varchar(255) to text datatype. Data is present, can delete
> the data but don't want to drop and recreate the same as it will
> make me to recreate the references.
I am not sure, but it works for me. Let us assume your table is 'foo' and
column is 'bar' and old type is varchar and new type is text. The sql is:
=# update pg_attribute set atttypid = pg_type.oid, atttypmod = -1 where
attname = 'bar' and attrelid = pg_class.oid and pg_class.relname = 'foo'
and pg_type.typname = 'text';
The above second method is also applicable here.
regards,
bhuvaneswaran
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster
From | Date | Subject | |
---|---|---|---|
Next Message | Josh Berkus | 2003-07-23 18:28:07 | Re: design/copying a bunch of records |
Previous Message | Joe Conway | 2003-07-23 15:57:38 | Re: Struggling with set-returning functions, seeking advice |