pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Emi Lu <emilu@encs.concordia.ca>
To: pgsql-sql@postgresql.org
Cc: Marcin Stępnicki <mstepnicki@gmail.com>
Subject: Re: alter column from varchar(32) to varchar(255) without view re-creation
Date: Thu, 14 May 2009 14:33:41 -0400
Message-ID: <4A0C6405.20609@encs.concordia.ca> (raw)
In-Reply-To: <49C25CAA.409@encs.concordia.ca>
References: <49A411D6.8080909@encs.concordia.ca>
	<179149fe0902240809x2ee73eacy3b684d3761b04b03@mail.gmail.com>
	<49C25CAA.409@encs.concordia.ca>

Emi Lu wrote:
>>> PostgreSQL 8.0.15.
>>> Is there a way that I can easily alter column type from varchar(32) to
>>> varchar(255) but do not have to worry about views dependent on it?
> 
>> You should test it carefully and it is considered a bad practice -
>> I'll probably get sued for recommending this :-), but you may try:
>>
>> SELECT * from pg_attribute where attname = 'colname' and  attrelid =
>> (SELECT oid FROM pg_class WHERE relname='_tablename');
>>
>> UPDATE pg_attribute set atttypmod = 4+_new_length_in_your_case_255
>> where attrelid = _attrelid_from_above_ and attname = 'colname';

Tried this, it worked for table but not view.

E.g.,
====================================================
T1(col1 varchar(64)... );
create view v1 as select * from T1;


update pg_attribute set atttypmod = 4+ 128 where ....
\d T1
    col1  varchar(128) ============== [OK]

\d v1
    col1  varchar(64)  ============== [did not change?]

So, it does not really update all dependencies?

Thanks a lot!

--
Lu Ying







Message-ID: <4A0C6405.20609@encs.concordia.ca>
Permalink:  ../4A0C6405.20609@encs.concordia.ca/
Also on:    postgresql.org/message-id/4A0C6405.20609@encs.concordia.ca

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: emilu@encs.concordia.ca, mstepnicki@gmail.com
  Subject: Re: alter column from varchar(32) to varchar(255) without view re-creation
  In-Reply-To: <4A0C6405.20609@encs.concordia.ca>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox