Hubble的视图不是物化的:它们不存储基础查询的结果。相反,每次使用该视图时都会重新执行基础查询。
所需权限
用户必须具有CREATE权限、SELECT以及视图引用的任何表的权限
语法图
- CreateViewStmt
- IfNotExists
- OrReplace
语法图
| 参数 | 简介 |
|---|---|
IF NOT EXISTS | 仅当不存在同名视图时才创建新视图。请注意,IF NOT EXISTS仅检查视图名称。它不检查现有视图是否与新视图具有相同的列。 |
OR REPLACE | 如果不存在同名视图,则创建一个新视图。如果已存在同名视图,请替换该视图 |
view_name | 要创建的视图的名称,在其数据库中必须是唯一的,并遵循这些标识符规则。 |
CREATE VIEW语句:create view hubble_db.user_info
as
select cust_no, cust_name,cust_card_no from cust_info;show tables from hubble_db; schema_name | table_name | type | owner | estimated_row_count | locality
--------------+------------+-------+-------+---------------------+-----------
public | cust_info | table | root | 0 | NULL
public | user_info | view | root | 0 | NULLviews在信息模式中查询表:select * from hubble_db.information_schema.views; table_catalog | table_schema | table_name | view_definition |
----------------+--------------+------------+-------------------------------------------------------------------------+--------------+--------------+--------------------+----------------------+----------------------+-----------------------------
hubble_db | public | user_info | SELECT cust_no, cust_name, cust_card_no FROM hubble_db.public.cust_info | NULL SELECT子句)作为目标,就像使用存储表一样:select * from hubble_db.user_info;SELECT视图执行的语句,请使用以下SHOW CREATE语句:show create hubble_db.user_info;ALTER VIEW语句:alter view hubble_db.user_info rename to hubble_db.user_info_bak;DROP VIEW语句drop view hubble_db.user_info_bak;