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.

2
  • Can you not recreate the views? Commented May 27, 2015 at 16:33
  • Was trying to avoid having to do that, as it'll be a lot of overhead... Commented May 27, 2015 at 17:05

1 Answer 1

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 $$
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.