When performing a \d+
on a table within Postgres, it lists the table schema along with the indexes, as well as other tables that reference it as a FK. Example:
Table "public.foo_table"
Column | Type | Modifiers | Storage | Description
------------+------+---------------+----------+-------------
id | text | | extended |
foo | text | | extended |
bar | text | | extended |
Indexes:
"foo_table_id_idx" btree (id)
"foo_table_foobar_idx" btree (foo,bar)
Foreign-key constraints:
"foo_table_bar_fk" FOREIGN KEY (bar) REFERENCES public.bar_table(id)
Referenced by:
TABLE "public.bar_table" CONSTRAINT "bar_table_foo_fk" FOREIGN KEY (foo) REFERENCES public.foo_table(foo)
Has OIDs: no
You can do something $dbh->statistics_info(...)
to retrieve the index information. Is there something similar to retrieve the FK info (references and referenced-by)?
It seems like my next option is to either issue a ->do()
command, or query the system tables.