| From: | Michael Paquier <michael(dot)paquier(at)gmail(dot)com> |
|---|---|
| To: | emilu(at)encs(dot)concordia(dot)ca |
| Cc: | pgsql-general <pgsql-general(at)postgresql(dot)org> |
| Subject: | Re: Alter column with views depended on it without drop views |
| Date: | 2014-03-20 00:07:28 |
| Message-ID: | CAB7nPqTLmMn1LTb5WE0v0dO57iP0U73yKwzbZytAXDF1CAWLZg@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
On Wed, Mar 19, 2014 at 11:27 PM, Emi Lu <emilu(at)encs(dot)concordia(dot)ca> wrote:
> Is there a way to change a table column from varchar(n) to varchar with
> views depended on it.
Nope. You cannot update the data type of a table column if it is used by a view.
=# create table aa (a varchar(4));
CREATE TABLE
=# create view aav as select * from aa;
CREATE VIEW
Time: 13.605 ms
=# alter table aa alter column a set data type varchar;
ERROR: 0A000: cannot alter type of a column used by a view or rule
DETAIL: rule _RETURN on view aav depends on column "a"
LOCATION: ATExecAlterColumnType, tablecmds.c:7814
> The problem is that I do not want to drop and re-create all views
> dependencies. I am looking for a way/command that can change the column type
> and all views will be auto updated as well.
A solution to minimize the impact on users would be to do all those
operations inside the same transaction:
begin;
drop view v1;
[...]
alter table tab alter column col set data type mytype;
create view v1 as select blabla;
[...]
commit;
Regards,
--
Michael
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Michael Paquier | 2014-03-20 00:14:29 | Re: High Level Committers Wanted |
| Previous Message | Adrian Klaver | 2014-03-19 23:48:53 | Re: How to access NEW or OLD field given only the field's name? |