视图相关操作
最近更新时间: 2024-10-17 17:10:00
- 建立视图。
postgres=# create or replace view tbase_view as select * from tbase;
CREATE VIEW
- \d查视图结构。
postgres=# \d tbase
Table "public.tbase"
Column | Type | Modifiers
--------+---------+-----------
id |integer |
mc |text |
- \d+查看视图结构(包含注释),包含创建视图的sql语句。
postgres=# \d+ tbase_view
View "public.tbase_view"
Column | Type | Modifiers | Storage | Description
--------+---------+-----------+----------+-------------
id |integer | | plain |
mc |text | | extended |
View definition:
SELECT tbase.id,
tbase.mc
FROM tbase;
- \dv查看视图列表。
postgres=# \dv
List of relations
Schema | Name | Type | Owner
--------+-------------------+------+-------
pgxc |t_time_range_view | view | tbase
public | tbase_view | view | tbase
(2 rows)
- \dv+查看视图列表详细信息(包含注释)。
postgres=# \dv+
List of relations
Schema | Name | Type | Owner | Size | Description
--------+-------------------+------+-------+---------+-------------
pgxc |t_time_range_view | view | tbase | 0bytes |
public | tbase_view | view | tbase | 0 bytes | 我的视图
(2 rows)
- \dv+显示某个模式下的所有视图。
postgres=# \dv+ pgxc.*
List of relations
Schema | Name | Type | Owner | Size | Description
--------+-------------------+------+-------+---------+-------------
pgxc |t_time_range_view | view | tbase | 0bytes |
(1 row)
- \dv+视图名显示某个视图的详细信息。
postgres=# \dv+ tbase_view
List of relations
Schema | Name | Type | Owner | Size | Description
--------+------------+------+-------+---------+-------------
public | tbase_view | view | tbase | 0 bytes | 我的视图
(1 row)
- \dv+通配符列出适配的视图。
postgres=# \dv+ t*
List of relations
Schema | Name | Type | Owner | Size | Description
--------+-------------------+------+-------+---------+-------------
pgxc |t_time_range_view | view | tbase | 0bytes |
public | tbase_view | view | tbase | 0 bytes | 我的视图
(2 rows)
postgres=# \dv+ tb*
List of relations
Schema | Name | Type | Owner | Size | Description
--------+------------+------+-------+---------+-------------
public | tbase_view | view | tbase | 0 bytes | 我的视图
(1 row)