3. SQL syntax
The SQL syntax lets filters be written as SQL WHERE predicates, which are compact and readable in URLs. It is a restricted grammar, not SQL: implementations parse it into the filter model (section 1) and never send it to a database.
SQL_PARSE MUST
An implementation MUST parse SQL syntax with the grammar in this section and translate it into the filter model.
SQL_NO_PASSTHROUGH MUST NOT
An implementation MUST NOT pass SQL syntax text, in whole or in part, to a data source.
SQL_REJECT MUST
An implementation MUST fail on any input that does not match the grammar, including subqueries, function calls, comments and statements other than predicates.
3.1 Grammar
Section titled “3.1 Grammar”The grammar uses ABNF (RFC 5234). Keywords are case-insensitive. Optional whitespace (ws: one or more spaces, tabs, carriage returns and line feeds) is allowed between tokens; the grammar shows ws only where it is required. Inside strings, '' represents one '.
SQL_KEYWORD_BOUNDARY MUST NOT
A keyword MUST NOT be immediately preceded or followed by a letter, a digit, _ or -: a=1ORb=2 is invalid, while a='x'OR b=2 is valid.
SQL_QUOTED_NAMES MUST
Field paths follow PATH_DOT_NOTATION (section 1.2), except that a field name (the name of a segment, not counting its indexes) that contains characters other than letters, digits, _ and -, or that is equal to a keyword (such as AND or IN), MUST be quoted: "Customer name" = 'Ana', items[0].price > 10.
filter = or-expror-expr = and-expr *( "OR" and-expr )and-expr = not-expr *( "AND" not-expr )not-expr = "NOT" not-expr / primaryprimary = "(" filter ")" / predicatepredicate = field tailtail = comp-op literal / [ "NOT" ] "IN" "(" literal *( "," literal ) ")" / [ "NOT" ] "BETWEEN" literal "AND" literal / [ "NOT" ] "LIKE" string / "IS" [ "NOT" ] "NULL"comp-op = "=" / "!=" / "<>" / ">=" / ">" / "<=" / "<"field = sql-segment *( "." sql-segment )sql-segment = ( 1*( ALPHA / DIGIT / "_" / "-" ) / quoted ) *index ; quoted, index: section 1.2literal = string / number / "TRUE" / "FALSE" / "NULL" / "TIMESTAMP" ws string / "DATE" ws stringstring = "'" *( %x20-26 / %x28-7E / "''" / non-ascii ) "'"number = [ "-" ] 1*DIGIT [ "." 1*DIGIT ] [ ( "e" / "E" ) [ "+" / "-" ] 1*DIGIT ]non-ascii = %x80-D7FF / %xE000-10FFFF ; Unicode scalar values, encoded as UTF-8ws = 1*( WSP / CR / LF )3.2 Mapping to the filter model
Section titled “3.2 Mapping to the filter model”| SQL syntax | Filter model |
|---|---|
f = v, f != v, f <> v |
eq, ne |
f > v, f >= v, f < v, f <= v |
gt, gte, lt, lte |
f IN (a, b), f NOT IN (a, b) |
in, nin |
f BETWEEN a AND b |
and of gte a and lte b |
f NOT BETWEEN a AND b |
not of the above |
f LIKE p, f NOT LIKE p |
like, not of like |
f IS NULL, f IS NOT NULL |
eq null, ne null |
f = NULL, f != NULL, f <> NULL |
eq null, ne null |
f > NULL and other ranges with NULL |
invalid (ORDER_TYPES) |
AND, OR, NOT |
and, or, not |
3.3 Typed literals
Section titled “3.3 Typed literals”SQL_TYPED_LITERALS MUST
TIMESTAMP '<value>' MUST be interpreted as an ECSON $date whose string form is <value> (RFC 3339), and DATE '<value>' as an ECSON $plaindate whose string form is <value>.
SQL_TYPED_LITERAL_INVALID MUST
A typed literal whose value does not satisfy the ECSON type definition (ECSON TYPEDEF_VALIDATE, with TYPE_DATE_READ_STRICT for $date) MUST make the filter fail.
Source: lingodata/unquery@865de91 · spec/sections/03-sql-syntax.md · unquery 0.1.0 (draft)
LingoData specifications, reference implementations and this site are licensed under the Apache License 2.0. Copyright 2026 Gustavo Gondim.