pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Querying dependencies
2+ messages / 2 participants
[nested] [flat]

* Querying dependencies
@ 2023-05-22 18:01  Wells Oliver <wells.oliver@gmail.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Wells Oliver @ 2023-05-22 18:01 UTC (permalink / raw)
  To: pgsql-admin

Sometimes I'll "drop table .." on a replica just to see the list of
dependencies,.. This is quite dumb. What's the simple query I can run to
get the same detail without the idiocy?

-- 
Wells Oliver
wells.oliver@gmail.com <wellsoliver@gmail.com>

^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Querying dependencies
@ 2023-05-22 18:11  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Wells Oliver <wells.oliver@gmail.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2023-05-22 18:11 UTC (permalink / raw)
  To: Wells Oliver <wells.oliver@gmail.com>; +Cc: pgsql-admin

Wells Oliver <wells.oliver@gmail.com> writes:
> Sometimes I'll "drop table .." on a replica just to see the list of
> dependencies,.. This is quite dumb. What's the simple query I can run to
> get the same detail without the idiocy?

Not sure about "simple", but here's an example of looking at the
catalog data for this:

regression=# create table mytable(a int primary key, b text unique);
CREATE TABLE
regression=# create table othertable (a int references mytable);
CREATE TABLE
regression=# select pg_describe_object(classid,objid,objsubid), deptype from pg_depend where refclassid = 'pg_class'::regclass and refobjid = 'mytable'::regclass;
                pg_describe_object                | deptype 
--------------------------------------------------+---------
 type mytable                                     | i
 toast table pg_toast.pg_toast_40635              | i
 constraint mytable_pkey on table mytable         | a
 constraint othertable_a_fkey on table othertable | n
 constraint mytable_b_key on table mytable        | a
(5 rows)

See https://www.postgresql.org/docs/current/catalog-pg-depend.html

In the general case you'd need to worry about indirect
dependencies, so you'd need to embed this in a recursive
CTE.  But tables don't usually have indirect dependencies.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2023-05-22 18:11 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-05-22 18:01 Querying dependencies Wells Oliver <wells.oliver@gmail.com>
2023-05-22 18:11 ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox