在 Postgres 中对表执行d+
时,它会列出表架构以及索引,以及将其引用为 FK 的其他表。 例:
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
您可以执行某些操作$dbh->statistics_info(...)
来检索索引信息。 是否有类似的东西来检索 FK 信息(引用和引用者)?
似乎我的下一个选择是发出->do()
命令,或者查询系统表。
到目前为止我
发现的:
$dbh->foreign_key_info( pk_cat, pk_schema, pk_tbl
, fk_cat, fk_schema, fk_tbl );
# FK References
$dbh->foreign_key_info( undef , undef , undef
, undef , undef , $table_name );
# FK Referenced By
$dbh->foreign_key_info( undef , undef , $table_name
, undef , undef , undef );
## Putting the schema/catalog info only ensures you are hitting the intended
## table. If you have dupicate tables, or your table is not in the public
## schema it's probably a good idea to include the schema.
## Catalog is generally unnecessary for Postgres
如果使用-E
选项运行psql,它将显示它为响应d
(和其他)元数据请求而运行的所有查询。 从中复制/粘贴以获取所需的查询非常容易。