SQL language

The page describes the SQL dialect recognized by Calcite’s default SQL parser.

Grammar

SQL grammar in BNF-likeform.

  1. statement:
  2. setStatement
  3. | resetStatement
  4. | explain
  5. | describe
  6. | insert
  7. | update
  8. | merge
  9. | delete
  10. | query
  11. statementList:
  12. statement [ ';' statement ]* [ ';' ]
  13. setStatement:
  14. [ ALTER ( SYSTEM | SESSION ) ] SET identifier '=' expression
  15. resetStatement:
  16. [ ALTER ( SYSTEM | SESSION ) ] RESET identifier
  17. | [ ALTER ( SYSTEM | SESSION ) ] RESET ALL
  18. explain:
  19. EXPLAIN PLAN
  20. [ WITH TYPE | WITH IMPLEMENTATION | WITHOUT IMPLEMENTATION ]
  21. [ EXCLUDING ATTRIBUTES | INCLUDING [ ALL ] ATTRIBUTES ]
  22. [ AS JSON | AS XML ]
  23. FOR ( query | insert | update | merge | delete )
  24. describe:
  25. DESCRIBE DATABASE databaseName
  26. | DESCRIBE CATALOG [ databaseName . ] catalogName
  27. | DESCRIBE SCHEMA [ [ databaseName . ] catalogName ] . schemaName
  28. | DESCRIBE [ TABLE ] [ [ [ databaseName . ] catalogName . ] schemaName . ] tableName [ columnName ]
  29. | DESCRIBE [ STATEMENT ] ( query | insert | update | merge | delete )
  30. insert:
  31. ( INSERT | UPSERT ) INTO tablePrimary
  32. [ '(' column [, column ]* ')' ]
  33. query
  34. update:
  35. UPDATE tablePrimary
  36. SET assign [, assign ]*
  37. [ WHERE booleanExpression ]
  38. assign:
  39. identifier '=' expression
  40. merge:
  41. MERGE INTO tablePrimary [ [ AS ] alias ]
  42. USING tablePrimary
  43. ON booleanExpression
  44. [ WHEN MATCHED THEN UPDATE SET assign [, assign ]* ]
  45. [ WHEN NOT MATCHED THEN INSERT VALUES '(' value [ , value ]* ')' ]
  46. delete:
  47. DELETE FROM tablePrimary [ [ AS ] alias ]
  48. [ WHERE booleanExpression ]
  49. query:
  50. values
  51. | WITH withItem [ , withItem ]* query
  52. | {
  53. select
  54. | selectWithoutFrom
  55. | query UNION [ ALL | DISTINCT ] query
  56. | query EXCEPT [ ALL | DISTINCT ] query
  57. | query MINUS [ ALL | DISTINCT ] query
  58. | query INTERSECT [ ALL | DISTINCT ] query
  59. }
  60. [ ORDER BY orderItem [, orderItem ]* ]
  61. [ LIMIT [ start, ] { count | ALL } ]
  62. [ OFFSET start { ROW | ROWS } ]
  63. [ FETCH { FIRST | NEXT } [ count ] { ROW | ROWS } ONLY ]
  64. withItem:
  65. name
  66. [ '(' column [, column ]* ')' ]
  67. AS '(' query ')'
  68. orderItem:
  69. expression [ ASC | DESC ] [ NULLS FIRST | NULLS LAST ]
  70. select:
  71. SELECT [ STREAM ] [ ALL | DISTINCT ]
  72. { * | projectItem [, projectItem ]* }
  73. FROM tableExpression
  74. [ WHERE booleanExpression ]
  75. [ GROUP BY { groupItem [, groupItem ]* } ]
  76. [ HAVING booleanExpression ]
  77. [ WINDOW windowName AS windowSpec [, windowName AS windowSpec ]* ]
  78. selectWithoutFrom:
  79. SELECT [ ALL | DISTINCT ]
  80. { * | projectItem [, projectItem ]* }
  81. projectItem:
  82. expression [ [ AS ] columnAlias ]
  83. | tableAlias . *
  84. tableExpression:
  85. tableReference [, tableReference ]*
  86. | tableExpression [ NATURAL ] [ ( LEFT | RIGHT | FULL ) [ OUTER ] ] JOIN tableExpression [ joinCondition ]
  87. | tableExpression CROSS JOIN tableExpression
  88. | tableExpression [ CROSS | OUTER ] APPLY tableExpression
  89. joinCondition:
  90. ON booleanExpression
  91. | USING '(' column [, column ]* ')'
  92. tableReference:
  93. tablePrimary
  94. [ FOR SYSTEM_TIME AS OF expression ]
  95. [ matchRecognize ]
  96. [ [ AS ] alias [ '(' columnAlias [, columnAlias ]* ')' ] ]
  97. tablePrimary:
  98. [ [ catalogName . ] schemaName . ] tableName
  99. '(' TABLE [ [ catalogName . ] schemaName . ] tableName ')'
  100. | tablePrimary [ EXTEND ] '(' columnDecl [, columnDecl ]* ')'
  101. | [ LATERAL ] '(' query ')'
  102. | UNNEST '(' expression ')' [ WITH ORDINALITY ]
  103. | [ LATERAL ] TABLE '(' [ SPECIFIC ] functionName '(' expression [, expression ]* ')' ')'
  104. columnDecl:
  105. column type [ NOT NULL ]
  106. values:
  107. VALUES expression [, expression ]*
  108. groupItem:
  109. expression
  110. | '(' ')'
  111. | '(' expression [, expression ]* ')'
  112. | CUBE '(' expression [, expression ]* ')'
  113. | ROLLUP '(' expression [, expression ]* ')'
  114. | GROUPING SETS '(' groupItem [, groupItem ]* ')'
  115. window:
  116. windowName
  117. | windowSpec
  118. windowSpec:
  119. '('
  120. [ windowName ]
  121. [ ORDER BY orderItem [, orderItem ]* ]
  122. [ PARTITION BY expression [, expression ]* ]
  123. [
  124. RANGE numericOrIntervalExpression { PRECEDING | FOLLOWING }
  125. | ROWS numericExpression { PRECEDING | FOLLOWING }
  126. ]
  127. ')'

In insert, if the INSERT or UPSERT statement does not specify alist of target columns, the query must have the same number ofcolumns as the target table, except in certainconformance levels.

In merge, at least one of the WHEN MATCHED and WHEN NOT MATCHED clauses mustbe present.

tablePrimary may only contain an EXTEND clause in certainconformance levels;in those same conformance levels, any column in insert may be replaced bycolumnDecl, which has a similar effect to including it in an EXTEND clause.

In orderItem, if expression is a positive integer n, it denotesthe _n_th item in the SELECT clause.

In query, count and start may each be either an unsigned integer literalor a dynamic parameter whose value is an integer.

An aggregate query is a query that contains a GROUP BY or a HAVINGclause, or aggregate functions in the SELECT clause. In the SELECT,HAVING and ORDER BY clauses of an aggregate query, all expressionsmust be constant within the current group (that is, grouping constantsas defined by the GROUP BY clause, or constants), or aggregatefunctions, or a combination of constants and aggregatefunctions. Aggregate and grouping functions may only appear in anaggregate query, and only in a SELECT, HAVING or ORDER BY clause.

A scalar sub-query is a sub-query used as an expression.If the sub-query returns no rows, the value is NULL; if itreturns more than one row, it is an error.

IN, EXISTS and scalar sub-queries can occurin any place where an expression can occur (such as the SELECT clause,WHERE clause, ON clause of a JOIN, or as an argument to an aggregatefunction).

An IN, EXISTS or scalar sub-query may be correlated; that is, itmay refer to tables in the FROM clause of an enclosing query.

selectWithoutFrom is equivalent to VALUES,but is not standard SQL and is only allowed in certainconformance levels.

MINUS is equivalent to EXCEPT,but is not standard SQL and is only allowed in certainconformance levels.

CROSS APPLY and OUTER APPLY are only allowed in certainconformance levels.

“LIMIT start, count” is equivalent to “LIMIT count OFFSET start”but is only allowed in certainconformance levels.

Keywords

The following is a list of SQL keywords.Reserved keywords are bold.

A,ABS,ABSENT,ABSOLUTE,ACTION,ADA,ADD,ADMIN,AFTER,ALL,ALLOCATE,ALLOW,ALTER,ALWAYS,AND,ANY,APPLY,ARE,ARRAY,ARRAY_MAX_CARDINALITY,AS,ASC,ASENSITIVE,ASSERTION,ASSIGNMENT,ASYMMETRIC,AT,ATOMIC,ATTRIBUTE,ATTRIBUTES,AUTHORIZATION,AVG,BEFORE,BEGIN,BEGIN_FRAME,BEGIN_PARTITION,BERNOULLI,BETWEEN,BIGINT,BINARY,BIT,BLOB,BOOLEAN,BOTH,BREADTH,BY,C,CALL,CALLED,CARDINALITY,CASCADE,CASCADED,CASE,CAST,CATALOG,CATALOG_NAME,CEIL,CEILING,CENTURY,CHAIN,CHAR,CHARACTER,CHARACTERISTICS,CHARACTERS,CHARACTER_LENGTH,CHARACTER_SET_CATALOG,CHARACTER_SET_NAME,CHARACTER_SET_SCHEMA,CHAR_LENGTH,CHECK,CLASSIFIER,CLASS_ORIGIN,CLOB,CLOSE,COALESCE,COBOL,COLLATE,COLLATION,COLLATION_CATALOG,COLLATION_NAME,COLLATION_SCHEMA,COLLECT,COLUMN,COLUMN_NAME,COMMAND_FUNCTION,COMMAND_FUNCTION_CODE,COMMIT,COMMITTED,CONDITION,CONDITIONAL,CONDITION_NUMBER,CONNECT,CONNECTION,CONNECTION_NAME,CONSTRAINT,CONSTRAINTS,CONSTRAINT_CATALOG,CONSTRAINT_NAME,CONSTRAINT_SCHEMA,CONSTRUCTOR,CONTAINS,CONTINUE,CONVERT,CORR,CORRESPONDING,COUNT,COVAR_POP,COVAR_SAMP,CREATE,CROSS,CUBE,CUME_DIST,CURRENT,CURRENT_CATALOG,CURRENT_DATE,CURRENT_DEFAULT_TRANSFORM_GROUP,CURRENT_PATH,CURRENT_ROLE,CURRENT_ROW,CURRENT_SCHEMA,CURRENT_TIME,CURRENT_TIMESTAMP,CURRENT_TRANSFORM_GROUP_FOR_TYPE,CURRENT_USER,CURSOR,CURSOR_NAME,CYCLE,DATA,DATABASE,DATE,DATETIME_INTERVAL_CODE,DATETIME_INTERVAL_PRECISION,DAY,DEALLOCATE,DEC,DECADE,DECIMAL,DECLARE,DEFAULT,DEFAULTS,DEFERRABLE,DEFERRED,DEFINE,DEFINED,DEFINER,DEGREE,DELETE,DENSE_RANK,DEPTH,DEREF,DERIVED,DESC,DESCRIBE,DESCRIPTION,DESCRIPTOR,DETERMINISTIC,DIAGNOSTICS,DISALLOW,DISCONNECT,DISPATCH,DISTINCT,DOMAIN,DOUBLE,DOW,DOY,DROP,DYNAMIC,DYNAMIC_FUNCTION,DYNAMIC_FUNCTION_CODE,EACH,ELEMENT,ELSE,EMPTY,ENCODING,END,END-EXEC,END_FRAME,END_PARTITION,EPOCH,EQUALS,ERROR,ESCAPE,EVERY,EXCEPT,EXCEPTION,EXCLUDE,EXCLUDING,EXEC,EXECUTE,EXISTS,EXP,EXPLAIN,EXTEND,EXTERNAL,EXTRACT,FALSE,FETCH,FILTER,FINAL,FIRST,FIRST_VALUE,FLOAT,FLOOR,FOLLOWING,FOR,FOREIGN,FORMAT,FORTRAN,FOUND,FRAC_SECOND,FRAME_ROW,FREE,FROM,FULL,FUNCTION,FUSION,G,GENERAL,GENERATED,GEOMETRY,GET,GLOBAL,GO,GOTO,GRANT,GRANTED,GROUP,GROUPING,GROUPS,HAVING,HIERARCHY,HOLD,HOUR,IDENTITY,IGNORE,IMMEDIATE,IMMEDIATELY,IMPLEMENTATION,IMPORT,IN,INCLUDING,INCREMENT,INDICATOR,INITIAL,INITIALLY,INNER,INOUT,INPUT,INSENSITIVE,INSERT,INSTANCE,INSTANTIABLE,INT,INTEGER,INTERSECT,INTERSECTION,INTERVAL,INTO,INVOKER,IS,ISODOW,ISOLATION,ISOYEAR,JAVA,JOIN,JSON,JSON_ARRAY,JSON_ARRAYAGG,JSON_EXISTS,JSON_OBJECT,JSON_OBJECTAGG,JSON_QUERY,JSON_VALUE,K,KEY,KEY_MEMBER,KEY_TYPE,LABEL,LAG,LANGUAGE,LARGE,LAST,LAST_VALUE,LATERAL,LEAD,LEADING,LEFT,LENGTH,LEVEL,LIBRARY,LIKE,LIKE_REGEX,LIMIT,LN,LOCAL,LOCALTIME,LOCALTIMESTAMP,LOCATOR,LOWER,M,MAP,MATCH,MATCHED,MATCHES,MATCH_NUMBER,MATCH_RECOGNIZE,MAX,MAXVALUE,MEASURES,MEMBER,MERGE,MESSAGE_LENGTH,MESSAGE_OCTET_LENGTH,MESSAGE_TEXT,METHOD,MICROSECOND,MILLENNIUM,MILLISECOND,MIN,MINUS,MINUTE,MINVALUE,MOD,MODIFIES,MODULE,MONTH,MORE,MULTISET,MUMPS,NAME,NAMES,NANOSECOND,NATIONAL,NATURAL,NCHAR,NCLOB,NESTING,NEW,NEXT,NO,NONE,NORMALIZE,NORMALIZED,NOT,NTH_VALUE,NTILE,NULL,NULLABLE,NULLIF,NULLS,NUMBER,NUMERIC,OBJECT,OCCURRENCES_REGEX,OCTETS,OCTET_LENGTH,OF,OFFSET,OLD,OMIT,ON,ONE,ONLY,OPEN,OPTION,OPTIONS,OR,ORDER,ORDERING,ORDINALITY,OTHERS,OUT,OUTER,OUTPUT,OVER,OVERLAPS,OVERLAY,OVERRIDING,PAD,PARAMETER,PARAMETER_MODE,PARAMETER_NAME,PARAMETER_ORDINAL_POSITION,PARAMETER_SPECIFIC_CATALOG,PARAMETER_SPECIFIC_NAME,PARAMETER_SPECIFIC_SCHEMA,PARTIAL,PARTITION,PASCAL,PASSING,PASSTHROUGH,PAST,PATH,PATTERN,PER,PERCENT,PERCENTILE_CONT,PERCENTILE_DISC,PERCENT_RANK,PERIOD,PERMUTE,PLACING,PLAN,PLI,PORTION,POSITION,POSITION_REGEX,POWER,PRECEDES,PRECEDING,PRECISION,PREPARE,PRESERVE,PREV,PRIMARY,PRIOR,PRIVILEGES,PROCEDURE,PUBLIC,QUARTER,RANGE,RANK,READ,READS,REAL,RECURSIVE,REF,REFERENCES,REFERENCING,REGR_AVGX,REGR_AVGY,REGR_COUNT,REGR_INTERCEPT,REGR_R2,REGR_SLOPE,REGR_SXX,REGR_SXY,REGR_SYY,RELATIVE,RELEASE,REPEATABLE,REPLACE,RESET,RESPECT,RESTART,RESTRICT,RESULT,RETURN,RETURNED_CARDINALITY,RETURNED_LENGTH,RETURNED_OCTET_LENGTH,RETURNED_SQLSTATE,RETURNING,RETURNS,REVOKE,RIGHT,ROLE,ROLLBACK,ROLLUP,ROUTINE,ROUTINE_CATALOG,ROUTINE_NAME,ROUTINE_SCHEMA,ROW,ROWS,ROW_COUNT,ROW_NUMBER,RUNNING,SAVEPOINT,SCALAR,SCALE,SCHEMA,SCHEMA_NAME,SCOPE,SCOPE_CATALOGS,SCOPE_NAME,SCOPE_SCHEMA,SCROLL,SEARCH,SECOND,SECTION,SECURITY,SEEK,SELECT,SELF,SENSITIVE,SEQUENCE,SERIALIZABLE,SERVER,SERVER_NAME,SESSION,SESSION_USER,SET,SETS,SHOW,SIMILAR,SIMPLE,SIZE,SKIP,SMALLINT,SOME,SOURCE,SPACE,SPECIFIC,SPECIFICTYPE,SPECIFIC_NAME,SQL,SQLEXCEPTION,SQLSTATE,SQLWARNING,SQL_BIGINT,SQL_BINARY,SQL_BIT,SQL_BLOB,SQL_BOOLEAN,SQL_CHAR,SQL_CLOB,SQL_DATE,SQL_DECIMAL,SQL_DOUBLE,SQL_FLOAT,SQL_INTEGER,SQL_INTERVAL_DAY,SQL_INTERVAL_DAY_TO_HOUR,SQL_INTERVAL_DAY_TO_MINUTE,SQL_INTERVAL_DAY_TO_SECOND,SQL_INTERVAL_HOUR,SQL_INTERVAL_HOUR_TO_MINUTE,SQL_INTERVAL_HOUR_TO_SECOND,SQL_INTERVAL_MINUTE,SQL_INTERVAL_MINUTE_TO_SECOND,SQL_INTERVAL_MONTH,SQL_INTERVAL_SECOND,SQL_INTERVAL_YEAR,SQL_INTERVAL_YEAR_TO_MONTH,SQL_LONGVARBINARY,SQL_LONGVARCHAR,SQL_LONGVARNCHAR,SQL_NCHAR,SQL_NCLOB,SQL_NUMERIC,SQL_NVARCHAR,SQL_REAL,SQL_SMALLINT,SQL_TIME,SQL_TIMESTAMP,SQL_TINYINT,SQL_TSI_DAY,SQL_TSI_FRAC_SECOND,SQL_TSI_HOUR,SQL_TSI_MICROSECOND,SQL_TSI_MINUTE,SQL_TSI_MONTH,SQL_TSI_QUARTER,SQL_TSI_SECOND,SQL_TSI_WEEK,SQL_TSI_YEAR,SQL_VARBINARY,SQL_VARCHAR,SQRT,START,STATE,STATEMENT,STATIC,STDDEV_POP,STDDEV_SAMP,STREAM,STRUCTURE,STYLE,SUBCLASS_ORIGIN,SUBMULTISET,SUBSET,SUBSTITUTE,SUBSTRING,SUBSTRING_REGEX,SUCCEEDS,SUM,SYMMETRIC,SYSTEM,SYSTEM_TIME,SYSTEM_USER,TABLE,TABLESAMPLE,TABLE_NAME,TEMPORARY,THEN,TIES,TIME,TIMESTAMP,TIMESTAMPADD,TIMESTAMPDIFF,TIMEZONE_HOUR,TIMEZONE_MINUTE,TINYINT,TO,TOP_LEVEL_COUNT,TRAILING,TRANSACTION,TRANSACTIONS_ACTIVE,TRANSACTIONS_COMMITTED,TRANSACTIONS_ROLLED_BACK,TRANSFORM,TRANSFORMS,TRANSLATE,TRANSLATE_REGEX,TRANSLATION,TREAT,TRIGGER,TRIGGER_CATALOG,TRIGGER_NAME,TRIGGER_SCHEMA,TRIM,TRIM_ARRAY,TRUE,TRUNCATE,TYPE,UESCAPE,UNBOUNDED,UNCOMMITTED,UNCONDITIONAL,UNDER,UNION,UNIQUE,UNKNOWN,UNNAMED,UNNEST,UPDATE,UPPER,UPSERT,USAGE,USER,USER_DEFINED_TYPE_CATALOG,USER_DEFINED_TYPE_CODE,USER_DEFINED_TYPE_NAME,USER_DEFINED_TYPE_SCHEMA,USING,UTF16,UTF32,UTF8,VALUE,VALUES,VALUE_OF,VARBINARY,VARCHAR,VARYING,VAR_POP,VAR_SAMP,VERSION,VERSIONING,VIEW,WEEK,WHEN,WHENEVER,WHERE,WIDTH_BUCKET,WINDOW,WITH,WITHIN,WITHOUT,WORK,WRAPPER,WRITE,XML,YEAR,ZONE.

Identifiers

Identifiers are the names of tables, columns and other metadataelements used in a SQL query.

Unquoted identifiers, such as emp, must start with a letter and canonly contain letters, digits, and underscores. They are implicitlyconverted to upper case.

Quoted identifiers, such as "Employee Name", start and end withdouble quotes. They may contain virtually any character, includingspaces and other punctuation. If you wish to include a double quotein an identifier, use another double quote to escape it, like this:"An employee called ""Fred"".".

In Calcite, matching identifiers to the name of the referenced object iscase-sensitive. But remember that unquoted identifiers are implicitlyconverted to upper case before matching, and if the object it refersto was created using an unquoted identifier for its name, then itsname will have been converted to upper case also.

Data types

Scalar types

Data typeDescriptionRange and example literals
BOOLEANLogical valuesValues: TRUE, FALSE, UNKNOWN
TINYINT1 byte signed integerRange is -128 to 127
SMALLINT2 byte signed integerRange is -32768 to 32767
INTEGER, INT4 byte signed integerRange is -2147483648 to 2147483647
BIGINT8 byte signed integerRange is -9223372036854775808 to 9223372036854775807
DECIMAL(p, s)Fixed pointExample: 123.45 is a DECIMAL(5, 2) value.
NUMERICFixed point
REAL, FLOAT4 byte floating point6 decimal digits precision
DOUBLE8 byte floating point15 decimal digits precision
CHAR(n), CHARACTER(n)Fixed-width character string‘Hello’, ‘’ (empty string), _latin1’Hello’, n’Hello’, _UTF16’Hello’, ‘Hello’ ‘there’ (literal split into multiple parts)
VARCHAR(n), CHARACTER VARYING(n)Variable-length character stringAs CHAR(n)
BINARY(n)Fixed-width binary stringx’45F0AB’, x’’ (empty binary string), x’AB’ ‘CD’ (multi-part binary string literal)
VARBINARY(n), BINARY VARYING(n)Variable-length binary stringAs BINARY(n)
DATEDateExample: DATE ‘1969-07-20’
TIMETime of dayExample: TIME ‘20:17:40’
TIMESTAMP [ WITHOUT TIME ZONE ]Date and timeExample: TIMESTAMP ‘1969-07-20 20:17:40’
TIMESTAMP WITH LOCAL TIME ZONEDate and time with local time zoneExample: TIMESTAMP ‘1969-07-20 20:17:40 America/Los Angeles’
TIMESTAMP WITH TIME ZONEDate and time with time zoneExample: TIMESTAMP ‘1969-07-20 20:17:40 America/Los Angeles’
INTERVAL timeUnit [ TO timeUnit ]Date time intervalExamples: INTERVAL ‘1-5’ YEAR TO MONTH, INTERVAL ‘45’ DAY, INTERVAL ‘1 2:34:56.789’ DAY TO SECOND
GEOMETRYGeometryExamples: ST_GeomFromText(‘POINT (30 10)’)

Where:

  1. timeUnit:
  2. MILLENNIUM | CENTURY | DECADE | YEAR | QUARTER | MONTH | WEEK | DOY | DOW | DAY | HOUR | MINUTE | SECOND | EPOCH

Note:

  • DATE, TIME and TIMESTAMP have no time zone. For those types, there is noteven an implicit time zone, such as UTC (as in Java) or the local time zone.It is left to the user or application to supply a time zone. In turn,TIMESTAMP WITH LOCAL TIME ZONE does not store the time zone internally, butit will rely on the supplied time zone to provide correct semantics.
  • GEOMETRY is allowed only in certainconformance levels.

Non-scalar types

TypeDescriptionExample literals
ANYA value of an unknown type
ROWRow with 1 or more columnsExample: Row(f0 int null, f1 varchar)
MAPCollection of keys mapped to values
MULTISETUnordered collection that may contain duplicatesExample: int multiset
ARRAYOrdered, contiguous collection that may contain duplicatesExample: varchar(10) array
CURSORCursor over the result of executing a query

Note:

  • Every ROW column type can have an optional [ NULL | NOT NULL ] suffixto indicate if this column type is nullable, default is not nullable.

Spatial types

Spatial data is represented as character strings encoded aswell-known text (WKT)or binary strings encoded aswell-known binary (WKB).

Where you would use a literal, apply the ST_GeomFromText function,for example ST_GeomFromText('POINT (30 10)').

Data typeType codeExamples in WKT
GEOMETRY0generalization of Point, Curve, Surface, GEOMETRYCOLLECTION
POINT1ST_GeomFromText(​'POINT (30 10)') is a point in 2D space; ST_GeomFromText(​'POINT Z(30 10 2)') is point in 3D space
CURVE13generalization of LINESTRING
LINESTRING2ST_GeomFromText(​'LINESTRING (30 10, 10 30, 40 40)')
SURFACE14generalization of Polygon, PolyhedralSurface
POLYGON3ST_GeomFromText(​'POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))') is a pentagon; ST_GeomFromText(​'POLYGON ((35 10, 45 45, 15 40, 10 20, 35 10), (20 30, 35 35, 30 20, 20 30))') is a pentagon with a quadrilateral hole
POLYHEDRALSURFACE15
GEOMETRYCOLLECTION7a collection of zero or more GEOMETRY instances; a generalization of MULTIPOINT, MULTILINESTRING, MULTIPOLYGON
MULTIPOINT4ST_GeomFromText(​'MULTIPOINT ((10 40), (40 30), (20 20), (30 10))') is equivalent to ST_GeomFromText(​'MULTIPOINT (10 40, 40 30, 20 20, 30 10)')
MULTICURVE-generalization of MULTILINESTRING
MULTILINESTRING5ST_GeomFromText(​'MULTILINESTRING ((10 10, 20 20, 10 40), (40 40, 30 30, 40 20, 30 10))')
MULTISURFACE-generalization of MULTIPOLYGON
MULTIPOLYGON6ST_GeomFromText(​'MULTIPOLYGON (((30 20, 45 40, 10 40, 30 20)), ((15 5, 40 10, 10 20, 5 10, 15 5)))')

Operators and functions

Operator precedence

The operator precedence and associativity, highest to lowest.

OperatorAssociativity
.left
::left
[ ] (array element)left
+ - (unary plus, minus)right
* / % ||left
+ -left
BETWEEN, IN, LIKE, SIMILAR, OVERLAPS, CONTAINS etc.-
< > = <= >= <> !=left
IS NULL, IS FALSE, IS NOT TRUE etc.-
NOTright
ANDleft
ORleft

Note that :: is dialect-specific, but is shown in this table forcompleteness.

Comparison operators

Operator syntaxDescription
value1 = value2Equals
value1 <> value2Not equal
value1 != value2Not equal (only available at some conformance levels)
value1 > value2Greater than
value1 >= value2Greater than or equal
value1 < value2Less than
value1 <= value2Less than or equal
value IS NULLWhether value is null
value IS NOT NULLWhether value is not null
value1 IS DISTINCT FROM value2Whether two values are not equal, treating null values as the same
value1 IS NOT DISTINCT FROM value2Whether two values are equal, treating null values as the same
value1 BETWEEN value2 AND value3Whether value1 is greater than or equal to value2 and less than or equal to value3
value1 NOT BETWEEN value2 AND value3Whether value1 is less than value2 or greater than value3
string1 LIKE string2 [ ESCAPE string3 ]Whether string1 matches pattern string2
string1 NOT LIKE string2 [ ESCAPE string3 ]Whether string1 does not match pattern string2
string1 SIMILAR TO string2 [ ESCAPE string3 ]Whether string1 matches regular expression string2
string1 NOT SIMILAR TO string2 [ ESCAPE string3 ]Whether string1 does not match regular expression string2
value IN (value [, value])Whether value is equal to a value in a list
value NOT IN (value [, value])Whether value is not equal to every value in a list
value IN (sub-query)Whether value is equal to a row returned by sub-query
value NOT IN (sub-query)Whether value is not equal to every row returned by sub-query
value comparison SOME (sub-query)Whether value__comparison at least one row returned by sub-query
value comparison ANY (sub-query)Synonym for SOME
value comparison ALL (sub-query)Whether value__comparison every row returned by sub-query
EXISTS (sub-query)Whether sub-query returns at least one row
  1. comp:
  2. =
  3. | <>
  4. | >
  5. | >=
  6. | <
  7. | <=

Logical operators

Operator syntaxDescription
boolean1 OR boolean2Whether boolean1 is TRUE or boolean2 is TRUE
boolean1 AND boolean2Whether boolean1 and boolean2 are both TRUE
NOT booleanWhether boolean is not TRUE; returns UNKNOWN if boolean is UNKNOWN
boolean IS FALSEWhether boolean is FALSE; returns FALSE if boolean is UNKNOWN
boolean IS NOT FALSEWhether boolean is not FALSE; returns TRUE if boolean is UNKNOWN
boolean IS TRUEWhether boolean is TRUE; returns FALSE if boolean is UNKNOWN
boolean IS NOT TRUEWhether boolean is not TRUE; returns TRUE if boolean is UNKNOWN
boolean IS UNKNOWNWhether boolean is UNKNOWN
boolean IS NOT UNKNOWNWhether boolean is not UNKNOWN

Arithmetic operators and functions

Operator syntaxDescription
+ numericReturns numeric
- numericReturns negative numeric
numeric1 + numeric2Returns numeric1 plus numeric2
numeric1 - numeric2Returns numeric1 minus numeric2
numeric1 * numeric2Returns numeric1 multiplied by numeric2
numeric1 / numeric2Returns numeric1 divided by numeric2
numeric1 % numeric2As MOD(numeric1, numeric2) (only in certain conformance levels)
POWER(numeric1, numeric2)Returns numeric1 raised to the power of numeric2
ABS(numeric)Returns the absolute value of numeric
MOD(numeric1, numeric2)Returns the remainder (modulus) of numeric1 divided by numeric2. The result is negative only if numeric1 is negative
SQRT(numeric)Returns the square root of numeric
LN(numeric)Returns the natural logarithm (base e) of numeric
LOG10(numeric)Returns the base 10 logarithm of numeric
EXP(numeric)Returns e raised to the power of numeric
CEIL(numeric)Rounds numeric up, returning the smallest integer that is greater than or equal to numeric
FLOOR(numeric)Rounds numeric down, returning the largest integer that is less than or equal to numeric
RAND([seed])Generates a random double between 0 and 1 inclusive, optionally initializing the random number generator with seed
RANDINTEGER([seed, ] numeric)Generates a random integer between 0 and _numeric - 1 inclusive, optionally initializing the random number generator with seed
ACOS(numeric)Returns the arc cosine of numeric
ASIN(numeric)Returns the arc sine of numeric
ATAN(numeric)Returns the arc tangent of numeric
ATAN2(numeric, numeric)Returns the arc tangent of the numeric coordinates
COS(numeric)Returns the cosine of numeric
COT(numeric)Returns the cotangent of numeric
DEGREES(numeric)Converts numeric from radians to degrees
PI()Returns a value that is closer than any other value to pi
RADIANS(numeric)Converts numeric from degrees to radians
ROUND(numeric1 [, numeric2])Rounds numeric1 to optionally numeric2 (if not specified 0) places right to the decimal point
SIGN(numeric)Returns the signum of numeric
SIN(numeric)Returns the sine of numeric
TAN(numeric)Returns the tangent of numeric
TRUNCATE(numeric1 [, numeric2])Truncates numeric1 to optionally numeric2 (if not specified 0) places right to the decimal point

Character string operators and functions

Operator syntaxDescription
string || stringConcatenates two character strings
CHARLENGTH(string)Returns the number of characters in a character string
CHARACTER_LENGTH(string)As CHAR_LENGTH(_string)
UPPER(string)Returns a character string converted to upper case
LOWER(string)Returns a character string converted to lower case
POSITION(string1 IN string2)Returns the position of the first occurrence of string1 in string2
POSITION(string1 IN string2 FROM integer)Returns the position of the first occurrence of string1 in string2 starting at a given point (not standard SQL)
TRIM( { BOTH | LEADING | TRAILING } string1 FROM string2)Removes the longest string containing only the characters in string1 from the start/end/both ends of string1
OVERLAY(string1 PLACING string2 FROM integer [ FOR integer2 ])Replaces a substring of string1 with string2
SUBSTRING(string FROM integer)Returns a substring of a character string starting at a given point
SUBSTRING(string FROM integer FOR integer)Returns a substring of a character string starting at a given point with a given length
INITCAP(string)Returns string with the first letter of each word converter to upper case and the rest to lower case. Words are sequences of alphanumeric characters separated by non-alphanumeric characters.

Not implemented:

  • SUBSTRING(string FROM regexp FOR regexp)

Binary string operators and functions

Operator syntaxDescription
binary || binaryConcatenates two binary strings
POSITION(binary1 IN binary2)Returns the position of the first occurrence of binary1 in binary2
POSITION(binary1 IN binary2 FROM integer)Returns the position of the first occurrence of binary1 in binary2 starting at a given point (not standard SQL)
OVERLAY(binary1 PLACING binary2 FROM integer [ FOR integer2 ])Replaces a substring of binary1 with binary2
SUBSTRING(binary FROM integer)Returns a substring of binary starting at a given point
SUBSTRING(binary FROM integer FOR integer)Returns a substring of binary starting at a given point with a given length

Date/time functions

Operator syntaxDescription
LOCALTIMEReturns the current date and time in the session time zone in a value of datatype TIME
LOCALTIME(precision)Returns the current date and time in the session time zone in a value of datatype TIME, with precision digits of precision
LOCALTIMESTAMPReturns the current date and time in the session time zone in a value of datatype TIMESTAMP
LOCALTIMESTAMP(precision)Returns the current date and time in the session time zone in a value of datatype TIMESTAMP, with precision digits of precision
CURRENTTIMEReturns the current time in the session time zone, in a value of datatype TIMESTAMP WITH TIME ZONE
CURRENT_DATEReturns the current date in the session time zone, in a value of datatype DATE
CURRENT_TIMESTAMPReturns the current date and time in the session time zone, in a value of datatype TIMESTAMP WITH TIME ZONE
EXTRACT(timeUnit FROM datetime)Extracts and returns the value of a specified datetime field from a datetime value expression
FLOOR(datetime TO timeUnit)Rounds _datetime down to timeUnit
CEIL(datetime TO timeUnit)Rounds datetime up to timeUnit
YEAR(date)Equivalent to EXTRACT(YEAR FROM date). Returns an integer.
QUARTER(date)Equivalent to EXTRACT(QUARTER FROM date). Returns an integer between 1 and 4.
MONTH(date)Equivalent to EXTRACT(MONTH FROM date). Returns an integer between 1 and 12.
WEEK(date)Equivalent to EXTRACT(WEEK FROM date). Returns an integer between 1 and 53.
DAYOFYEAR(date)Equivalent to EXTRACT(DOY FROM date). Returns an integer between 1 and 366.
DAYOFMONTH(date)Equivalent to EXTRACT(DAY FROM date). Returns an integer between 1 and 31.
DAYOFWEEK(date)Equivalent to EXTRACT(DOW FROM date). Returns an integer between 1 and 7.
HOUR(date)Equivalent to EXTRACT(HOUR FROM date). Returns an integer between 0 and 23.
MINUTE(date)Equivalent to EXTRACT(MINUTE FROM date). Returns an integer between 0 and 59.
SECOND(date)Equivalent to EXTRACT(SECOND FROM date). Returns an integer between 0 and 59.
TIMESTAMPADD(timeUnit, integer, datetime)Returns datetime with an interval of (signed) integer__timeUnit_s added. Equivalent to datetime + INTERVAL 'integer' timeUnit
TIMESTAMPDIFF(timeUnit, datetime, datetime2)Returns the (signed) number of _timeUnit intervals between datetime and datetime2. Equivalent to (datetime2 - datetime) timeUnit
LAST_DAY(date)Returns the date of the last day of the month in a value of datatype DATE; For example, it returns DATE’2020-02-29’ for both DATE’2020-02-10’ and TIMESTAMP’2020-02-10 10:10:10’

Calls to niladic functions such as CURRENT_DATE do not accept parentheses instandard SQL. Calls with parentheses, such as CURRENT_DATE() are accepted in certainconformance levels.

Not implemented:

  • CEIL(interval)
  • FLOOR(interval)
    • interval
    • interval
  • interval + interval
  • interval - interval
  • interval / interval

System functions

Operator syntaxDescription
USEREquivalent to CURRENT_USER
CURRENT_USERUser name of current execution context
SESSION_USERSession user name
SYSTEM_USERReturns the name of the current data store user as identified by the operating system
CURRENT_PATHReturns a character string representing the current lookup scope for references to user-defined routines and types
CURRENT_ROLEReturns the current active role
CURRENT_SCHEMAReturns the current schema

Conditional functions and operators

Operator syntaxDescription
CASE valueWHEN value1 [, value11 ] THEN result1[ WHEN valueN [, valueN1 ] THEN resultN ][ ELSE resultZ ] ENDSimple case
CASEWHEN condition1 THEN result1[ WHEN conditionN THEN resultN ][ ELSE resultZ ]ENDSearched case
NULLIF(value, value)Returns NULL if the values are the same.For example, NULLIF(5, 5) returns NULL; NULLIF(5, 0) returns 5.
COALESCE(value, value [, value ]*)Provides a value if the first value is null.For example, COALESCE(NULL, 5) returns 5.

Type conversion

Generally an expression cannot contain values of different datatypes. For example, an expression cannot multiply 5 by 10 and then add ‘JULIAN’.However, Calcite supports both implicit and explicit conversion of values from one datatype to another.

Implicit and Explicit Type Conversion

Calcite recommends that you specify explicit conversions, rather than rely on implicit or automatic conversions, for these reasons:

  • SQL statements are easier to understand when you use explicit datatype conversion functions.
  • Implicit datatype conversion can have a negative impact on performance, especially if the datatype of a column value is converted to that of a constant rather than the other way around.
  • Implicit conversion depends on the context in which it occurs and may not work the same way in every case. For example, implicit conversion from a datetime value to a VARCHAR value may return an unexpected format.

Algorithms for implicit conversion are subject to change across Calcite releases. Behavior of explicit conversions is more predictable.

Explicit Type Conversion

Operator syntaxDescription
CAST(value AS type)Converts a value to a given type.

Supported data types syntax:

  1. type:
  2. typeName
  3. [ collectionsTypeName ]*
  4. typeName:
  5. sqlTypeName
  6. | rowTypeName
  7. | compoundIdentifier
  8. sqlTypeName:
  9. char [ precision ] [ charSet ]
  10. | varchar [ precision ] [ charSet ]
  11. | DATE
  12. | time
  13. | timestamp
  14. | GEOMETRY
  15. | decimal [ precision [, scale] ]
  16. | BOOLEAN
  17. | integer
  18. | BINARY [ precision ]
  19. | varbinary [ precision ]
  20. | TINYINT
  21. | SMALLINT
  22. | BIGINT
  23. | REAL
  24. | double
  25. | FLOAT
  26. | ANY [ precision [, scale] ]
  27. collectionsTypeName:
  28. ARRAY | MULTISET
  29. rowTypeName:
  30. ROW '('
  31. fieldName1 fieldType1 [ NULL | NOT NULL ]
  32. [ , fieldName2 fieldType2 [ NULL | NOT NULL ] ]*
  33. ')'
  34. char:
  35. CHARACTER | CHAR
  36. varchar:
  37. char VARYING | VARCHAR
  38. decimal:
  39. DECIMAL | DEC | NUMERIC
  40. integer:
  41. INTEGER | INT
  42. varbinary:
  43. BINARY VARYING | VARBINARY
  44. double:
  45. DOUBLE [ PRECISION ]
  46. time:
  47. TIME [ precision ] [ timeZone ]
  48. timestamp:
  49. TIMESTAMP [ precision ] [ timeZone ]
  50. charSet:
  51. CHARACTER SET charSetName
  52. timeZone:
  53. WITHOUT TIME ZONE
  54. | WITH LOCAL TIME ZONE

Implicit Type Conversion

Calcite automatically converts a value from one datatype to anotherwhen such a conversion makes sense. The table below is a matrix ofCalcite type conversions. The table shows all possible conversions,without regard to the context in which it is made. The rules governingthese details follow the table.

FROM - TONULLBOOLEANTINYINTSMALLINTINTBIGINTDECIMALFLOAT or REALDOUBLEINTERVALDATETIMETIMESTAMPCHAR or VARCHARBINARY or VARBINARY
NULLiiiiiiiiiiiiiii
BOOLEANxieeeeeeexxxxix
TINYINTxeiiiiiiiexxeix
SMALLINTxeiiiiiiiexxeix
INTxeiiiiiiiexxeix
BIGINTxeiiiiiiiexxeix
DECIMALxeiiiiiiiexxeix
FLOAT/REALxeiiiiiiixxxeix
DOUBLExeiiiiiiixxxeix
INTERVALxxeeeeexxixxxex
DATExxxxxxxxxxixiix
TIMExxxxxxxxxxxieix
TIMESTAMPxxeeeeeeexieiix
CHAR or VARCHARxeiiiiiiiiiiiii
BINARY or VARBINARYxxxxxxxxxxeeeii

i: implicit cast / e: explicit cast / x: not allowed

Conversion Contexts and Strategies
  • Set operation (UNION, EXCEPT, INTERSECT): Compare every branchrow data type and find the common type of each fields pair;
  • Binary arithmetic expression (+, -, &, ^, /, %): promotestring operand to data type of the other numeric operand;
  • Binary comparison (=, <, <=, <>, >, >=):if operands are STRING and TIMESTAMP, promote to TIMESTAMP;make 1 = true and 0 = false always evaluate to TRUE;if there is numeric type operand, find common type for both operands.
  • IN sub-query: compare type of LHS and RHS, and find the common type;if it is struct type, find wider type for every field;
  • IN expression list: compare every expression to find the common type;
  • CASE WHEN expression or COALESCE: find the common wider type of the THENand ELSE operands;
  • Character + INTERVAL or character - INTERVAL: Promote character toTIMESTAMP;
  • Built-in function: Look up the type families registered in the checker,find the family default type if checker rules allow it;
  • User-defined function (UDF): Coerce based on the declared argument typesof the eval() method.
Strategies for Finding Common Type
  • If the operator has expected data types, just take them as thedesired one. (e.g. the UDF would have eval() method which hasreflection argument types);
  • If there is no expected data type but the data type families areregistered, try to coerce the arguments to the family’s default datatype, i.e. the String family will have a VARCHAR type;
  • If neither expected data type nor families are specified, try tofind the tightest common type of the node types, i.e. INTEGER andDOUBLE will return DOUBLE, the numeric precision does not losefor this case;
  • If no tightest common type is found, try to find a wider type,i.e. VARCHAR and INTEGER will return INTEGER,we allow some precision loss when widening decimal to fractional,or promote to VARCHAR type.

Value constructors

Operator syntaxDescription
ROW (value [, value ])Creates a row from a list of values.
(value [, value ] )Creates a row from a list of values.
map ‘[’ key ‘]’Returns the element of a map with a particular key.
array ‘[’ index ‘]’Returns the element at a particular location in an array.
ARRAY ‘[’ value [, value ] ‘]’Creates an array from a list of values.
MAP ‘[’ key, value [, key, value ] ‘]’Creates a map from a list of key-value pairs.

Collection functions

Operator syntaxDescription
ELEMENT(value)Returns the sole element of an array or multiset; null if the collection is empty; throws if it has more than one element.
CARDINALITY(value)Returns the number of elements in an array or multiset.
value MEMBER OF multisetReturns whether the value is a member of multiset.
multiset IS A SETWhether multiset is a set (has no duplicates).
multiset IS NOT A SETWhether multiset is not a set (has duplicates).
multiset IS EMPTYWhether multiset contains zero elements.
multiset IS NOT EMPTYWhether multiset contains one or more elements.
multiset SUBMULTISET OF multiset2Whether multiset is a submultiset of multiset2.
multiset NOT SUBMULTISET OF multiset2Whether multiset is not a submultiset of multiset2.
multiset MULTISET UNION [ ALL | DISTINCT ] multiset2Returns the union multiset and multiset2, eliminating duplicates if DISTINCT is specified (ALL is the default).
multiset MULTISET INTERSECT [ ALL | DISTINCT ] multiset2Returns the intersection of multiset and multiset2, eliminating duplicates if DISTINCT is specified (ALL is the default).
multiset MULTISET EXCEPT [ ALL | DISTINCT ] multiset2Returns the difference of multiset and multiset2, eliminating duplicates if DISTINCT is specified (ALL is the default).

See also: the UNNEST relational operator converts a collection to a relation.

Period predicates

Operator syntaxDescription
period1 CONTAINS datetime
period1 CONTAINS period2
period1 OVERLAPS period2
period1 EQUALS period2
period1 PRECEDES period2
period1 IMMEDIATELY PRECEDES period2
period1 SUCCEEDS period2
period1 IMMEDIATELY SUCCEEDS period2

Where period1 and period2 are period expressions:

  1. period:
  2. (datetime, datetime)
  3. | (datetime, interval)
  4. | PERIOD (datetime, datetime)
  5. | PERIOD (datetime, interval)

JDBC function escape

Numeric

Operator syntaxDescription
{fn ABS(numeric)}Returns the absolute value of numeric
{fn ACOS(numeric)}Returns the arc cosine of numeric
{fn ASIN(numeric)}Returns the arc sine of numeric
{fn ATAN(numeric)}Returns the arc tangent of numeric
{fn ATAN2(numeric, numeric)}Returns the arc tangent of the numeric coordinates
{fn CEILING(numeric)}Rounds numeric up, and returns the smallest number that is greater than or equal to numeric
{fn COS(numeric)}Returns the cosine of numeric
{fn COT(numeric)}Returns the cotangent of numeric
{fn DEGREES(numeric)}Converts numeric from radians to degrees
{fn EXP(numeric)}Returns e raised to the power of numeric
{fn FLOOR(numeric)}Rounds numeric down, and returns the largest number that is less than or equal to numeric
{fn LOG(numeric)}Returns the natural logarithm (base e) of numeric
{fn LOG10(numeric)}Returns the base-10 logarithm of numeric
{fn MOD(numeric1, numeric2)}Returns the remainder (modulus) of numeric1 divided by numeric2. The result is negative only if numeric1 is negative
{fn PI()}Returns a value that is closer than any other value to pi
{fn POWER(numeric1, numeric2)}Returns numeric1 raised to the power of numeric2
{fn RADIANS(numeric)}Converts numeric from degrees to radians
{fn RAND(numeric)}Returns a random double using numeric as the seed value
{fn ROUND(numeric1, numeric2)}Rounds numeric1 to numeric2 places right to the decimal point
{fn SIGN(numeric)}Returns the signum of numeric
{fn SIN(numeric)}Returns the sine of numeric
{fn SQRT(numeric)}Returns the square root of numeric
{fn TAN(numeric)}Returns the tangent of numeric
{fn TRUNCATE(numeric1, numeric2)}Truncates numeric1 to numeric2 places right to the decimal point

String

Operator syntaxDescription
{fn ASCII(string)}Returns the ASCII code of the first character of string; if the first character is a non-ASCII character, returns its Unicode code point; returns 0 if string is empty
{fn CONCAT(character, character)}Returns the concatenation of character strings
{fn INSERT(string1, start, length, string2)}Inserts string2 into a slot in string1
{fn LCASE(string)}Returns a string in which all alphabetic characters in string have been converted to lower case
{fn LENGTH(string)}Returns the number of characters in a string
{fn LOCATE(string1, string2 [, integer])}Returns the position in string2 of the first occurrence of string1. Searches from the beginning of string2, unless integer is specified.
{fn LEFT(string, length)}Returns the leftmost length characters from string
{fn LTRIM(string)}Returns string with leading space characters removed
{fn REPLACE(string, search, replacement)}Returns a string in which all the occurrences of search in string are replaced with replacement; if replacement is the empty string, the occurrences of search are removed
{fn REVERSE(string)}Returns string with the order of the characters reversed
{fn RIGHT(string, integer)}Returns the rightmost length characters from string
{fn RTRIM(string)}Returns string with trailing space characters removed
{fn SUBSTRING(string, offset, length)}Returns a character string that consists of length characters from string starting at the offset position
{fn UCASE(string)}Returns a string in which all alphabetic characters in string have been converted to upper case

Not implemented:

  • {fn CHAR(string)}

Date/time

Operator syntaxDescription
{fn CURDATE()}Equivalent to CURRENTDATE
{fn CURTIME()}Equivalent to LOCALTIME
{fn NOW()}Equivalent to LOCALTIMESTAMP
{fn YEAR(date)}Equivalent to EXTRACT(YEAR FROM date). Returns an integer.
{fn QUARTER(date)}Equivalent to EXTRACT(QUARTER FROM date). Returns an integer between 1 and 4.
{fn MONTH(date)}Equivalent to EXTRACT(MONTH FROM date). Returns an integer between 1 and 12.
{fn WEEK(date)}Equivalent to EXTRACT(WEEK FROM date). Returns an integer between 1 and 53.
{fn DAYOFYEAR(date)}Equivalent to EXTRACT(DOY FROM date). Returns an integer between 1 and 366.
{fn DAYOFMONTH(date)}Equivalent to EXTRACT(DAY FROM date). Returns an integer between 1 and 31.
{fn DAYOFWEEK(date)}Equivalent to EXTRACT(DOW FROM date). Returns an integer between 1 and 7.
{fn HOUR(date)}Equivalent to EXTRACT(HOUR FROM date). Returns an integer between 0 and 23.
{fn MINUTE(date)}Equivalent to EXTRACT(MINUTE FROM date). Returns an integer between 0 and 59.
{fn SECOND(date)}Equivalent to EXTRACT(SECOND FROM date). Returns an integer between 0 and 59.
{fn TIMESTAMPADD(timeUnit, count, datetime)}Adds an interval of _count__timeUnit_s to a datetime
{fn TIMESTAMPDIFF(timeUnit, timestamp1, timestamp2)}Subtracts _timestamp1 from timestamp2 and returns the result in _timeUnit_s

System

Operator syntaxDescription
{fn DATABASE()}Equivalent to CURRENT_CATALOG
{fn IFNULL(value1, value2)}Returns value2 if value1 is null
{fn USER()}Equivalent to CURRENT_USER

Conversion

Operator syntaxDescription
{fn CONVERT(value, type)}Cast value into type

Aggregate functions

Syntax:

  1. aggregateCall:
  2. agg( [ ALL | DISTINCT ] value [, value ]*)
  3. [ WITHIN GROUP (ORDER BY orderItem [, orderItem ]*) ]
  4. [ FILTER (WHERE condition) ]
  5. | agg(*) [ FILTER (WHERE condition) ]

where agg is one of the operators in the following table, or a user-definedaggregate function.

If FILTER is present, the aggregate function only considers rows for whichcondition evaluates to TRUE.

If DISTINCT is present, duplicate argument values are eliminated before beingpassed to the aggregate function.

If WITHIN GROUP is present, the aggregate function sorts the input rowsaccording to the ORDER BY clause inside WITHIN GROUP before aggregatingvalues. WITHIN GROUP is only allowed for hypothetical set functions (RANK,DENSE_RANK, PERCENT_RANK and CUME_DIST), inverse distribution functions(PERCENTILE_CONT and PERCENTILE_DISC) and collection functions (COLLECTand LISTAGG).

Operator syntaxDescription
COLLECT( [ ALL | DISTINCT ] value)Returns a multiset of the values
LISTAGG( [ ALL | DISTINCT ] value [, separator])Returns values concatenated into a string, delimited by separator (default ‘,’)
COUNT( [ ALL | DISTINCT ] value [, value ])Returns the number of input rows for which value is not null (wholly not null if value is composite)
COUNT()Returns the number of input rows
FUSION(multiset)Returns the multiset union of multiset across all input values
APPROXCOUNT_DISTINCT(value [, value ]*)Returns the approximate number of distinct values of _value; the database is allowed to use an approximation but is not required to
AVG( [ ALL | DISTINCT ] numeric)Returns the average (arithmetic mean) of numeric across all input values
SUM( [ ALL | DISTINCT ] numeric)Returns the sum of numeric across all input values
MAX( [ ALL | DISTINCT ] value)Returns the maximum value of value across all input values
MIN( [ ALL | DISTINCT ] value)Returns the minimum value of value across all input values
ANYVALUE( [ ALL | DISTINCT ] value)Returns one of the values of _value across all input values; this is NOT specified in the SQL standard
BITAND( [ ALL | DISTINCT ] value)Returns the bitwise AND of all non-null input values, or null if none
BIT_OR( [ ALL | DISTINCT ] value)Returns the bitwise OR of all non-null input values, or null if none
STDDEV_POP( [ ALL | DISTINCT ] numeric)Returns the population standard deviation of _numeric across all input values
STDDEVSAMP( [ ALL | DISTINCT ] numeric)Returns the sample standard deviation of _numeric across all input values
STDDEV( [ ALL | DISTINCT ] numeric)Synonym for STDDEVSAMP
VAR_POP( [ ALL | DISTINCT ] value)Returns the population variance (square of the population standard deviation) of _numeric across all input values
VARSAMP( [ ALL | DISTINCT ] numeric)Returns the sample variance (square of the sample standard deviation) of _numeric across all input values
COVARPOP(numeric1, numeric2)Returns the population covariance of the pair (_numeric1, numeric2) across all input values
COVARSAMP(numeric1, numeric2)Returns the sample covariance of the pair (_numeric1, numeric2) across all input values
REGR_COUNT(numeric1, numeric2)Returns the number of rows where both dependent and independent expressions are not null
REGR_SXX(numeric1, numeric2)Returns the sum of squares of the dependent expression in a linear regression model
REGR_SYY(numeric1, numeric2)Returns the sum of squares of the independent expression in a linear regression model

Not implemented:

  • REGR_AVGX(numeric1, numeric2)
  • REGR_AVGY(numeric1, numeric2)
  • REGR_INTERCEPT(numeric1, numeric2)
  • REGR_R2(numeric1, numeric2)
  • REGR_SLOPE(numeric1, numeric2)
  • REGR_SXY(numeric1, numeric2)

Window functions

Syntax:

  1. windowedAggregateCall:
  2. agg( [ ALL | DISTINCT ] value [, value ]*)
  3. [ RESPECT NULLS | IGNORE NULLS ]
  4. [ WITHIN GROUP (ORDER BY orderItem [, orderItem ]*) ]
  5. [ FILTER (WHERE condition) ]
  6. OVER window
  7. | agg(*)
  8. [ FILTER (WHERE condition) ]
  9. OVER window

where agg is one of the operators in the following table, or a user-definedaggregate function.

DISTINCT, FILTER and WITHIN GROUP are as described for aggregatefunctions.

Operator syntaxDescription
COUNT(value [, value ]) OVER windowReturns the number of rows in window for which value is not null (wholly not null if value is composite)
COUNT() OVER windowReturns the number of rows in window
AVG(numeric) OVER windowReturns the average (arithmetic mean) of numeric across all values in window
SUM(numeric) OVER windowReturns the sum of numeric across all values in window
MAX(value) OVER windowReturns the maximum value of value across all values in window
MIN(value) OVER windowReturns the minimum value of value across all values in window
RANK() OVER windowReturns the rank of the current row with gaps; same as ROWNUMBER of its first peer
DENSE_RANK() OVER windowReturns the rank of the current row without gaps; this function counts peer groups
ROW_NUMBER() OVER windowReturns the number of the current row within its partition, counting from 1
FIRST_VALUE(value) OVER windowReturns _value evaluated at the row that is the first row of the window frame
LASTVALUE(value) OVER windowReturns _value evaluated at the row that is the last row of the window frame
LEAD(value, offset, default) OVER windowReturns value evaluated at the row that is offset rows after the current row within the partition; if there is no such row, instead returns default. Both offset and default are evaluated with respect to the current row. If omitted, offset defaults to 1 and default to NULL
LAG(value, offset, default) OVER windowReturns value evaluated at the row that is offset rows before the current row within the partition; if there is no such row, instead returns default. Both offset and default are evaluated with respect to the current row. If omitted, offset defaults to 1 and default to NULL
NTHVALUE(value, nth) OVER windowReturns _value evaluated at the row that is the n_th row of the window frame
NTILE(value) OVER windowReturns an integer ranging from 1 to _value, dividing the partition as equally as possible

Note:

  • You may specify null treatment (IGNORE NULLS, RESPECT NULLS) forFIRST_VALUE, LAST_VALUE, NTH_VALUE, LEAD and LAG functions. Thesyntax handled by the parser, but only RESPECT NULLS is implemented atruntime.

Not implemented:

  • COUNT(DISTINCT value [, value ]*) OVER window
  • APPROX_COUNT_DISTINCT(value [, value ]*) OVER window
  • PERCENT_RANK(value) OVER window
  • CUME_DIST(value) OVER window

Grouping functions

Operator syntaxDescription
GROUPING(expression [, expression ])Returns a bit vector of the given grouping expressions
GROUP_ID()Returns an integer that uniquely identifies the combination of grouping keys
GROUPING_ID(expression [, expression ])Synonym for GROUPING

Grouped window functions

Grouped window functions occur in the GROUP BY clause and define a key valuethat represents a window containing several rows.

In some window functions, a row may belong to more than one window.For example, if a query is grouped usingHOP(t, INTERVAL '2' HOUR, INTERVAL '1' HOUR), a row with timestamp ‘10:15:00’ will occur in both the 10:00 - 11:00 and 11:00 - 12:00 totals.

Operator syntaxDescription
HOP(datetime, slide, size [, time ])Indicates a hopping window for datetime, covering rows within the interval of size, shifting every slide, and optionally aligned at time
SESSION(datetime, interval [, time ])Indicates a session window of interval for datetime, optionally aligned at time
TUMBLE(datetime, interval [, time ])Indicates a tumbling window of interval for datetime, optionally aligned at time

Grouped auxiliary functions

Grouped auxiliary functions allow you to access properties of a window definedby a grouped window function.

Operator syntaxDescription
HOPEND(expression, slide, size [, time ])Returns the value of _expression at the end of the window defined by a HOP function call
HOPSTART(expression, slide, size [, time ])Returns the value of _expression at the beginning of the window defined by a HOP function call
SESSIONEND(expression, interval [, time])Returns the value of _expression at the end of the window defined by a SESSION function call
SESSIONSTART(expression, interval [, time])Returns the value of _expression at the beginning of the window defined by a SESSION function call
TUMBLEEND(expression, interval [, time ])Returns the value of _expression at the end of the window defined by a TUMBLE function call
TUMBLESTART(expression, interval [, time ])Returns the value of _expression at the beginning of the window defined by a TUMBLE function call

Spatial functions

In the following:

In the “C” (for “compatibility”) column, “o” indicates that the functionimplements the OpenGIS Simple Features Implementation Specification for SQL,version 1.2.1;“p” indicates that the function is aPostGIS extension to OpenGIS.

Geometry conversion functions (2D)

COperator syntaxDescription
pSTAsText(geom)Alias for ST_AsWKT
oST_AsWKT(geom)Converts _geom → WKT
oST_GeomFromText(wkt [, srid ])Returns a specified GEOMETRY value from WKT representation
oST_LineFromText(wkt [, srid ])Converts WKT → LINESTRING
oST_MLineFromText(wkt [, srid ])Converts WKT → MULTILINESTRING
oST_MPointFromText(wkt [, srid ])Converts WKT → MULTIPOINT
oST_MPolyFromText(wkt [, srid ]) Converts WKT → MULTIPOLYGON
oST_PointFromText(wkt [, srid ])Converts WKT → POINT
oST_PolyFromText(wkt [, srid ])Converts WKT → POLYGON

Not implemented:

  • ST_AsBinary(geom) GEOMETRY → WKB
  • ST_AsGML(geom) GEOMETRY → GML
  • ST_Force2D(geom) 3D GEOMETRY → 2D GEOMETRY
  • ST_GeomFromGML(gml [, srid ]) GML → GEOMETRY
  • ST_GeomFromWKB(wkb [, srid ]) WKB → GEOMETRY
  • ST_GoogleMapLink(geom [, layerType [, zoom ]]) GEOMETRY → Google map link
  • ST_LineFromWKB(wkb [, srid ]) WKB → LINESTRING
  • ST_OSMMapLink(geom [, marker ]) GEOMETRY → OSM map link
  • ST_PointFromWKB(wkb [, srid ]) WKB → POINT
  • ST_PolyFromWKB(wkb [, srid ]) WKB → POLYGON
  • STToMultiLine(geom) Converts the coordinates of _geom (which may be a GEOMETRYCOLLECTION) into a MULTILINESTRING
  • STToMultiPoint(geom)) Converts the coordinates of _geom (which may be a GEOMETRYCOLLECTION) into a MULTIPOINT
  • STToMultiSegments(geom) Converts _geom (which may be a GEOMETRYCOLLECTION) into a set of distinct segments stored in a MULTILINESTRING

Geometry conversion functions (3D)

Not implemented:

  • ST_Force3D(geom) 2D GEOMETRY → 3D GEOMETRY

Geometry creation functions (2D)

COperator syntaxDescription
oST_MakeLine(point1 [, point ]*)Creates a line-string from the given POINTs (or MULTIPOINTs)
pST_MakePoint(x, y [, z ])Alias for ST_Point
oST_Point(x, y [, z ])Constructs a point from two or three coordinates

Not implemented:

  • STBoundingCircle(geom) Returns the minimum bounding circle of _geom
  • STExpand(geom, distance) Expands _geom’s envelope
  • STExpand(geom, deltaX, deltaY) Expands _geom’s envelope
  • ST_MakeEllipse(point, width, height) Constructs an ellipse
  • ST_MakeEnvelope(xMin, yMin, xMax, yMax [, srid ]) Creates a rectangular POLYGON
  • STMakeGrid(geom, deltaX, deltaY) Calculates a regular grid of POLYGONs based on _geom
  • STMakeGridPoints(geom, deltaX, deltaY) Calculates a regular grid of points based on _geom
  • STMakePolygon(lineString [, hole ]) Creates a POLYGON from *lineString_ with the given holes (which are required to be closed LINESTRINGs)
  • STMinimumDiameter(geom) Returns the minimum diameter of _geom
  • STMinimumRectangle(geom) Returns the minimum rectangle enclosing _geom
  • STOctogonalEnvelope(geom) Returns the octogonal envelope of _geom
  • STRingBuffer(geom, distance, bufferCount [, endCapStyle [, doDifference]]) Returns a MULTIPOLYGON of buffers centered at _geom and of increasing buffer size

Geometry creation functions (3D)

Not implemented:

  • ST_Extrude(geom, height [, flag]) Extrudes a GEOMETRY
  • STGeometryShadow(geom, point, height) Computes the shadow footprint of _geom
  • STGeometryShadow(geom, azimuth, altitude, height [, unify ]) Computes the shadow footprint of _geom

Geometry properties (2D)

COperator syntaxDescription
oSTBoundary(geom [, srid ])Returns the boundary of _geom
oSTDistance(geom1, geom2)Returns the distance between _geom1 and geom2
oSTGeometryType(geom)Returns the type of _geom
oSTGeometryTypeCode(geom)Returns the OGC SFS type code of _geom
oSTEnvelope(geom [, srid ])Returns the envelope of _geom (which may be a GEOMETRYCOLLECTION) as a GEOMETRY
oSTX(geom)Returns the x-value of the first coordinate of _geom
oSTY(geom)Returns the y-value of the first coordinate of _geom

Not implemented:

  • STCentroid(geom) Returns the centroid of _geom (which may be a GEOMETRYCOLLECTION)
  • STCompactnessRatio(polygon) Returns the square root of _polygon’s area divided by the area of the circle with circumference equal to its perimeter
  • STCoordDim(geom) Returns the dimension of the coordinates of _geom
  • STDimension(geom) Returns the dimension of _geom
  • STEndPoint(lineString) Returns the last coordinate of _lineString
  • STEnvelope(geom [, srid ]) Returns the envelope of _geom (which may be a GEOMETRYCOLLECTION) as a GEOMETRY
  • STExplode(query [, fieldName]) Explodes the GEOMETRYCOLLECTIONs in the _fieldName column of a query into multiple geometries
  • STExtent(geom) Returns the minimum bounding box of _geom (which may be a GEOMETRYCOLLECTION)
  • STExteriorRing(polygon) Returns the exterior ring of _polygon as a linear-ring
  • STGeometryN(geomCollection, n) Returns the _n_th GEOMETRY of _geomCollection
  • STInteriorRingN(polygon, n) Returns the _n_th interior ring of _polygon
  • STIsClosed(geom) Returns whether _geom is a closed LINESTRING or MULTILINESTRING
  • STIsEmpty(geom) Returns whether _geom is empty
  • STIsRectangle(geom) Returns whether _geom is a rectangle
  • STIsRing(geom) Returns whether _geom is a closed and simple line-string or MULTILINESTRING
  • STIsSimple(geom) Returns whether _geom is simple
  • STIsValid(geom) Returns whether _geom is valid
  • ST_IsValidDetail(geom [, selfTouchValid ]) Returns a valid detail as an array of objects
  • STIsValidReason(geom [, selfTouchValid ]) Returns text stating whether _geom is valid, and if not valid, a reason why
  • STNPoints(geom) Returns the number of points in _geom
  • STNumGeometries(geom) Returns the number of geometries in _geom (1 if it is not a GEOMETRYCOLLECTION)
  • ST_NumInteriorRing(geom) Alias for ST_NumInteriorRings
  • STNumInteriorRings(geom) Returns the number of interior rings of _geom
  • STNumPoints(lineString) Returns the number of points in _lineString
  • STPointN(geom, n) Returns the _n_th point of a _lineString
  • STPointOnSurface(geom) Returns an interior or boundary point of _geom
  • STSRID(geom) Returns SRID value of _geom or 0 if it does not have one
  • STStartPoint(lineString) Returns the first coordinate of _lineString
  • STXMax(geom) Returns the maximum x-value of _geom
  • STXMin(geom) Returns the minimum x-value of _geom
  • STYMax(geom) Returns the maximum y-value of _geom
  • STYMin(geom) Returns the minimum y-value of _geom

Geometry properties (3D)

COperator syntaxDescription
pSTIs3D(s)Returns whether _geom has at least one z-coordinate
oSTZ(geom)Returns the z-value of the first coordinate of _geom

Not implemented:

  • STZMax(geom) Returns the maximum z-value of _geom
  • STZMin(geom) Returns the minimum z-value of _geom

Geometry predicates

COperator syntaxDescription
oSTContains(geom1, geom2)Returns whether _geom1 contains geom2
pSTContainsProperly(geom1, geom2)Returns whether _geom1 contains geom2 but does not intersect its boundary
oSTCrosses(geom1, geom2)Returns whether _geom1 crosses geom2
oSTDisjoint(geom1, geom2)Returns whether _geom1 and geom2 are disjoint
pSTDWithin(geom1, geom2, distance)Returns whether _geom1 and geom are within distance of one another
oSTEnvelopesIntersect(geom1, geom2)Returns whether the envelope of _geom1 intersects the envelope of geom2
oSTEquals(geom1, geom2)Returns whether _geom1 equals geom2
oSTIntersects(geom1, geom2)Returns whether _geom1 intersects geom2
oSTOverlaps(geom1, geom2)Returns whether _geom1 overlaps geom2
oSTTouches(geom1, geom2)Returns whether _geom1 touches geom2
oSTWithin(geom1, geom2)Returns whether _geom1 is within geom2

Not implemented:

  • STCovers(geom1, geom2) Returns whether no point in _geom2 is outside geom1
  • STOrderingEquals(geom1, geom2) Returns whether _geom1 equals geom2 and their coordinates and component Geometries are listed in the same order
  • STRelate(geom1, geom2) Returns the DE-9IM intersection matrix of _geom1 and geom2
  • STRelate(geom1, geom2, iMatrix) Returns whether _geom1 and geom2 are related by the given intersection matrix iMatrix

Geometry operators (2D)

The following functions combine 2D geometries.

COperator syntaxDescription
oSTBuffer(geom, distance [, quadSegs | style ])Computes a buffer around _geom
oSTUnion(geom1, geom2)Computes the union of _geom1 and geom2
oSTUnion(geomCollection)Computes the union of the geometries in _geomCollection

See also: the ST_Union aggregate function.

Not implemented:

  • STConvexHull(geom) Computes the smallest convex polygon that contains all the points in _geom
  • ST_Difference(geom1, geom2) Computes the difference between two geometries
  • ST_Intersection(geom1, geom2) Computes the intersection of two geometries
  • ST_SymDifference(geom1, geom2) Computes the symmetric difference between two geometries

Affine transformation functions (3D and 2D)

Not implemented:

  • STRotate(geom, angle [, origin | x, y]) Rotates a _geom counter-clockwise by angle (in radians) about origin (or the point (x, y))
  • STScale(geom, xFactor, yFactor [, zFactor ]) Scales _geom by multiplying the ordinates by the indicated scale factors
  • STTranslate(geom, x, y, [, z]) Translates _geom

Geometry editing functions (2D)

The following functions modify 2D geometries.

Not implemented:

  • STAddPoint(geom, point [, tolerance ]) Adds _point to geom with a given tolerance (default 0)
  • STCollectionExtract(geom, dimension) Filters _geom, returning a multi-geometry of those members with a given dimension (1 = point, 2 = line-string, 3 = polygon)
  • STDensify(geom, tolerance) Inserts extra vertices every _tolerance along the line segments of geom
  • STFlipCoordinates(geom) Flips the X and Y coordinates of _geom
  • STHoles(geom) Returns the holes in _geom (which may be a GEOMETRYCOLLECTION)
  • STNormalize(geom) Converts _geom to normal form
  • STRemoveDuplicatedCoordinates(geom) Removes duplicated coordinates from _geom
  • STRemoveHoles(geom) Removes a _geom’s holes
  • STRemovePoints(geom, poly) Removes all coordinates of _geom located within poly; null if all coordinates are removed
  • STRemoveRepeatedPoints(geom, tolerance) Removes from _geom all repeated points (or points within tolerance of another point)
  • STReverse(geom) Reverses the vertex order of _geom

Geometry editing functions (3D)

The following functions modify 3D geometries.

Not implemented:

  • STAddZ(geom, zToAdd) Adds _zToAdd to the z-coordinate of geom
  • STInterpolate3DLine(geom) Returns _geom with an interpolation of z values, or null if it is not a line-string or MULTILINESTRING
  • STMultiplyZ(geom, zFactor) Returns _geom with its z-values multiplied by zFactor
  • STReverse3DLine(geom [, sortOrder ]) Potentially reverses _geom according to the z-values of its first and last coordinates
  • STUpdateZ(geom, newZ [, updateCondition ]) Updates the z-values of _geom
  • STZUpdateLineExtremities(geom, startZ, endZ [, interpolate ]) Updates the start and end z-values of _geom

Geometry measurement functions (2D)

Not implemented:

  • STArea(geom) Returns the area of _geom (which may be a GEOMETRYCOLLECTION)
  • STClosestCoordinate(geom, point) Returns the coordinate(s) of _geom closest to point
  • STClosestPoint(geom1, geom2) Returns the point of _geom1 closest to geom2
  • STFurthestCoordinate(geom, point) Returns the coordinate(s) of _geom that are furthest from point
  • STLength(lineString) Returns the length of _lineString
  • STLocateAlong(geom, segmentLengthFraction, offsetDistance) Returns a MULTIPOINT containing points along the line segments of _geom at segmentLengthFraction and offsetDistance
  • STLongestLine(geom1, geom2) Returns the 2-dimensional longest line-string between the points of _geom1 and geom2
  • STMaxDistance(geom1, geom2) Computes the maximum distance between _geom1 and geom2
  • STPerimeter(polygon) Returns the length of the perimeter of _polygon (which may be a MULTIPOLYGON)
  • STProjectPoint(point, lineString) Projects _point onto a lineString (which may be a MULTILINESTRING)

Geometry measurement functions (3D)

Not implemented:

  • ST_3DArea(geom) Return a polygon’s 3D area
  • ST_3DLength(geom) Returns the 3D length of a line-string
  • ST_3DPerimeter(geom) Returns the 3D perimeter of a polygon or MULTIPOLYGON
  • STSunPosition(point [, timestamp ]) Computes the sun position at _point and timestamp (now by default)

Geometry processing functions (2D)

The following functions process geometries.

Not implemented:

  • STLineIntersector(geom1, geom2) Splits _geom1 (a line-string) with geom2
  • ST_LineMerge(geom) Merges a collection of linear components to form a line-string of maximal length
  • STMakeValid(geom [, preserveGeomDim [, preserveDuplicateCoord [, preserveCoordDim]]]) Makes _geom valid
  • STPolygonize(geom) Creates a MULTIPOLYGON from edges of _geom
  • STPrecisionReducer(geom, n) Reduces _geom’s precision to n decimal places
  • ST_RingSideBuffer(geom, distance, bufferCount [, endCapStyle [, doDifference]]) Computes a ring buffer on one side
  • ST_SideBuffer(geom, distance [, bufferStyle ]) Compute a single buffer on one side
  • STSimplify(geom, distance) Simplifies _geom using the Douglas-Peuker algorithm with a distance tolerance
  • STSimplifyPreserveTopology(geom) Simplifies _geom, preserving its topology
  • STSnap(geom1, geom2, tolerance) Snaps _geom1 and geom2 together
  • STSplit(geom1, geom2 [, tolerance]) Splits _geom1 by geom2 using tolerance (default 1E-6) to determine where the point splits the line

Geometry projection functions

COperator syntaxDescription
oSTSetSRID(geom, srid)Returns a copy of _geom with a new SRID
oSTTransform(geom, srid)Transforms _geom from one coordinate reference system (CRS) to the CRS specified by srid

Trigonometry functions

Not implemented:

  • STAzimuth(point1, point2) Return the azimuth of the segment from _point1 to point2

Topography functions

Not implemented:

  • ST_TriangleAspect(geom) Returns the aspect of a triangle
  • ST_TriangleContouring(query [, z1, z2, z3 ][, varArgs]*) Splits triangles into smaller triangles according to classes
  • ST_TriangleDirection(geom) Computes the direction of steepest ascent of a triangle and returns it as a line-string
  • ST_TriangleSlope(geom) Computes the slope of a triangle as a percentage
  • ST_Voronoi(geom [, outDimension [, envelopePolygon ]]) Creates a Voronoi diagram

Triangulation functions

Not implemented:

  • STConstrainedDelaunay(geom [, flag [, quality ]]) Computes a constrained Delaunay triangulation based on _geom
  • ST_Delaunay(geom [, flag [, quality ]]) Computes a Delaunay triangulation based on points
  • STTessellate(polygon) Tessellates _polygon (may be MULTIPOLYGON) with adaptive triangles

Geometry aggregate functions

Not implemented:

  • STAccum(geom) Accumulates _geom into a GEOMETRYCOLLECTION (or MULTIPOINT, MULTILINESTRING or MULTIPOLYGON if possible)
  • ST_Collect(geom) Alias for ST_Accum
  • ST_Union(geom) Computes the union of geometries

JSON Functions

In the following:

  • jsonValue is a character string containing a JSON value;
  • path is a character string containing a JSON path expression; mode flag strict or lax should be specified in the beginning of path.

Query Functions

Operator syntaxDescription
JSONEXISTS(jsonValue, path [ { TRUE | FALSE | UNKNOWN | ERROR ) ON ERROR } )Whether a _jsonValue satisfies a search criterion described using JSON path expression path
JSONVALUE(jsonValue, path [ RETURNING type ] [ { ERROR | NULL | DEFAULT expr } ON EMPTY ] [ { ERROR | NULL | DEFAULT expr } ON ERROR ] )Extract an SQL scalar from a _jsonValue using JSON path expression path
JSONQUERY(jsonValue, path [ { WITHOUT [ ARRAY ] | WITH [ CONDITIONAL | UNCONDITIONAL ] [ ARRAY ] } WRAPPER ] [ { ERROR | NULL | EMPTY ARRAY | EMPTY OBJECT } ON EMPTY ] [ { ERROR | NULL | EMPTY ARRAY | EMPTY OBJECT } ON ERROR ] )Extract a JSON object or JSON array from _jsonValue using the path JSON path expression

Note:

  • The ON ERROR and ON EMPTY clauses define the fallbackbehavior of the function when an error is thrown or a null valueis about to be returned.
  • The ARRAY WRAPPER clause defines how to represent a JSON array resultin JSON_QUERY function. The following examples compare the wrapperbehaviors.

Example Data:

  1. {"a": "[1,2]", "b": [1,2], "c": "hi"}

Comparison:

Operator$.a$.b$.c
JSON_VALUE[1, 2]errorhi
JSON QUERY WITHOUT ARRAY WRAPPERerror[1, 2]error
JSON QUERY WITH UNCONDITIONAL ARRAY WRAPPER[ “[1,2]” ][ [1,2] ][ “hi” ]
JSON QUERY WITH CONDITIONAL ARRAY WRAPPER[ “[1,2]” ][1,2][ “hi” ]

Not implemented:

  • JSON_TABLE

Constructor Functions

Operator syntaxDescription
JSONOBJECT( { [ KEY ] name VALUE value [ FORMAT JSON ] | name : value [ FORMAT JSON ] } * [ { NULL | ABSENT } ON NULL ] )Construct JSON object using a series of key (_name) value (value) pairs
JSONOBJECTAGG( { [ KEY ] name VALUE value [ FORMAT JSON ] | name : value [ FORMAT JSON ] } [ { NULL | ABSENT } ON NULL ] )Aggregate function to construct a JSON object using a key (_name) value (value) pair
JSONARRAY( { value [ FORMAT JSON ] } * [ { NULL | ABSENT } ON NULL ] )Construct a JSON array using a series of values (_value)
JSONARRAYAGG( value [ FORMAT JSON ] [ ORDER BY orderItem [, orderItem ]* ] [ { NULL | ABSENT } ON NULL ] )Aggregate function to construct a JSON array using a value (_value)

Note:

  • The flag FORMAT JSON indicates the value is formatted as JSONcharacter string. When FORMAT JSON is used, the value should bede-parse from JSON character string to a SQL structured value.
  • ON NULL clause defines how the JSON output represents nullvalues. The default null behavior of JSON_OBJECT andJSON_OBJECTAGG is NULL ON NULL, and for JSON_ARRAY andJSON_ARRAYAGG it is ABSENT ON NULL.
  • If ORDER BY clause is provided, JSON_ARRAYAGG sorts theinput rows into the specified order before performing aggregation.

Comparison Operators

Operator syntaxDescription
jsonValue IS JSON [ VALUE ]Whether jsonValue is a JSON value
jsonValue IS NOT JSON [ VALUE ]Whether jsonValue is not a JSON value
jsonValue IS JSON SCALARWhether jsonValue is a JSON scalar value
jsonValue IS NOT JSON SCALARWhether jsonValue is not a JSON scalar value
jsonValue IS JSON OBJECTWhether jsonValue is a JSON object
jsonValue IS NOT JSON OBJECTWhether jsonValue is not a JSON object
jsonValue IS JSON ARRAYWhether jsonValue is a JSON array
jsonValue IS NOT JSON ARRAYWhether jsonValue is not a JSON array

Dialect-specific Operators

The following operators are not in the SQL standard, and are not enabled inCalcite’s default operator table. They are only available for use in queriesif your session has enabled an extra operator table.

To enable an operator table, set thefunconnect string parameter.

The ‘C’ (compatibility) column contains value‘m’ for MySQL (‘fun=mysql’ in the connect string),‘o’ for Oracle (‘fun=oracle’ in the connect string),‘p’ for PostgreSQL (‘fun=postgresql’ in the connect string).

One operator name may correspond to multiple SQL dialects, but with differentsemantics.

COperator syntaxDescription
pexpr :: typeCasts expr to type
oCHR(integer)Returns the character having the binary equivalent to integer as a CHAR value
m o pCONCAT(string [, string ])Concatenates two or more strings
pCONVERTTIMEZONE(tz1, tz2, datetime)Converts the timezone of _datetime from tz1 to tz2
mDAYNAME(datetime)Returns the name, in the connection’s locale, of the weekday in datetime; for example, it returns ‘星期日’ for both DATE ‘2020-02-10’ and TIMESTAMP ‘2020-02-10 10:10:10’
oDECODE(value, value1, result1 [, valueN, resultN ] [, default ])Compares value to each valueN value one by one; if value is equal to a valueN, returns the corresponding resultN, else returns default, or NULL if default is not specified
pDIFFERENCE(string, string)Returns a measure of the similarity of two strings, namely the number of character positions that their SOUNDEX values have in common: 4 if the SOUNDEX values are same and 0 if the SOUNDEX values are totally different
oGREATEST(expr [, expr ])Returns the greatest of the expressions
mJSONTYPE(jsonValue)Returns a string value indicating the type of a _jsonValue
mJSONDEPTH(jsonValue)Returns an integer value indicating the depth of a _jsonValue
mJSONPRETTY(jsonValue)Returns a pretty-printing of _jsonValue
mJSONLENGTH(jsonValue [, path ])Returns a integer indicating the length of _jsonValue
mJSONKEYS(jsonValue [, path ])Returns a string indicating the keys of a JSON _jsonValue
mJSONREMOVE(jsonValue, path[, path])Removes data from _jsonValue using a series of path expressions and returns the result
mJSONSTORAGE_SIZE(jsonValue)Returns the number of bytes used to store the binary representation of a _jsonValue
oLEAST(expr [, expr ] )Returns the least of the expressions
m pLEFT(string, length)Returns the leftmost length characters from the string
mTOBASE64(string)Converts the _string to base-64 encoded form and returns a encoded string
mFROMBASE64(string)Returns the decoded result of a base-64 _string as a string
oLTRIM(string)Returns string with all blanks removed from the start
m pMD5(string)Calculates an MD5 128-bit checksum of string and returns it as a hex string
mMONTHNAME(date)Returns the name, in the connection’s locale, of the month in datetime; for example, it returns ‘二月’ for both DATE ‘2020-02-10’ and TIMESTAMP ‘2020-02-10 10:10:10’
oNVL(value1, value2)Returns value1 if value1 is not null, otherwise value2
m oREGEXPREPLACE(string, regexp, rep, [, pos [, occurrence [, matchType]]])Replaces all substrings of _string that match regexp with rep at the starting pos in expr (if omitted, the default is 1), occurrence means which occurrence of a match to search for (if omitted, the default is 1), matchType specifies how to perform matching
m pREPEAT(string, integer)Returns a string consisting of string repeated of integer times; returns an empty string if integer is less than 1
mREVERSE(string)Returns string with the order of the characters reversed
m pRIGHT(string, length)Returns the rightmost length characters from the string
oRTRIM(string)Returns string with all blanks removed from the end
m pSHA1(string)Calculates a SHA-1 hash value of string and returns it as a hex string
m o pSOUNDEX(string)Returns the phonetic representation of string; throws if string is encoded with multi-byte encoding such as UTF-8
mSPACE(integer)Returns a string of integer spaces; returns an empty string if integer is less than 1
oSUBSTR(string, position [, substringLength ])Returns a portion of string, beginning at character position, substringLength characters long. SUBSTR calculates lengths using characters as defined by the input character set
o pTODATE(string, format)Converts _string to a date using the format format
o pTOTIMESTAMP(string, format)Converts _string to a timestamp using the format format
o pTRANSLATE(expr, fromString, toString)Returns expr with all occurrences of each character in fromString replaced by its corresponding character in toString. Characters in expr that are not in fromString are not replaced

Note:

  • JSON_TYPE / JSON_DEPTH / JSON_PRETTY / JSON_STORAGE_SIZE return null if the argument is null
  • JSON_LENGTH / JSON_KEYS / JSON_REMOVE return null if the first argument is null
  • JSON_TYPE generally returns an upper-case string flag indicating the type of the JSON input. Currently supported supported type flags are:
    • INTEGER
    • STRING
    • FLOAT
    • DOUBLE
    • LONG
    • BOOLEAN
    • DATE
    • OBJECT
    • ARRAY
    • NULL
  • JSON_DEPTH defines a JSON value’s depth as follows:
    • An empty array, empty object, or scalar value has depth 1;
    • A non-empty array containing only elements of depth 1 or non-empty object containing only member values of depth 1 has depth 2;
    • Otherwise, a JSON document has depth greater than 2.
  • JSON_LENGTH defines a JSON value’s length as follows:
    • A scalar value has length 1;
    • The length of array or object is the number of elements is contains.

Usage Examples:

JSON_TYPE example

SQL

  1. SELECT JSON_TYPE(v) AS c1,
  2. JSON_TYPE(JSON_VALUE(v, 'lax $.b' ERROR ON ERROR)) AS c2,
  3. JSON_TYPE(JSON_VALUE(v, 'strict $.a[0]' ERROR ON ERROR)) AS c3,
  4. JSON_TYPE(JSON_VALUE(v, 'strict $.a[1]' ERROR ON ERROR)) AS c4
  5. FROM (VALUES ('{"a": [10, true],"b": "[10, true]"}')) AS t(v)
  6. LIMIT 10;

Result

c1c2c3c4
OBJECTARRAYINTEGERBOOLEAN
JSON_DEPTH example

SQL

  1. SELECT JSON_DEPTH(v) AS c1,
  2. JSON_DEPTH(JSON_VALUE(v, 'lax $.b' ERROR ON ERROR)) AS c2,
  3. JSON_DEPTH(JSON_VALUE(v, 'strict $.a[0]' ERROR ON ERROR)) AS c3,
  4. JSON_DEPTH(JSON_VALUE(v, 'strict $.a[1]' ERROR ON ERROR)) AS c4
  5. FROM (VALUES ('{"a": [10, true],"b": "[10, true]"}')) AS t(v)
  6. LIMIT 10;

Result

c1c2c3c4
3211
JSON_LENGTH example

SQL

  1. SELECT JSON_LENGTH(v) AS c1,
  2. JSON_LENGTH(v, 'lax $.a') AS c2,
  3. JSON_LENGTH(v, 'strict $.a[0]') AS c3,
  4. JSON_LENGTH(v, 'strict $.a[1]') AS c4
  5. FROM (VALUES ('{"a": [10, true]}')) AS t(v)
  6. LIMIT 10;

Result

c1c2c3c4
1211
JSON_KEYS example

SQL

  1. SELECT JSON_KEYS(v) AS c1,
  2. JSON_KEYS(v, 'lax $.a') AS c2,
  3. JSON_KEYS(v, 'lax $.b') AS c2,
  4. JSON_KEYS(v, 'strict $.a[0]') AS c3,
  5. JSON_KEYS(v, 'strict $.a[1]') AS c4
  6. FROM (VALUES ('{"a": [10, true],"b": {"c": 30}}')) AS t(v)
  7. LIMIT 10;

Result

c1c2c3c4c5
[“a”, “b”]NULL[“c”]NULLNULL
JSON_REMOVE example

SQL

  1. SELECT JSON_REMOVE(v, '$[1]') AS c1
  2. FROM (VALUES ('["a", ["b", "c"], "d"]')) AS t(v)
  3. LIMIT 10;

Result

c1
[“a”, “d”]
JSON_STORAGE_SIZE example

SQL

  1. SELECT
  2. JSON_STORAGE_SIZE('[100, \"sakila\", [1, 3, 5], 425.05]') AS c1,
  3. JSON_STORAGE_SIZE('{\"a\": 10, \"b\": \"a\", \"c\": \"[1, 3, 5, 7]\"}') AS c2,
  4. JSON_STORAGE_SIZE('{\"a\": 10, \"b\": \"xyz\", \"c\": \"[1, 3, 5, 7]\"}') AS c3,
  5. JSON_STORAGE_SIZE('[100, \"json\", [[10, 20, 30], 3, 5], 425.05]') AS c4
  6. limit 10;

Result

c1c2c3c4
29353736

DECODE example

SQL

  1. SELECT DECODE(f1, 1, 'aa', 2, 'bb', 3, 'cc', 4, 'dd', 'ee') as c1,
  2. DECODE(f2, 1, 'aa', 2, 'bb', 3, 'cc', 4, 'dd', 'ee') as c2,
  3. DECODE(f3, 1, 'aa', 2, 'bb', 3, 'cc', 4, 'dd', 'ee') as c3,
  4. DECODE(f4, 1, 'aa', 2, 'bb', 3, 'cc', 4, 'dd', 'ee') as c4,
  5. DECODE(f5, 1, 'aa', 2, 'bb', 3, 'cc', 4, 'dd', 'ee') as c5
  6. FROM (VALUES (1, 2, 3, 4, 5)) AS t(f1, f2, f3, f4, f5);

Result

c1c2c3c4c5
aabbccddee

TRANSLATE example

SQL

  1. SELECT TRANSLATE('Aa*Bb*Cc''D*d', ' */''%', '_') as c1,
  2. TRANSLATE('Aa/Bb/Cc''D/d', ' */''%', '_') as c2,
  3. TRANSLATE('Aa Bb Cc''D d', ' */''%', '_') as c3,
  4. TRANSLATE('Aa%Bb%Cc''D%d', ' */''%', '_') as c4
  5. FROM (VALUES (true)) AS t(f0);

Result

c1c2c3c4
Aa_Bb_CcD_dAa_Bb_CcD_dAa_Bb_CcD_dAa_Bb_CcD_d

Not implemented:

  • JSON_INSERT
  • JSON_SET
  • JSON_REPLACE

User-defined functions

Calcite is extensible. You can define each kind of function using user code.For each kind of function there are often several ways to define a function,varying from convenient to efficient.

To implement a scalar function, there are 3 options:

  • Create a class with a public static eval method,and register the class;
  • Create a class with a public non-static eval method,and a public constructor with no arguments,and register the class;
  • Create a class with one or more public static methods,and register each class/method combination.

To implement an aggregate function, there are 2 options:

  • Create a class with public static init, add and result methods,and register the class;
  • Create a class with public non-static init, add and result methods,and a public constructor with no arguments,and register the class.

Optionally, add a public merge method to the class; this allows Calcite togenerate code that merges sub-totals.

Optionally, make your class implement theSqlSplittableAggFunctioninterface; this allows Calcite to decompose the function across several stagesof aggregation, roll up from summary tables, and push it through joins.

To implement a table function, there are 3 options:

To implement a table macro, there are 3 options:

  • Create a class with a static eval method that returnsTranslatableTable,and register the class;
  • Create a class with a non-static eval method that returnsTranslatableTable,and register the class;
  • Create a class with one or more public static methods that returnTranslatableTable,and register each class/method combination.

Calcite deduces the parameter types and result type of a function from theparameter and return types of the Java method that implements it. Further, youcan specify the name and optionality of each parameter using theParameterannotation.

Calling functions with named and optional parameters

Usually when you call a function, you need to specify all of its parameters,in order. But that can be a problem if a function has a lot of parameters,and especially if you want to add more parameters over time.

To solve this problem, the SQL standard allows you to pass parameters by name,and to define parameters which are optional (that is, have a default valuethat is used if they are not specified).

Suppose you have a function f, declared as in the following pseudo syntax:

  1. FUNCTION f(
  2. INTEGER a,
  3. INTEGER b DEFAULT NULL,
  4. INTEGER c,
  5. INTEGER d DEFAULT NULL,
  6. INTEGER e DEFAULT NULL) RETURNS INTEGER

All of the function’s parameters have names, and parameters b, d and ehave a default value of NULL and are therefore optional.(In Calcite, NULL is the only allowable default value for optional parameters;this may changein future.)

When calling a function with optional parameters,you can omit optional arguments at the end of the list, or use the DEFAULTkeyword for any optional arguments.Here are some examples:

  • f(1, 2, 3, 4, 5) provides a value to each parameter, in order;
  • f(1, 2, 3, 4) omits e, which gets its default value, NULL;
  • f(1, DEFAULT, 3) omits d and e,and specifies to use the default value of b;
  • f(1, DEFAULT, 3, DEFAULT, DEFAULT) has the same effect as the previousexample;
  • f(1, 2) is not legal, because c is not optional;
  • f(1, 2, DEFAULT, 4) is not legal, because c is not optional.

You can specify arguments by name using the => syntax.If one argument is named, they all must be.Arguments may be in any other, but must not specify any argument more than once,and you need to provide a value for every parameter which is not optional.Here are some examples:

  • f(c => 3, d => 1, a => 0) is equivalent to f(0, NULL, 3, 1, NULL);
  • f(c => 3, d => 1) is not legal, because you have not specified a value fora and a is not optional.

MATCH_RECOGNIZE

MATCH_RECOGNIZE is a SQL extension for recognizing sequences ofevents in complex event processing (CEP).

It is experimental in Calcite, and yet not fully implemented.

Syntax

  1. matchRecognize:
  2. MATCH_RECOGNIZE '('
  3. [ PARTITION BY expression [, expression ]* ]
  4. [ ORDER BY orderItem [, orderItem ]* ]
  5. [ MEASURES measureColumn [, measureColumn ]* ]
  6. [ ONE ROW PER MATCH | ALL ROWS PER MATCH ]
  7. [ AFTER MATCH
  8. ( SKIP TO NEXT ROW
  9. | SKIP PAST LAST ROW
  10. | SKIP TO FIRST variable
  11. | SKIP TO LAST variable
  12. | SKIP TO variable )
  13. ]
  14. PATTERN '(' pattern ')'
  15. [ WITHIN intervalLiteral ]
  16. [ SUBSET subsetItem [, subsetItem ]* ]
  17. DEFINE variable AS condition [, variable AS condition ]*
  18. ')'
  19. subsetItem:
  20. variable = '(' variable [, variable ]* ')'
  21. measureColumn:
  22. expression AS alias
  23. pattern:
  24. patternTerm [ '|' patternTerm ]*
  25. patternTerm:
  26. patternFactor [ patternFactor ]*
  27. patternFactor:
  28. patternPrimary [ patternQuantifier ]
  29. patternPrimary:
  30. variable
  31. | '$'
  32. | '^'
  33. | '(' [ pattern ] ')'
  34. | '{-' pattern '-}'
  35. | PERMUTE '(' pattern [, pattern ]* ')'
  36. patternQuantifier:
  37. '*'
  38. | '*?'
  39. | '+'
  40. | '+?'
  41. | '?'
  42. | '??'
  43. | '{' { [ minRepeat ], [ maxRepeat ] } '}' ['?']
  44. | '{' repeat '}'
  45. intervalLiteral:
  46. INTERVAL 'string' timeUnit [ TO timeUnit ]

In patternQuantifier, repeat is a positive integer,and minRepeat and maxRepeat are non-negative integers.

DDL Extensions

DDL extensions are only available in the calcite-server module.To enable, include calcite-server.jar in your class path, and addparserFactory=org.apache.calcite.sql.parser.ddl.SqlDdlParserImpl#FACTORYto the JDBC connect string (see connect string propertyparserFactory).

  1. ddlStatement:
  2. createSchemaStatement
  3. | createForeignSchemaStatement
  4. | createTableStatement
  5. | createViewStatement
  6. | createMaterializedViewStatement
  7. | createTypeStatement
  8. | createFunctionStatement
  9. | dropSchemaStatement
  10. | dropForeignSchemaStatement
  11. | dropTableStatement
  12. | dropViewStatement
  13. | dropMaterializedViewStatement
  14. | dropTypeStatement
  15. | dropFunctionStatement
  16. createSchemaStatement:
  17. CREATE [ OR REPLACE ] SCHEMA [ IF NOT EXISTS ] name
  18. createForeignSchemaStatement:
  19. CREATE [ OR REPLACE ] FOREIGN SCHEMA [ IF NOT EXISTS ] name
  20. (
  21. TYPE 'type'
  22. | LIBRARY 'com.example.calcite.ExampleSchemaFactory'
  23. )
  24. [ OPTIONS '(' option [, option ]* ')' ]
  25. option:
  26. name literal
  27. createTableStatement:
  28. CREATE TABLE [ IF NOT EXISTS ] name
  29. [ '(' tableElement [, tableElement ]* ')' ]
  30. [ AS query ]
  31. createTypeStatement:
  32. CREATE [ OR REPLACE ] TYPE name AS
  33. {
  34. baseType
  35. | '(' attributeDef [, attributeDef ]* ')'
  36. }
  37. attributeDef:
  38. attributeName type
  39. [ COLLATE collation ]
  40. [ NULL | NOT NULL ]
  41. [ DEFAULT expression ]
  42. tableElement:
  43. columnName type [ columnGenerator ] [ columnConstraint ]
  44. | columnName
  45. | tableConstraint
  46. columnGenerator:
  47. DEFAULT expression
  48. | [ GENERATED ALWAYS ] AS '(' expression ')'
  49. { VIRTUAL | STORED }
  50. columnConstraint:
  51. [ CONSTRAINT name ]
  52. [ NOT ] NULL
  53. tableConstraint:
  54. [ CONSTRAINT name ]
  55. {
  56. CHECK '(' expression ')'
  57. | PRIMARY KEY '(' columnName [, columnName ]* ')'
  58. | UNIQUE '(' columnName [, columnName ]* ')'
  59. }
  60. createViewStatement:
  61. CREATE [ OR REPLACE ] VIEW name
  62. [ '(' columnName [, columnName ]* ')' ]
  63. AS query
  64. createMaterializedViewStatement:
  65. CREATE MATERIALIZED VIEW [ IF NOT EXISTS ] name
  66. [ '(' columnName [, columnName ]* ')' ]
  67. AS query
  68. createFunctionStatement:
  69. CREATE [ OR REPLACE ] FUNCTION [ IF NOT EXISTS ] name
  70. AS classNameLiteral
  71. [ USING usingFile [, usingFile ]* ]
  72. usingFile:
  73. ( JAR | FILE | ARCHIVE ) filePathLiteral
  74. dropSchemaStatement:
  75. DROP SCHEMA [ IF EXISTS ] name
  76. dropForeignSchemaStatement:
  77. DROP FOREIGN SCHEMA [ IF EXISTS ] name
  78. dropTableStatement:
  79. DROP TABLE [ IF EXISTS ] name
  80. dropViewStatement:
  81. DROP VIEW [ IF EXISTS ] name
  82. dropMaterializedViewStatement:
  83. DROP MATERIALIZED VIEW [ IF EXISTS ] name
  84. dropTypeStatement:
  85. DROP TYPE [ IF EXISTS ] name
  86. dropFunctionStatement:
  87. DROP FUNCTION [ IF EXISTS ] name

In createTableStatement, if you specify AS query, you may omit the list oftableElement_s, or you can omit the data type of any _tableElement, in whichcase it just renames the underlying column.

In columnGenerator, if you do not specify VIRTUAL or STORED for agenerated column, VIRTUAL is the default.

In createFunctionStatement and usingFile, classNameLiteral_and _filePathLiteral are character literals.