SQL Reference Guide
This section explains the syntax of SQL to perform operations on databases, tables and STables, insert data, select data and use functions. We also provide some tips that can be used in TDengine SQL. If you have previous experience with SQL this section will be fairly easy to understand. If you do not have previous experience with SQL, you'll come to appreciate the simplicity and power of SQL. TDengine SQL has been enhanced in version 3.0, and the query engine has been rearchitected. For information about how TDengine SQL has changed, see Changes in TDengine 3.0.
TDengine SQL is the major interface for users to write data into or query from TDengine. It uses standard SQL syntax and includes extensions and optimizations for time-series data and services. The maximum length of a TDengine SQL statement is 1 MB. Note that keyword abbreviations are not supported. For example, DELETE cannot be entered as DEL.
Syntax Specifications used in this chapter:
- Keywords are given in uppercase, although SQL is not case-sensitive.
- Information that you input is given in lowercase.
- [ ] means optional input, excluding [] itself.
- | means one of a few options, excluding | itself.
- ... means the item prior to it can be repeated multiple times.
To better demonstrate the syntax, usage and rules of TDengine SQL, hereinafter it's assumed that there is a data set of data from electric meters. Each meter collects 3 data measurements: current, voltage, phase. The data model is shown below:
taos> DESCRIBE meters;
Field | Type | Length | Note |
=================================================================================
ts | TIMESTAMP | 8 | |
current | FLOAT | 4 | |
voltage | INT | 4 | |
phase | FLOAT | 4 | |
location | BINARY | 64 | TAG |
groupid | INT | 4 | TAG |
The data set includes the data collected by 4 meters, the corresponding table name is d1001, d1002, d1003 and d1004 based on the data model of TDengine.
ποΈ Data Types
This document describes the data types that TDengine supports.
ποΈ Database
This document describes how to create and perform operations on databases.
ποΈ Table
This document describes how to create and perform operations on standard tables and subtables.
ποΈ Supertable
This document describes how to create and perform operations on supertables.
ποΈ Insert
This document describes the SQL commands and syntax for inserting data into TDengine.
ποΈ Select
This document describes how to query data in TDengine.
ποΈ Tag Index
Use Tag Index to Improve Query Performance
ποΈ Delete Data
This document describes how to delete data from TDengine.
ποΈ Functions
This document describes the standard SQL functions available in TDengine.
ποΈ Time-Series Extensions
This document describes the extended functions specific to time-series data processing available in TDengine.
ποΈ Data Subscription
This document describes the SQL statements related to the data subscription component of TDengine.
ποΈ Stream Processing
This document describes the SQL statements related to the stream processing component of TDengine.
ποΈ Operators
This document describes the SQL operators available in TDengine.
ποΈ JSON Type
This document describes the JSON data type in TDengine.
ποΈ Escape Characters
This document describes the usage of escape characters in TDengine.
ποΈ Name and Size Limits
This document describes the name and size limits in TDengine.
ποΈ Reserved Keywords
This document describes the reserved keywords in TDengine that cannot be used in object names.
ποΈ Cluster
This document describes the SQL statements related to cluster management in TDengine.
ποΈ Metadata
This document describes how to use the INFORMATION_SCHEMA database in TDengine.
ποΈ Statistics
This document describes how to use the PERFORMANCE_SCHEMA database in TDengine.
ποΈ SHOW Statement
This document describes how to use the SHOW statement in TDengine.
ποΈ Access Control
This document describes how to manage users and permissions in TDengine.
ποΈ User-Defined Functions
This document describes the SQL statements related to user-defined functions (UDF) in TDengine.
ποΈ Window Pre-Aggregation
Instructions for using Window Pre-Aggregation
ποΈ Error Recovery
This document describes the SQL statements related to error recovery in TDengine.
ποΈ Changes in TDengine 3.0
This document describes how TDengine SQL has changed in version 3.0 compared with previous versions.
ποΈ JOIN
JOIN Description
ποΈ Configurable Column Compression
Configurable column storage compression method
ποΈ View
Introduction