Statement categories
TiDB SQL statements fall into four categories:Data types
Numeric types
String types
CHAR(n), VARCHAR(n), BINARY(n), VARBINARY(n), TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT, TINYBLOB, BLOB, MEDIUMBLOB, LONGBLOB, ENUM, SET
Date and time types
DATE, TIME, DATETIME, TIMESTAMP, YEAR
TIMESTAMP values are stored in UTC and converted to the session time zone on retrieval. DATETIME values are stored as-is with no time zone conversion.JSON type
TiDB supports theJSON type with the same path expression syntax as MySQL 8.0, including functions like JSON_EXTRACT, JSON_SET, JSON_ARRAYAGG, and the -> / ->> operators.
Spatial types
GEOMETRY, POINT, LINESTRING, POLYGON, MULTIPOINT, MULTILINESTRING, MULTIPOLYGON, GEOMETRYCOLLECTION
Spatial index support in TiDB is limited compared to MySQL. Verify your spatial query requirements before relying on spatial indexes in production.
Built-in functions
TiDB supports the majority of MySQL 8.0 built-in functions, organized into these groups:- Aggregate:
COUNT,SUM,AVG,MIN,MAX,GROUP_CONCAT,BIT_AND,BIT_OR,STD,VARIANCE - Window:
ROW_NUMBER,RANK,DENSE_RANK,NTILE,LAG,LEAD,FIRST_VALUE,LAST_VALUE,NTH_VALUE - String:
CONCAT,SUBSTRING,TRIM,REPLACE,UPPER,LOWER,REGEXP_REPLACE,FORMAT - Math:
ROUND,CEIL,FLOOR,ABS,MOD,POWER,SQRT,LOG,RAND - Date/time:
NOW,CURDATE,DATE_FORMAT,DATEDIFF,DATE_ADD,TIMESTAMPDIFF,UNIX_TIMESTAMP - JSON:
JSON_OBJECT,JSON_ARRAY,JSON_EXTRACT,JSON_CONTAINS,JSON_TYPE - Information:
DATABASE,USER,VERSION,TIDB_VERSION,LAST_INSERT_ID
System databases
TiDB-specific extensions
AUTO_RANDOM
AUTO_RANDOM is a TiDB alternative to AUTO_INCREMENT for BIGINT PRIMARY KEY columns. It randomizes the high bits of the generated ID to avoid write hotspots on a single TiKV region.
SHARD_ROW_ID_BITS
For tables without an explicitAUTO_RANDOM or AUTO_INCREMENT primary key, TiDB generates an implicit _tidb_rowid. SHARD_ROW_ID_BITS shards that ID space to spread writes across regions.
TTL tables
TTL (Time To Live) tables automatically delete rows older than a configured interval, removing the need for manual purge jobs.Next steps
DDL
Create and manage tables, indexes, and partitions.
DML
Query and modify row data with SELECT, INSERT, UPDATE, and DELETE.
Transactions
Control transaction boundaries and isolation levels.