mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 00:22:29 +00:00
191 lines
58 KiB
Markdown
191 lines
58 KiB
Markdown
---
|
||
slug: /en/sql-reference/ansi
|
||
sidebar_position: 40
|
||
sidebar_label: ANSI Compatibility
|
||
title: "ANSI SQL Compatibility of ClickHouse SQL Dialect"
|
||
---
|
||
|
||
:::note
|
||
This article relies on Table 38, “Feature taxonomy and definition for mandatory features”, Annex F of [ISO/IEC CD 9075-2:2011](https://www.iso.org/obp/ui/#iso:std:iso-iec:9075:-2:ed-4:v1:en:sec:8).
|
||
:::
|
||
|
||
## Differences in Behaviour
|
||
|
||
The following table lists cases when query feature works in ClickHouse, but behaves not as specified in ANSI SQL.
|
||
|
||
| Feature ID | Feature Name | Difference |
|
||
|------------|-----------------------------|-----------------------------------------------------------------------------------------------------------|
|
||
| E011 | Numeric data types | Numeric literal with period is interpreted as approximate (`Float64`) instead of exact (`Decimal`) |
|
||
| E051-05 | Select items can be renamed | Item renames have a wider visibility scope than just the SELECT result |
|
||
| E141-01 | NOT NULL constraints | `NOT NULL` is implied for table columns by default |
|
||
| E011-04 | Arithmetic operators | ClickHouse overflows instead of checked arithmetic and changes the result data type based on custom rules |
|
||
|
||
## Feature Status
|
||
|
||
| Feature ID | Feature Name | Status | Comment |
|
||
|------------|--------------------------------------------------------------------------------------------------------------------------|----------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||
| **E011** | **Numeric data types** | <span class="text-warning">Partial</span> | |
|
||
| E011-01 | INTEGER and SMALLINT data types | <span class="text-success">Yes</span> | |
|
||
| E011-02 | REAL, DOUBLE PRECISION and FLOAT data types data types | <span class="text-success">Yes</span> | |
|
||
| E011-03 | DECIMAL and NUMERIC data types | <span class="text-success">Yes</span> | |
|
||
| E011-04 | Arithmetic operators | <span class="text-success">Yes</span> | |
|
||
| E011-05 | Numeric comparison | <span class="text-success">Yes</span> | |
|
||
| E011-06 | Implicit casting among the numeric data types | <span class="text-danger">No</span> | ANSI SQL allows arbitrary implicit cast between numeric types, while ClickHouse relies on functions having multiple overloads instead of implicit cast |
|
||
| **E021** | **Character string types** | <span class="text-warning">Partial</span> | |
|
||
| E021-01 | CHARACTER data type | <span class="text-success">Yes</span> | |
|
||
| E021-02 | CHARACTER VARYING data type | <span class="text-success">Yes</span> | |
|
||
| E021-03 | Character literals | <span class="text-success">Yes</span> | |
|
||
| E021-04 | CHARACTER_LENGTH function | <span class="text-warning">Partial</span> | No `USING` clause |
|
||
| E021-05 | OCTET_LENGTH function | <span class="text-danger">No</span> | `LENGTH` behaves similarly |
|
||
| E021-06 | SUBSTRING | <span class="text-warning">Partial</span> | No support for `SIMILAR` and `ESCAPE` clauses, no `SUBSTRING_REGEX` variant |
|
||
| E021-07 | Character concatenation | <span class="text-warning">Partial</span> | No `COLLATE` clause |
|
||
| E021-08 | UPPER and LOWER functions | <span class="text-success">Yes</span> | |
|
||
| E021-09 | TRIM function | <span class="text-success">Yes</span> | |
|
||
| E021-10 | Implicit casting among the fixed-length and variable-length character string types | <span class="text-warning">Partial</span> | ANSI SQL allows arbitrary implicit cast between string types, while ClickHouse relies on functions having multiple overloads instead of implicit cast |
|
||
| E021-11 | POSITION function | <span class="text-warning">Partial</span> | No support for `IN` and `USING` clauses, no `POSITION_REGEX` variant |
|
||
| E021-12 | Character comparison | <span class="text-success">Yes</span> | |
|
||
| **E031** | **Identifiers** | <span class="text-warning">Partial</span>| |
|
||
| E031-01 | Delimited identifiers | <span class="text-warning">Partial</span> | Unicode literal support is limited |
|
||
| E031-02 | Lower case identifiers | <span class="text-success">Yes</span> | |
|
||
| E031-03 | Trailing underscore | <span class="text-success">Yes</span> | |
|
||
| **E051** | **Basic query specification** | <span class="text-warning">Partial</span>| |
|
||
| E051-01 | SELECT DISTINCT | <span class="text-success">Yes</span> | |
|
||
| E051-02 | GROUP BY clause | <span class="text-success">Yes</span> | |
|
||
| E051-04 | GROUP BY can contain columns not in `<select list>` | <span class="text-success">Yes</span> | |
|
||
| E051-05 | Select items can be renamed | <span class="text-success">Yes</span> | |
|
||
| E051-06 | HAVING clause | <span class="text-success">Yes</span> | |
|
||
| E051-07 | Qualified \* in select list | <span class="text-success">Yes</span> | |
|
||
| E051-08 | Correlation name in the FROM clause | <span class="text-success">Yes</span> | |
|
||
| E051-09 | Rename columns in the FROM clause | <span class="text-danger">No</span> | |
|
||
| **E061** | **Basic predicates and search conditions** | <span class="text-warning">Partial</span> | |
|
||
| E061-01 | Comparison predicate | <span class="text-success">Yes</span> | |
|
||
| E061-02 | BETWEEN predicate | <span class="text-warning">Partial</span> | No `SYMMETRIC` and `ASYMMETRIC` clause |
|
||
| E061-03 | IN predicate with list of values | <span class="text-success">Yes</span> | |
|
||
| E061-04 | LIKE predicate | <span class="text-success">Yes</span> | |
|
||
| E061-05 | LIKE predicate: ESCAPE clause | <span class="text-danger">No</span> | |
|
||
| E061-06 | NULL predicate | <span class="text-success">Yes</span> | |
|
||
| E061-07 | Quantified comparison predicate | <span class="text-danger">No</span> | |
|
||
| E061-08 | EXISTS predicate | <span class="text-danger">No</span> | |
|
||
| E061-09 | Subqueries in comparison predicate | <span class="text-success">Yes</span> | |
|
||
| E061-11 | Subqueries in IN predicate | <span class="text-success">Yes</span> | |
|
||
| E061-12 | Subqueries in quantified comparison predicate | <span class="text-danger">No</span> | |
|
||
| E061-13 | Correlated subqueries | <span class="text-danger">No</span> | |
|
||
| E061-14 | Search condition | <span class="text-success">Yes</span> | |
|
||
| **E071** | **Basic query expressions** | <span class="text-warning">Partial</span> | |
|
||
| E071-01 | UNION DISTINCT table operator | <span class="text-success">Yes</span> | |
|
||
| E071-02 | UNION ALL table operator | <span class="text-success">Yes</span> | |
|
||
| E071-03 | EXCEPT DISTINCT table operator | <span class="text-danger">No</span> | |
|
||
| E071-05 | Columns combined via table operators need not have exactly the same data type | <span class="text-success">Yes</span> | |
|
||
| E071-06 | Table operators in subqueries | <span class="text-success">Yes</span> | |
|
||
| **E081** | **Basic privileges** | <span class="text-success">Yes</span> |
|
||
| E081-01 | SELECT privilege at the table level | <span class="text-success">Yes</span> |
|
||
| E081-02 | DELETE privilege | |
|
||
| E081-03 | INSERT privilege at the table level | <span class="text-success">Yes</span> |
|
||
| E081-04 | UPDATE privilege at the table level | <span class="text-success">Yes</span> |
|
||
| E081-05 | UPDATE privilege at the column level | |
|
||
| E081-06 | REFERENCES privilege at the table level | | |
|
||
| E081-07 | REFERENCES privilege at the column level | | |
|
||
| E081-08 | WITH GRANT OPTION | <span class="text-success">Yes</span> | |
|
||
| E081-09 | USAGE privilege | | |
|
||
| E081-10 | EXECUTE privilege | | |
|
||
| **E091** | **Set functions** |<span class="text-success">Yes</span> |
|
||
| E091-01 | AVG | <span class="text-success">Yes</span> | |
|
||
| E091-02 | COUNT | <span class="text-success">Yes</span> | |
|
||
| E091-03 | MAX | <span class="text-success">Yes</span> | |
|
||
| E091-04 | MIN | <span class="text-success">Yes</span> | |
|
||
| E091-05 | SUM | <span class="text-success">Yes</span> | |
|
||
| E091-06 | ALL quantifier | <span class="text-success">Yes</span> | |
|
||
| E091-07 | DISTINCT quantifier | <span class="text-success">Yes</span> | Not all aggregate functions supported |
|
||
| **E101** | **Basic data manipulation** | <span class="text-warning">Partial</span> | |
|
||
| E101-01 | INSERT statement | <span class="text-success">Yes</span> | Note: primary key in ClickHouse does not imply the `UNIQUE` constraint |
|
||
| E101-03 | Searched UPDATE statement | <span class="text-warning">Partial</span> | There’s an `ALTER UPDATE` statement for batch data modification |
|
||
| E101-04 | Searched DELETE statement | <span class="text-warning">Partial</span> | There’s an `ALTER DELETE` statement for batch data removal |
|
||
| **E111** | **Single row SELECT statement** | <span class="text-danger">No</span> | |
|
||
| **E121** | **Basic cursor support** | <span class="text-danger">No</span> | |
|
||
| E121-01 | DECLARE CURSOR | <span class="text-danger">No</span> | |
|
||
| E121-02 | ORDER BY columns need not be in select list | <span class="text-success">Yes</span> | |
|
||
| E121-03 | Value expressions in ORDER BY clause | <span class="text-success">Yes</span> | |
|
||
| E121-04 | OPEN statement | <span class="text-danger">No</span> | |
|
||
| E121-06 | Positioned UPDATE statement | <span class="text-danger">No</span> | |
|
||
| E121-07 | Positioned DELETE statement | <span class="text-danger">No</span> | |
|
||
| E121-08 | CLOSE statement | <span class="text-danger">No</span> | |
|
||
| E121-10 | FETCH statement: implicit NEXT | <span class="text-danger">No</span> | |
|
||
| E121-17 | WITH HOLD cursors | <span class="text-danger">No</span> | |
|
||
| **E131** | **Null value support (nulls in lieu of values)** | <span class="text-success">Yes</span> | Some restrictions apply |
|
||
| **E141** | **Basic integrity constraints** | <span class="text-warning">Partial</span> | |
|
||
| E141-01 | NOT NULL constraints | <span class="text-success">Yes</span> | Note: `NOT NULL` is implied for table columns by default |
|
||
| E141-02 | UNIQUE constraint of NOT NULL columns | <span class="text-danger">No</span> | |
|
||
| E141-03 | PRIMARY KEY constraints | <span class="text-warning">Partial</span> | |
|
||
| E141-04 | Basic FOREIGN KEY constraint with the NO ACTION default for both referential delete action and referential update action | <span class="text-danger">No</span> | |
|
||
| E141-06 | CHECK constraint | <span class="text-success">Yes</span> | |
|
||
| E141-07 | Column defaults | <span class="text-success">Yes</span> | |
|
||
| E141-08 | NOT NULL inferred on PRIMARY KEY | <span class="text-success">Yes</span> | |
|
||
| E141-10 | Names in a foreign key can be specified in any order | <span class="text-danger">No</span> | |
|
||
| **E151** | **Transaction support** | <span class="text-danger">No</span> | |
|
||
| E151-01 | COMMIT statement | <span class="text-danger">No</span> | |
|
||
| E151-02 | ROLLBACK statement | <span class="text-danger">No</span> | |
|
||
| **E152** | **Basic SET TRANSACTION statement** | <span class="text-danger">No</span> | |
|
||
| E152-01 | SET TRANSACTION statement: ISOLATION LEVEL SERIALIZABLE clause | <span class="text-danger">No</span> | |
|
||
| E152-02 | SET TRANSACTION statement: READ ONLY and READ WRITE clauses | <span class="text-danger">No</span> | |
|
||
| **E153** | **Updatable queries with subqueries** | <span class="text-success">Yes</span> | |
|
||
| **E161** | **SQL comments using leading double minus** | <span class="text-success">Yes</span> | |
|
||
| **E171** | **SQLSTATE support** | <span class="text-danger">No</span> | |
|
||
| **E182** | **Host language binding** | <span class="text-danger">No</span> | |
|
||
| **F031** | **Basic schema manipulation** | <span class="text-warning">Partial</span>| |
|
||
| F031-01 | CREATE TABLE statement to create persistent base tables | <span class="text-warning">Partial</span> | No `SYSTEM VERSIONING`, `ON COMMIT`, `GLOBAL`, `LOCAL`, `PRESERVE`, `DELETE`, `REF IS`, `WITH OPTIONS`, `UNDER`, `LIKE`, `PERIOD FOR` clauses and no support for user resolved data types |
|
||
| F031-02 | CREATE VIEW statement | <span class="text-warning">Partial</span> | No `RECURSIVE`, `CHECK`, `UNDER`, `WITH OPTIONS` clauses and no support for user resolved data types |
|
||
| F031-03 | GRANT statement | <span class="text-success">Yes</span> | |
|
||
| F031-04 | ALTER TABLE statement: ADD COLUMN clause | <span class="text-success">Yes</span> | No support for `GENERATED` clause and system time period |
|
||
| F031-13 | DROP TABLE statement: RESTRICT clause | <span class="text-danger">No</span> | |
|
||
| F031-16 | DROP VIEW statement: RESTRICT clause | <span class="text-danger">No</span> | |
|
||
| F031-19 | REVOKE statement: RESTRICT clause | <span class="text-danger">No</span> | |
|
||
| **F041** | **Basic joined table** | <span class="text-warning">Partial</span> | |
|
||
| F041-01 | Inner join (but not necessarily the INNER keyword) | <span class="text-success">Yes</span> | |
|
||
| F041-02 | INNER keyword | <span class="text-success">Yes</span> | |
|
||
| F041-03 | LEFT OUTER JOIN | <span class="text-success">Yes</span> | |
|
||
| F041-04 | RIGHT OUTER JOIN | <span class="text-success">Yes</span> | |
|
||
| F041-05 | Outer joins can be nested | <span class="text-success">Yes</span> | |
|
||
| F041-07 | The inner table in a left or right outer join can also be used in an inner join | <span class="text-success">Yes</span> | |
|
||
| F041-08 | All comparison operators are supported (rather than just =) | <span class="text-danger">No</span> | |
|
||
| **F051** | **Basic date and time** | <span class="text-warning">Partial</span> | |
|
||
| F051-01 | DATE data type (including support of DATE literal) | <span class="text-success">Yes</span> | |
|
||
| F051-02 | TIME data type (including support of TIME literal) with fractional seconds precision of at least 0 | <span class="text-danger">No</span> | |
|
||
| F051-03 | TIMESTAMP data type (including support of TIMESTAMP literal) with fractional seconds precision of at least 0 and 6 | <span class="text-success">Yes</span> | |
|
||
| F051-04 | Comparison predicate on DATE, TIME, and TIMESTAMP data types | <span class="text-success">Yes</span> | |
|
||
| F051-05 | Explicit CAST between datetime types and character string types | <span class="text-success">Yes</span> | |
|
||
| F051-06 | CURRENT_DATE | <span class="text-danger">No</span> | `today()` is similar |
|
||
| F051-07 | LOCALTIME | <span class="text-danger">No</span> | `now()` is similar |
|
||
| F051-08 | LOCALTIMESTAMP | <span class="text-danger">No</span> | |
|
||
| **F081** | **UNION and EXCEPT in views** | <span class="text-warning">Partial</span> | |
|
||
| **F131** | **Grouped operations** | <span class="text-warning">Partial</span> | |
|
||
| F131-01 | WHERE, GROUP BY, and HAVING clauses supported in queries with grouped views | <span class="text-success">Yes</span> | |
|
||
| F131-02 | Multiple tables supported in queries with grouped views | <span class="text-success">Yes</span> | |
|
||
| F131-03 | Set functions supported in queries with grouped views | <span class="text-success">Yes</span> | |
|
||
| F131-04 | Subqueries with GROUP BY and HAVING clauses and grouped views | <span class="text-success">Yes</span> | |
|
||
| F131-05 | Single row SELECT with GROUP BY and HAVING clauses and grouped views | <span class="text-danger">No</span> | |
|
||
| **F181** | **Multiple module support** | <span class="text-danger">No</span> | |
|
||
| **F201** | **CAST function** | <span class="text-success">Yes</span> | |
|
||
| **F221** | **Explicit defaults** | <span class="text-danger">No</span> | |
|
||
| **F261** | **CASE expression** | <span class="text-success">Yes</span> | |
|
||
| F261-01 | Simple CASE | <span class="text-success">Yes</span> | |
|
||
| F261-02 | Searched CASE | <span class="text-success">Yes</span> | |
|
||
| F261-03 | NULLIF | <span class="text-success">Yes</span> | |
|
||
| F261-04 | COALESCE | <span class="text-success">Yes</span> | |
|
||
| **F311** | **Schema definition statement** | <span class="text-warning">Partial</span> | |
|
||
| F311-01 | CREATE SCHEMA | <span class="text-warning">Partial</span> | See CREATE DATABASE |
|
||
| F311-02 | CREATE TABLE for persistent base tables | <span class="text-success">Yes</span> | |
|
||
| F311-03 | CREATE VIEW | <span class="text-success">Yes</span> | |
|
||
| F311-04 | CREATE VIEW: WITH CHECK OPTION | <span class="text-danger">No</span> | |
|
||
| F311-05 | GRANT statement | <span class="text-success">Yes</span> | |
|
||
| **F471** | **Scalar subquery values** | <span class="text-success">Yes</span> | |
|
||
| **F481** | **Expanded NULL predicate** | <span class="text-success">Yes</span> | |
|
||
| **F812** | **Basic flagging** | <span class="text-danger">No</span> | |
|
||
| **S011** | **Distinct data types** | | |
|
||
| **T321** | **Basic SQL-invoked routines** | <span class="text-danger">No</span> | |
|
||
| T321-01 | User-defined functions with no overloading | <span class="text-danger">No</span> | |
|
||
| T321-02 | User-defined stored procedures with no overloading | <span class="text-danger">No</span> | |
|
||
| T321-03 | Function invocation | <span class="text-danger">No</span> | |
|
||
| T321-04 | CALL statement | <span class="text-danger">No</span> | |
|
||
| T321-05 | RETURN statement | <span class="text-danger">No</span> | |
|
||
| **T631** | **IN predicate with one list element** | <span class="text-success">Yes</span> | |
|