SQL Manual
This document explains the syntax rules supported by TDengine SQL, main query functionalities, supported SQL query functions, and common tips. Readers are expected to have a basic understanding of SQL language. TDengine version 3.0 has made significant improvements and optimizations compared to version 2.x, especially with a complete overhaul of the query engine, leading to many changes in SQL syntax. For detailed changes, please refer to the Syntax Changes in TDengine 3.0 section.
TDengine SQL is the primary tool for users to write and query data in TDengine. It provides standard SQL syntax and has optimized and added many syntaxes and features tailored for time-series data and business characteristics. The maximum length for TDengine SQL statements is 1M. TDengine SQL does not support abbreviations for keywords; for example, DELETE cannot be abbreviated to DEL.
The following conventions are used in this chapter for SQL syntax:
- Keywords are represented in uppercase, but SQL itself does not distinguish between the case of keywords and identifiers.
- User-input content is represented in lowercase letters.
- [ ] indicates that the content is optional but should not include the brackets themselves when inputting.
- | indicates a choice among multiple options, and one can choose one of them, but the pipe character should not be included in the input.
- β¦ indicates that the preceding item can be repeated multiple times.
To better illustrate the rules and characteristics of SQL syntax, this document assumes the existence of a dataset. Using smart meters (meters) as an example, each smart meter collects three measurements: current, voltage, and phase. The modeling is as follows:
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 dataset contains data from 4 smart meters, corresponding to 4 subtables according to TDengine's modeling rules, with names d1001, d1002, d1003, and d1004 respectively.
ποΈ Data Types
TDengine supported data types: Timestamp, Float, JSON type, etc.
ποΈ Manage Databases
Create, delete databases, view and modify database parameters
ποΈ Manage Tables
Various management operations on tables
ποΈ Manage Supertables
Various management operations on supertables
ποΈ Insert Data
Detailed syntax for writing data
ποΈ Query Data
Detailed syntax for querying data
ποΈ Manage Tag Indices
Using tag indexes to improve query performance
ποΈ Delete Data
Delete data records from specified tables or supertables.
ποΈ Functions
List of functions supported by TDengine
ποΈ Time-Series Extensions
TDengine's unique querying capabilities for time series data
ποΈ Manage Topics and Consumer Groups
The data subscription functionality provided by TDengine's message queue
ποΈ Manage Streams
Detailed syntax for SQL related to stream processing
ποΈ Operators
All operators supported by TDengine
ποΈ JSON Data Type
Detailed explanation of how to use JSON types
ποΈ Escape Characters
Detailed rules for using escape characters in TDengine
ποΈ Names & Limits
Legal character set and naming restrictions
ποΈ Reserved Keywords
Detailed list of reserved keywords in TDengine
ποΈ Manage Nodes
Detailed analysis of SQL commands for managing cluster nodes
ποΈ Metadata
The INFORMATION_SCHEMA database stores all metadata information in the system.
ποΈ Performance Data
The Performance_Schema database stores various statistical information in the system
ποΈ SHOW Commands
Complete list of SHOW commands
ποΈ Manage Users
This section discusses basic user management functions.
ποΈ Manage Permissions
Permission management in TDengine consists of user management, database authorization management, and message subscription authorization management. This section focuses on database authorization and subscription authorization.
ποΈ Manage UDFs
Detailed guide on using UDFs
ποΈ Manage TSMAs
Instructions for using window pre-aggregation
ποΈ Troubleshooting
How to terminate problematic connections, queries, and transactions to restore the system to normal
ποΈ Syntax Changes in TDengine 3.0
Syntax change notes for TDengine version 3.0
ποΈ Join Queries
Detailed description of join queries
ποΈ Manage Data Compression
Configurable compression algorithms
ποΈ Manage Views
Starting from TDengine version 3.2.1.0, TDengine Enterprise Edition provides view functionality to simplify operations and enhance sharing capabilities among users.