Search Postgresql Archives

Dropping dependent tables

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,
I would like to write a SQL statement to drop all the tables owned by me but a problem I’m struggling with is with referential integrity. The statement I have now to generate the drop statements is

select 'drop table '||tablename||' cascade;' from pg_tables where tableowner='<myuseraccount>';

The generated SQLs above might attempt to drop the parent tables first before the child and to be able to drop all the tables, I had to run the SQL script in multiple iterations. Not very clean.

Can someone advise how I could formulate the SQL to check for table dependencies to generate a SQL script that drops the child tables first before the parent? Or are there any better alternatives?

Thank you.

Tiff

Virus-free. www.avast.com

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux