docs/en/14-reference/03-taos-sql/27-view.md
Starting from TDengine 3.2.1.0, TDengine Enterprise Edition 1 provides the functionality of views, which simplifies operations and enhances sharing capabilities among users.
A view (View) is essentially a query statement stored in the database. Views (non-materialized views) do not contain data themselves; the specified query statement is dynamically executed only when data is read from the view. When creating a view, we specify a name for it, and then it can be queried and operated on like a regular table. The use of views must follow these rules:
CREATE [ OR REPLACE ] VIEW [db_name.]view_name AS query
Explanation:
SHOW [db_name.]VIEWS;
SHOW CREATE VIEW [db_name.]view_name;
DESCRIBE [db_name.]view_name;
SELECT ... FROM information_schema.ins_views;
DROP VIEW [IF EXISTS] [db_name.]view_name;
View permissions are divided into READ, WRITE, and ALTER. Query operations require READ permission, write operations require WRITE permission, and modification or deletion of the view itself requires ALTER permission.
The specific rules for permission control are shown in the table below:
| No. | Operation | Permission Requirements |
|---|---|---|
| 1 | CREATE VIEW | |
| (create new view) | User has WRITE permission on the database to which the view belongs | |
| and | ||
| User has query permissions on the target database, table, or view of the view, if the object in the query is a view, it must satisfy rule 8 in this table | ||
| 2 | CREATE OR REPLACE VIEW | |
| (overwrite old view) | User has WRITE permission on the database to which the view belongs and has ALTER permission on the old view | |
| and | ||
| User has query permissions on the target database, table, or view of the view, if the object in the query is a view, it must satisfy rule 8 in this table | ||
| 3 | DROP VIEW | User has ALTER permission on the view |
| 4 | SHOW VIEWS | None |
| 5 | SHOW CREATE VIEW | None |
| 6 | DESCRIBE VIEW | None |
| 7 | System table query | None |
| 8 | SELECT FROM VIEW | Operating user has READ permission on the view and the operating user or the effective user of the view has READ permission on the target database, table, or view |
| 9 | INSERT INTO VIEW | Operating user has WRITE permission on the view and the operating user or the effective user of the view has WRITE permission on the target database, table, or view |
| 10 | GRANT/REVOKE | Only root users have permission |
GRANT privileges ON [db_name.]view_name TO user_name
privileges: {
ALL,
| priv_type [, priv_type] ...
}
priv_type: {
READ
| WRITE
| ALTER
}
REVOKE privileges ON [db_name.]view_name FROM user_name
privileges: {
ALL,
| priv_type [, priv_type] ...
}
priv_type: {
READ
| WRITE
| ALTER
}
| SQL Query | SQL Write | STMT Query | STMT Write | Subscription | Stream Computing |
|---|---|---|---|---|---|
| Supported | Not supported | Not supported | Not supported | Supported | Not supported |
Create View
CREATE VIEW view1 AS SELECT _wstart, count(*) FROM table1 INTERVAL(1d);
CREATE VIEW view2 AS SELECT ts, col2 FROM table1;
CREATE VIEW view3 AS SELECT * from view1;
Query Data
SELECT * from view1;
Delete View
DROP VIEW view1;
TDengine Enterprise Edition was renamed to TDengine TSDB-Enterprise starting from version 3.3.7.0 ↩