information schema 是一个特殊的模式,其中包含当前数据库中定义的对象的标准视图。
information schema 在 PostgreSQL 7.4 中引入。
用法
information schema 提供了一种几乎符合 SQL 标准的方式来访问 PostgreSQL 数据库对象的元数据,该方式在主要版本之间应该是稳定的。这比通过 PostgreSQL 的 系统目录 表和视图可用的接口更稳定,但它不包含关于 PostgreSQL 特有功能的信息。
变更历史
进行中
- PostgreSQL 17
element_types视图中删除了domain_default列(提交 78806a95)
- PostgreSQL 16
- 支持 SQL:2023(提交 f275af8c)
- PostgreSQL 14
- 添加了例程使用表作为占位符(提交 f40c6969)
- PostgreSQL 12
- PostgreSQL 9.4
- PostgreSQL 9.2
- PostgreSQL 9.0
- 添加了函数
aclexplode()以加速信息模式视图(提交 36f887c4)
- 添加了函数
- PostgreSQL 8.2
- 支持 SQL:2003(提交 f7ae9004)
- PostgreSQL 8.0
- 在
information_schema.parameters中支持命名参数(提交 9d888807)
- 在
- PostgreSQL 7.4
- 已添加(初始提交 1b42ad7e)
示例
由 information_schema.tables 视图公开的表的基元数据
postgres=# CREATE TABLE foo (id int); CREATE TABLE postgres=# SELECT * FROM information_schema.tables WHERE table_name='foo'; -[ RECORD 1 ]----------------+----------- table_catalog | postgres table_schema | public table_name | foo table_type | BASE TABLE self_referencing_column_name | reference_generation | user_defined_type_catalog | user_defined_type_schema | user_defined_type_name | is_insertable_into | YES is_typed | NO commit_action |
参考资料
- PostgreSQL 文档: 信息模式
