Renaming table is affecting views

From: Александр Кайданник <kaydannik(dot)a(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Renaming table is affecting views
Date: 2014-04-18 09:25:57
Message-ID: CAD_EgNJe=HONhi5KUsyYmEOACK6x-2HSHQ=s3cAtFRPiWacSbQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hello.
I need to swap two tables behind view:
And when i am renaming table - its affecting view.

For example:

CREATE TABLE verybigtable (id integer primary key, names varchar(10));
CREATE TABLE inactive_verybigtable (id integer primary key, names
varchar(10));
CREATE VIEW showdata AS (SELECT id, names FROM verybigtable);

postgres=# \d+ showdata
View "public.showdata"
Column | Type | Modifiers | Storage | Description
--------+-----------------------+-----------+----------+-------------
id | integer | | plain |
names | character varying(10) | | extended |
View definition:
SELECT verybigtable.id, verybigtable.names
FROM verybigtable;

And at moment i need to swipe table behind view.

ALTER TABLE verybigtable RENAME TO verybigtable_swiping; //giving
temporarly name for table
ALTER TABLE inactive_verybigtable RENAME TO verybigtable; //rename
inactive_ table to normal
ALTER TABLE verybigtable_swiping RENAME TO inactive_verybigtable; //rename
temporarly to active

But, view now also changed.And its problem for me.

postgres=# \d+ showdata
View "public.showdata"
Column | Type | Modifiers | Storage | Description
--------+-----------------------+-----------+----------+-------------
id | integer | | plain |
names | character varying(10) | | extended |
View definition:
SELECT verybigtable.id, verybigtable.names
FROM inactive_verybigtable verybigtable;

How to prevent it without recreating view each time ?
Thanks

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Albe Laurenz 2014-04-18 09:42:15 Re: Renaming table is affecting views
Previous Message Anderson Amaral 2014-04-16 13:17:31 Running psql queries on Excel without Power Query