# Lexical syntax

> Keywords, identifiers, literals, comments, parameters, INTERVAL literals and the one-statement, 64 KiB request boundary.

These are the lexical rules of NYXDB SQL.

## Keywords

Keywords are case-insensitive: `select`, `SELECT` and `Select` are the same
keyword. The pages of this reference write them in upper case.

## Identifiers

An identifier names a table, column, index, attribute group, view or
transformation.

- It starts with an ASCII letter or `_` and continues with ASCII letters,
  digits and `_`.
- It is at most 128 bytes.
- It is case-insensitive and stored in lower case: a table created as
  `Balances` is the table `balances`. Prefer snake_case names.
- Double quotes delimit an identifier that contains spaces or punctuation.
- A system relation is named with a dot, such as `system.tables`, and a column
  can be qualified by its relation alias, such as `t.token`.

## Literals

| Literal | Form |
| --- | --- |
| string | single quotes; a quote inside is written twice, so `'it''s'` is `it's` |
| number | decimal digits with an optional fractional part, such as `42` or `-12.50`; no exponent and no hexadecimal form |
| Boolean | `TRUE`, `FALSE` |
| null | `NULL` |

Typed values such as dates, timestamps and UUIDs are written as string literals
and converted to the column's type. The accepted spellings are on
[Data types](/docs/sql/data-types) and [INSERT](/docs/sql/insert).

## Comments

- `--` starts a comment that runs to the end of the line (a line feed or a
  carriage return).
- `/* … */` is a block comment. Block comments do not nest: the first `*/`
  closes the comment. The error for an unterminated block comment gives the
  byte offset where it starts.
- Comment markers inside a string literal are text, not comments.

A statement holds at least one token besides comments.

## Parameters

An unquoted `?` in a statement is a positional parameter. Its value is sent
with the request, in parameter order, and is bound to the type of the column it
is compared with. A `?` inside a string literal is text. See
[Protocol](/docs/drivers/protocol) for how parameter values are carried, and
[SELECT](/docs/sql/select) for an example.

Named parameters of the form `${name:TYPE}` belong to parameterized views and
materialized views; see [Views](/docs/sql/views).

## INTERVAL literals

`INTERVAL <n> <unit>` is a duration: `n` is a positive integer without a sign or
a fractional part, and the unit is one of `MICROSECOND`, `MILLISECOND`,
`SECOND`, `MINUTE`, `HOUR` or `DAY`, in the singular or with a trailing `S`
(`INTERVAL 5 MINUTES`). Intervals appear in window relations and `EMIT` clauses
of [streaming queries](/docs/sql/streaming) and as values of the
[SETTINGS](/docs/sql/settings) clause.

## One statement per request

A request carries one statement, with an optional trailing `;`. The statement
text, comments included, is up to 64 KiB.

Statements are sent over HTTP `POST /sql` or as frames of a WebSocket session;
see [Protocol](/docs/drivers/protocol). Session statements such as `SET` and the
federation statements run on a WebSocket session.

---

Source: https://nyxdb.io/docs/sql/syntax/
