I was wondering if there is a quick and efficient way to order tables in PostgreSQL
so that, if I ran a DELETE FROM <table_name>
they would all succeed without breaking referential integrity.
E.g. if the tables were USER -->* ACCOUNT -->* TRANSACTION
, I want to delete first TRANSACTION, then ACCOUNT, then USER because any other order would break the foreign key relationships.
I have done this before with other DBs by querying system tables and building a referential integrity tree in memory of some scripting language. But I was wondering if there is a quick(er) way to produce such a list.