2015-05-27 50 views
4

有沒有辦法在PostgreSQL中放棄一個表,忽略依賴關係(不使用CASCADE)?刪除表忽略PostgreSQL中的依賴關係?

我試圖刪除並重新創建一個表,以便添加一個IDENTITY列(因爲似乎有no other way to do this in AWS Redshift),但我有依賴於表的視圖。

我顯然不想暫時修改每個從屬視圖,只是爲了讓我可以使用添加的列刪除並重新創建同一個表。

+0

你能不能重現的看法? –

+0

正試圖避免必須這樣做,因爲它會有很多開銷... –

回答

0

我找不到辦法做到這一點。

我會做類似如下:

create table viewSQL 
as select view_definition 
from information_schema.views; 

drop table [table you want to change] cascade; 

do $$ 
declare 
record record ; 
lv_sql text; 
begin 
for record in select view_definition 
       from viewSQL loop 
           execute immediate 'record.view_definition'; 
          end loop; 
end $$