Re: List tables in reverse dependancy order

From: "Gregory Williamson" <Gregory(dot)Williamson(at)digitalglobe(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: List tables in reverse dependancy order
Date: 2007-08-05 00:00:04
Message-ID: 8B319E5A30FF4A48BE7EEAAF609DB233011B0460@COMAIL01.digitalglobe.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Thanks ... I was afraid it would as messy as it is; unfortunately Oracle seems to have a way to gather at least some of this in one (ugly) SQL command and I was hoping for some equivalent trick.

Greg W.
(apologies for top-posting -- limited mail reader)

-----Original Message-----
From: Tom Lane [mailto:tgl(at)sss(dot)pgh(dot)pa(dot)us]
Sent: Sat 8/4/2007 9:51 AM
To: Gregory Williamson
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: [GENERAL] List tables in reverse dependancy order

"Gregory Williamson" <Gregory(dot)Williamson(at)digitalglobe(dot)com> writes:
> I'm trying to create a procedure that would let me retrieve a list of =
> tables and views in a database that will be used to control the order in =
> which lookup data is created/loaded. So, much simplified, if table =
> references table B, which in turn references table A, we want output to =
> list table A, B and C in that order.

> I'm sure that this exists -- the pg_dump command must use some similar =
> algorithm to decide in which order to load tables, but I can't see to =
> puzzle this out.

pg_dump expends a fair amount of code on this problem; if you want to
handle the general case with circular references and so on, it's not
simple. You could do worse than to run "pg_dump -s" and postprocess
its output.

If you are only interested in simpler cases then you might be able to
find a simpler solution. For instance if you are only worried about
foreign-key linkages then looking into pg_constraint is much the
easiest way to find out about those.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Joshua D. Drake 2007-08-05 01:24:01 Re: v8.2 ... command line interface on Windows
Previous Message Geoffrey 2007-08-04 23:46:14 Re: backend process terminates