Perl:是否有类似于statistics_info的DBI函数来检索FK引用和约束?

Perl:是否有类似于statistics_info的DBI函数来检索FK引用和约束?,perl,postgresql,foreign-keys,dbi,dbd-pg,Perl,Postgresql,Foreign Keys,Dbi,Dbd Pg,在Postgres中的表上执行\d+时,它会列出表架构以及索引,以及将其引用为FK的其他表。例如: Table "public.foo_table" Column | Type | Modifiers | Storage | Description ------------+------+---------------+----------+------------- id | text | | extended |

在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\u 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

到目前为止,我发现:

$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
(和其他)元数据请求而运行的所有查询。从中复制/粘贴以获得所需的查询非常容易。

如果您使用
-E
选项运行psql,它将显示为响应
\d
(和其他)元数据请求而运行的所有查询。从中复制/粘贴以获得所需的查询非常容易。

找到
外键信息
,我会检查它的使用情况,因为它需要6个参数(奇数)自学徽章才能获得@vol7ron:)@stackoverflow:我真的希望你不要删除你的答案,我真的认为它很有用。找到
外键信息
,我会检查一下它是如何使用的,因为它需要6个参数(奇数)自我学习徽章,用于@vol7ron:)@stackoverflow:我真希望你不要删除你的答案,我真的认为它很有用。这可能是一个很好的选择。我已经有查询来检索信息了,我正在寻找一些更干净的东西,虽然这可能是一个很好的选择。我已经有查询来检索信息了,不过我想找一些更干净的东西