4

Is there any way at all to drop a table in PostgreSQL ignoring dependencies (not using CASCADE)?

I'm attempting to drop and recreate a table in order to add an IDENTITY column (as there seems to be no other way to do this in AWS Redshift), but I've got views that are dependent on the table.

I obviously don't want to have to temporarily modify every dependent view just so that I can drop and recreate the same table with an added column.

Community
  • 1
  • 1
MJ.
  • 1,269
  • 4
  • 12
  • 24

1 Answers1

0

I can't find a way to do this.

I would do something like the following:

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 $$
VynlJunkie
  • 1,953
  • 22
  • 26