tencent cloud

All product documents
Stream Compute Service
CREATE VIEW
Last updated: 2023-11-08 15:29:24
CREATE VIEW
Last updated: 2023-11-08 15:29:24
You can use the CREATE VIEW statement to create a view. A view is a virtual table that is generated based on a SELECT statement. It is useful in scenarios such as type conversion, column conversion, virtual columns, and long code splitting.

Syntax

CREATE VIEW view name AS
SELECT clause

Example 1

Create a view with the name "MyView":
CREATE VIEW MyView AS
SELECT s1.time_, s1.client_ip, s1.uri, s1.protocol_version, s2.status_code, s2.date_
FROM KafkaSource1 AS s1, KafkaSource2 AS s2
WHERE s1.time_ = s2.time_ AND s1.client_ip = s2.client_ip;

Example 2

Due to reasons such as large data volumes or the use of specific function types, you may need to use data types such as TINYINT and SMALLINT. Such data types are not recognized by Kafka and some other data sources. In such cases, you can use the CREATE VIEW statement together with the type conversion function CAST() (see Type Conversion Functions) to define a virtual table and use it as the data source.
Define a view named "KafkaSource2" to convert the status_code column, whose data type is BIGINT, to the data type VARCHAR:
CREATE VIEW KafkaSource2 AS
SELECT
`time_`,
`client_ip`,
`method`,
CAST(`status_code` AS VARCHAR) AS status_code,
FROM KafkaSource1;
Note
Some CAST() conversions, for example, from BIGINT to INTEGER or BIGINT to TINYINT, may lead to loss of precision.
To convert between string (VARCHAR) and timestamp (TIMESTAMP), see TO_TIMESTAMP and DATE_FORMAT functions in Date and Time Functions.
Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

7x24 Phone Support
Hong Kong, China
+852 800 906 020 (Toll Free)
United States
+1 844 606 0804 (Toll Free)
United Kingdom
+44 808 196 4551 (Toll Free)
Canada
+1 888 605 7930 (Toll Free)
Australia
+61 1300 986 386 (Toll Free)
EdgeOne hotline
+852 300 80699
More local hotlines coming soon