如何列出PostgreSQL中的外表?

时间:2012-12-16 15:05:12

标签: sql database postgresql

在PostgreSQL中,运行\ d命令会列出表及其表类型。目前我正在尝试列出我使用外部数据包装器创建的所有外表。列出这些表的查询是什么?

4 个答案:

答案 0 :(得分:3)

根据手册\dE[S+]应该这样做。

http://www.postgresql.org/docs/current/static/app-psql.html

要查看此背后的查询,请使用-e(“echo queries”)选项启动psql。

或使用information_schema.tables视图:http://www.postgresql.org/docs/current/static/infoschema-tables.html

table_type列将为这些表格包含FOREIGN TABLE

答案 1 :(得分:2)

仅查询列出外部表:

select * from information_schema.foreign_tables

答案 2 :(得分:1)

您也可以使用以下命令:

\detr

答案 3 :(得分:0)

SELECT tc.table_name , ctu.table_name  
FROM information_schema.table_constraints tc  
inner join information_schema.constraint_table_usage ctu on ctu.constraint_name = tc.constraint_name  
where constraint_type = 'FOREIGN KEY'