tencent cloud

Stream Compute Service

Releases Notes and Announcements
Release Notes
Product Introduction
Overview
Strengths
Use Cases
Purchase Guide
Billing Overview
Billing Mode
Refund
Configuration Adjustments
Getting Started
Preparations
Creating a Private Cluster
Creating a SQL Job
Creating a JAR Job
Creating an ETL Job
Creating a Python Job
Operation Guide
Managing Jobs
Developing Jobs
Monitoring Jobs
Job Logs
Events and Diagnosis
Managing Metadata
Managing Checkpoints
Tuning Jobs
Managing Dependencies
Managing Clusters
Managing Permissions
SQL Developer Guide
Overview
Glossary and Data Types
DDL Statements
DML Statements
Merging MySQL CDC Sources
Connectors
SET Statement
Operators and Built-in Functions
Identifiers and Reserved Words
Python Developer Guide
ETL Developer Guide
Overview
Glossary
Connectors
FAQ
Contact Us

CREATE VIEW

PDF
포커스 모드
폰트 크기
마지막 업데이트 시간: 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.

도움말 및 지원

문제 해결에 도움이 되었나요?

피드백