This article provides reference information for the following:Documentation Index
Fetch the complete documentation index at: https://docs.ditto.live/llms.txt
Use this file to discover all available pages before exploring further.
Identifiers
Path Expressions
String Literals
Comments
Reserved Keywords
Identifiers
Identifiers are the names of collections, documents, fields, and other database objects.Rules for Identifiers
| Rule | Guidelines |
|---|---|
| Case-Sensitivity |
|
Examples: (these are distinct identifiers and do not refer to the same field)
| |
| Non-Quoted Identifiers |
|
Examples:
| |
| Quoted Identifiers | Quote identifiers using backticks (grave accent)(`)(U+0060)
|
Examples:
|
Reserved Identifiers
The following table provides an overview of the DQL-specific restrictions that supersede common identifier rules:| Element | Rule |
|---|---|
| Document Identifier | _id is a reserved identifier for the document ID. All documents must have an assigned document ID. |
| System Collection Identifiers | Double underscore (__) is a reserved identifier prefix for collections. Double underscore denotes a Ditto system collection. |
Path Expressions
Since Ditto stores data as JSON-like documents, you can use keypath indexing, known commonly as dot syntax, to navigate and reference specific parts of a Ditto document when performing query operations in DQL. To separate a name in a path, use a dot (.).
For example, to navigate to the seats field in a SELECT statement:
JSON
Rules for Path Expressions
Following is an overview of the of the DQL-specific restrictions that supersede common rules:| Topic | Guidelines |
|---|---|
| Path Evaluation | Path expressions are evaluated from left to right. For example, a.b.c:
|
| Collections | Collection names or aliases can be present in path expressions to fully qualify them. If absent, the collection is added during the statement formalisation process, for example in SELECT a one, cars.a two FROM cars, both projection elements one and two refer to the same field. |
| Types | Only REGISTER with nested JSON object and MAP types can be navigated with path expressions. |
MISSING | The path expression result is MISSING if any element does not exist. |
Attachment Path Expressions
Attachments in Ditto have a specific structure that can be navigated using path expressions.Attachment Structure
An attachment field contains:id: The attachment identifierlen: The length in bytesmetadata: Optional metadata object
Path Expression Rules for Attachments
When navigating into anATTACHMENT field:
- Path expressions can access
id,len, andmetadatafields - Accessing
metadatareturns the metadata object if present, orMISSINGif not - Further navigation into
metadatais allowed
DQL
Attachment Errors
Certain operations on attachments will cause errors:- Attempting to navigate to fields other than
id,len, ormetadata - Using array subscripting on attachments
- Treating attachments as arrays or regular objects
For more information on working with attachments, see Working with Attachments.
String Literals
In versions prior to version 5.0:
Enclose
string literals in single quotes ('') in DQL; for example 'blue'.string literals in single ('') or double ("") quotes in DQL; for example 'blue' or "blue":
DQL
Escape Sequences
To include special characters in strings:- Single quote in single-quoted string: Use two single quotes
''- Example:
'he''llo'represents the stringhe'llo
- Example:
- Escape sequences: Use the
eprefix to enable common escape sequences- Example:
e"\""represents a string containing a double quote - Example:
e"\n"represents a newline character - Without the
eprefix,"\n"is a string containing a backslash followed byn
- Example:
Other Literals
Number Literals
Numbers can be specified as-is:- Decimal:
123,45.67,-89.0 - Hexadecimal: Use the
0xprefix, e.g.,0xFF,0x1A2B
Boolean and NULL Literals
TRUE,FALSE, andNULLcan be specified as-is- Case does not matter:
true,True,TRUEare all equivalent
Array Literals
Array literals use standard JSON syntax with square brackets:- Empty array:
[] - Array with elements:
[1, "a", true, null]
DQL
Object Literals
Object literals use standard JSON syntax with curly braces:- Empty object:
{} - Object with fields:
{"a": 1, "b": true, "c": "text"}
DQL
Array and object literals are supported in SDK 4.8+. For earlier versions, use parameters to pass arrays and objects.
Parameters
To protect against SQL injection attacks, DQL supports parameterized queries. Parameters take the place of literals and are replaced with actual values at execution time.Parameter Syntax
A parameter consists of a colon: followed by the parameter name:
DQL
Parameter Names
Parameter names follow the same rules as identifiers:- Regular parameter names:
:abc_4u,:foo,:id - Delimited parameter names use backtick-quoted identifiers:
- Parameter names are case-sensitive:
:Colorand:colorare different
Where Parameters Are Supported
Parameters can be used in:WHEREclausesORDER BYclausesLIMITclausesOFFSETclausesDOCUMENTSclause in INSERT- Mutators in UPDATE
Parameter Examples
DQL
Comments
DQL supports both inline and multi-line comments.Inline Comments
Inline comments start with-- and continue to the end of the line:
DQL
Multi-line Comments
Multi-line comments are enclosed by/* and */:
DQL
Nested Block Comments
Block comments can be nested. Within a block comment:/*always starts a nested block comment*/always ends the innermost block comment- These symbols cannot be escaped
DQL
DQL
Directive Comments
Special comment syntax can be used to specify query directives:DQL
Reserved Keywords
The following table provides a complete overview of the reserved keywords in DQL. Identifiers that are the same as a reserved keyword may still be used, but must be quoted (see: Rules for identifiers)ALL
ALTER
AND
ANTI
ANY
APPLY
ARRAY
AS
ASC
AT
BETWEEN
BINARY
BOOLEAN
BOTH
BY
CASE
CAST
COLLECTION
CONTEXT
CREATE
CROSS
CURRENT
DEFAULT
DELETE
DESC
DISTINCT
DISTRIBUTE
DO
DOCUMENTS
DROP
ELEMENT
ELSE
END
ESCAPE
EVERY
EVICT
EXCEPT
EXISTS
EXPLAIN
FAIL
FALSE
FETCH
FILTER
FLOAT
ALTER
AND
ANTI
ANY
APPLY
ARRAY
AS
ASC
AT
BETWEEN
BINARY
BOOLEAN
BOTH
BY
CASE
CAST
COLLECTION
CONTEXT
CREATE
CROSS
CURRENT
DEFAULT
DELETE
DESC
DISTINCT
DISTRIBUTE
DO
DOCUMENTS
DROP
ELEMENT
ELSE
END
ESCAPE
EVERY
EVICT
EXCEPT
EXISTS
EXPLAIN
FAIL
FALSE
FETCH
FILTER
FLOAT
FOLLOWING
FOR
FROM
FULL
GROUP
GROUPS
HAVING
ILIKE
IN
INCREMENT
INDEX
INITIAL
INNER
INSERT
INT
INTEGER
INTERSECT
INTO
IS
JOIN
LANGUAGE
LATERAL
LEADING
LEFT
LIKE
LIMIT
MERGE
MISSING
NOT
NOTHING
NULL
OBJECT
OFFSET
ON
OPERATOR
OR
ORDER
OUTER
OVER
PARTITION
PEERS
POSITION
PRECEDING
RANGE
FOR
FROM
FULL
GROUP
GROUPS
HAVING
ILIKE
IN
INCREMENT
INDEX
INITIAL
INNER
INSERT
INT
INTEGER
INTERSECT
INTO
IS
JOIN
LANGUAGE
LATERAL
LEADING
LEFT
LIKE
LIMIT
MERGE
MISSING
NOT
NOTHING
NULL
OBJECT
OFFSET
ON
OPERATOR
OR
ORDER
OUTER
OVER
PARTITION
PEERS
POSITION
PRECEDING
RANGE
RAW
RESET
RETURNING
RIGHT
ROW
ROWS
SELECT
SEMI
SET
SHOW
SIMILAR
SORT
STRING
SUBSTRING
SYNC
SYSTEM
TABLE
TEMP
TEMPORARY
THEN
TO
TOMBSTONE
TRAILING
TRIM
TRUE
UNBOUNDED
UNION
UNKNOWN
UNNEST
UNSET
UPDATE
UPDATE_LOCAL_DIFF
USE
USING
VALUE
VALUES
VIEW
WHEN
WHERE
WITH
WITHIN
XOR
RESET
RETURNING
RIGHT
ROW
ROWS
SELECT
SEMI
SET
SHOW
SIMILAR
SORT
STRING
SUBSTRING
SYNC
SYSTEM
TABLE
TEMP
TEMPORARY
THEN
TO
TOMBSTONE
TRAILING
TRIM
TRUE
UNBOUNDED
UNION
UNKNOWN
UNNEST
UNSET
UPDATE
UPDATE_LOCAL_DIFF
USE
USING
VALUE
VALUES
VIEW
WHEN
WHERE
WITH
WITHIN
XOR
Previously reserved keywords
The following keywords were reserved in earlier versions but are no longer reserved as of version 5.0:AGAINST
ANALYZE
ARRAY_AGG
ATTACHMENT
BIGINT
BLOB
BYTEA
CEIL
CENTURY
CHAR
CHARACTER
CHARACTERS
CLOB
CLUSTER
COLLATE
CONFLICT
COUNT
COUNTER
CURRENT_DATE
CURRENT_TIME
CURRENT_TIMESTAMP
DATE
DATETIME
DAY
DEC
DECADE
DECIMAL
DOUBLE
DOW
DOY
ENUM
EPOCH
ERROR
EXPANSION
EXTRACT
ANALYZE
ARRAY_AGG
ATTACHMENT
BIGINT
BLOB
BYTEA
CEIL
CENTURY
CHAR
CHARACTER
CHARACTERS
CLOB
CLUSTER
COLLATE
CONFLICT
COUNT
COUNTER
CURRENT_DATE
CURRENT_TIME
CURRENT_TIMESTAMP
DATE
DATETIME
DAY
DEC
DECADE
DECIMAL
DOUBLE
DOW
DOY
ENUM
EPOCH
ERROR
EXPANSION
EXTRACT
FLOOR
HOUR
ID
INHERIT
INTERVAL
ISODOW
ISOYEAR
JULIAN
LARGE
LISTAGG
LOCALTIME
LOCALTIMESTAMP
MAP
MEDIUMINT
MICROSECOND
MICROSECONDS
MILLENIUM
MILLENNIUM
MILLISECOND
MILLISECONDS
MINUTE
MODE
MONTH
NANOSECOND
NANOSECONDS
NATURAL
NUMERIC
NVARCHAR
OCTETS
OUTPUTFORMAT
OVERFLOW
OVERLAY
PERCENT
PLACING
PNCOUNTER
HOUR
ID
INHERIT
INTERVAL
ISODOW
ISOYEAR
JULIAN
LARGE
LISTAGG
LOCALTIME
LOCALTIMESTAMP
MAP
MEDIUMINT
MICROSECOND
MICROSECONDS
MILLENIUM
MILLENNIUM
MILLISECOND
MILLISECONDS
MINUTE
MODE
MONTH
NANOSECOND
NANOSECONDS
NATURAL
NUMERIC
NVARCHAR
OCTETS
OUTPUTFORMAT
OVERFLOW
OVERLAY
PERCENT
PLACING
PNCOUNTER
PRECISION
QUALIFY
QUARTER
QUERY
REAL
REGCLASS
REGISTER
SAFE_CAST
SECOND
SMALLINT
STCOUNTER
TEXT
TIES
TIME
TIMESTAMP
TIMESTAMPTZ
TIMETZ
TIMEZONE
TIMEZONE_HOUR
TIMEZONE_MINUTE
TINYINT
TOP
TRUNCATE
TRY_CAST
UNLOGGED
UNSIGNED
UUID
VALID
VARBINARY
VARCHAR
VARYING
WEEK
WITHOUT
YEAR
ZONE
QUALIFY
QUARTER
QUERY
REAL
REGCLASS
REGISTER
SAFE_CAST
SECOND
SMALLINT
STCOUNTER
TEXT
TIES
TIME
TIMESTAMP
TIMESTAMPTZ
TIMETZ
TIMEZONE
TIMEZONE_HOUR
TIMEZONE_MINUTE
TINYINT
TOP
TRUNCATE
TRY_CAST
UNLOGGED
UNSIGNED
UUID
VALID
VARBINARY
VARCHAR
VARYING
WEEK
WITHOUT
YEAR
ZONE