> For the complete documentation index, see [llms.txt](https://mariadb.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mariadb.com/docs/gridgain/gridgain-9/reference/sql/grammar-reference.md).

# Grammar Reference

Reference for the shared SQL grammar elements used across GridGain 9 DDL, DML, and other SQL statements, with the BNF syntax for each production.

This section describes grammar elements that are common to multiple SQL functions ([DDL](/docs/gridgain/gridgain-9/reference/sql/ddl.md), [Distribution Zones](/docs/gridgain/gridgain-9/reference/sql/distribution-zones.md), etc.).

## assign

```bnf
identifier = expression
```

### Parameters

* `identifier` - the name of table, column or other element that will be updated by the operation.
* `expression` - a valid SQL expression that returns the values that must be assigned to the `identifier`.

Referenced by:

* [MERGE](/docs/gridgain/gridgain-9/reference/sql/dml.md#merge)
* [UPDATE](/docs/gridgain/gridgain-9/reference/sql/dml.md#update)

## column\_definition

```bnf
column_name data_type [ [NOT] NULL ]
  [ DEFAULT { rand_uuid()
            | NEXTVAL ( sequence_name )
            | literal_value
            | CURRENT_TIMESTAMP + INTERVAL interval_string interval_qualifier } ]
  [ PRIMARY KEY ]
```

![Railroad diagram for column\_definition — equivalent to the BNF above](https://709350093-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoHbGEk22iR73P3x6DryR%2Fuploads%2Fgit-blob-13d5e69fa7e97ec04b2a67c807268d72b2452dd2%2Fgg9-sql-reference-columns_definition_bnf.svg?alt=media)

Keywords and parameters:

* `column_name` - a column name.
* `DATA TYPE` - the [data type](/docs/gridgain/gridgain-9/reference/sql/data-types.md) allowed in the column.
* `rand_uuid()` - the function that generates a random UUID identifier.
* `sequence_name` - the name of the sequence to use with `NEXTVAL()` function.
* `literal_value` - a value to be assigned as default.
* `CURRENT_TIMESTAMP` - the function that returns current time. Can only be used for `TIMESTAMP WITH LOCAL TIME ZONE` columns.
* `interval_string` - a string literal representing an integer number that specifies the offset amount. For example: `'1'`, `'5'`, or `'30'`. If the interval is `'0'`, current time is used
* `interval_qualifier` - the time unit for the interval offset. Can be one of:
  * `SECOND` or `SECONDS`
  * `MINUTE` or `MINUTES`
  * `HOUR` or `HOURS`
  * `DAY` or `DAYS`
  * `MONTH` or `MONTHS`

Referenced by:

* [CREATE TABLE](/docs/gridgain/gridgain-9/reference/sql/ddl.md#create-table)
* [CREATE CACHE](/docs/gridgain/gridgain-9/reference/sql/ddl.md#create-cache)
* [ALTER TABLE](/docs/gridgain/gridgain-9/reference/sql/ddl.md#alter-table)
* [project\_item](#project_item)
* [join\_condition](#join_condition)

## column\_definition\_or\_list

```bnf
{ column_name data_type
| ( column_name data_type [, column_name data_type]... ) }
```

![Railroad diagram for column\_definition\_or\_list — equivalent to the BNF above](https://709350093-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoHbGEk22iR73P3x6DryR%2Fuploads%2Fgit-blob-3654ada9df4a1b7228176a7819f22ee6d8b185aa%2Fgg9-sql-reference-column_definition_or_list_bnf.svg?alt=media)

Keywords and parameters:

* `column_name` - a column name.
* `data_type` - a valid [data type](/docs/gridgain/gridgain-9/reference/sql/data-types.md).

Referenced by:

* [ALTER TABLE](/docs/gridgain/gridgain-9/reference/sql/ddl.md#alter-table)
* [with\_item](#with_item)

## column\_list

```bnf
( column_name [, column_name]... )
```

![Railroad diagram for column\_list — equivalent to the BNF above](https://709350093-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoHbGEk22iR73P3x6DryR%2Fuploads%2Fgit-blob-47460f2081e70f72457c6be890981054b17f88a4%2Fgg9-sql-reference-column_list_bnf.svg?alt=media)

Keywords and parameters:

* `column_name` - a column name.

Referenced by:

* [INSERT](/docs/gridgain/gridgain-9/reference/sql/dml.md#insert)
* [join\_condition](#join_condition)

## column\_name\_or\_list

```bnf
{ column_name
| ( column_name [, column_name]... ) }
```

Keywords and parameters:

* `column_name` - a column name.

Referenced by:

* [ALTER TABLE](/docs/gridgain/gridgain-9/reference/sql/ddl.md#alter-table)

## constraint

```bnf
[ CONSTRAINT constraint_name ]
  PRIMARY KEY
  [ USING { SORTED sorted_column_list
          | HASH column_list } ]
```

![Railroad diagram for constraint — equivalent to the BNF above](https://709350093-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoHbGEk22iR73P3x6DryR%2Fuploads%2Fgit-blob-cb13482c328111d9d2cfbc56aaddda210b8ecd4c%2Fgg9-sql-reference-pk_constraint_bnf.svg?alt=media)

Keywords and parameters:

* `constraint_name` - a name of the constraint.

Referenced by:

* [CREATE TABLE](/docs/gridgain/gridgain-9/reference/sql/ddl.md#create-table)
* [CREATE CACHE](/docs/gridgain/gridgain-9/reference/sql/ddl.md#create-cache)

## group\_item

```bnf
{ expression
| ( )
| ( expression [, expression]... ) }
```

### Parameters

* `expression` - a valid SQL expression that returns the values that must be assigned to the `identifier`.

Referenced by:

* [SELECT](/docs/gridgain/gridgain-9/reference/sql/operational-commands.md#select)

## join\_condition

```bnf
{ ON boolean_expression
| USING column_list }
```

### Parameters

* `boolean_expression` - an SQL expression that returns a boolean value. Only the records for which `TRUE` was returned will be returned. If not specified, all matching records are returned.

Referenced by:

* [table\_expression](#table_expression)

## order\_item

```bnf
expression [ ASC | DESC ] [ NULLS FIRST | NULLS LAST ]
```

### Parameters

* `expression` - a valid SQL expression that denotes the specific item in the SELECT clause.

Referenced by:

* [query](#query)

## parameter

```bnf
parameter_name = parameter_value
```

Parameters:

* `parameter_name` - the name of the parameter.
* `parameter_value` - the value of the parameter.

When a parameter is specified, you can provide it as a literal value or as an identifier. For example:

```sql
CREATE ZONE test_zone;
CREATE TABLE test_table (id INT PRIMARY KEY, val INT) ZONE test_zone;
```

In this case, `test_zone` is the identifier, and is used as an identifier. When used like this, the parameters are not case-sensitive.

```sql
CREATE ZONE "test_zone";
CREATE TABLE test_table (id INT PRIMARY KEY, val INT) ZONE 'test_zone';
```

In this case, `test_zone` is created as a literal value, and is used as a literal. When used like this, the parameter is case-sensitive.

```sql
CREATE ZONE test_zone;
CREATE TABLE test_table (id INT PRIMARY KEY, val INT) ZONE `TEST_ZONE`;
```

In this case, `test_zone` is created as an identifier, and is case-insensitive. As such, when `TEST_ZONE` is used as a literal, it still matches the identifier.

Referenced by:

* [CREATE ZONE](/docs/gridgain/gridgain-9/reference/sql/distribution-zones.md#create-zone)
* [ALTER ZONE](/docs/gridgain/gridgain-9/reference/sql/distribution-zones.md#alter-zone)

## project\_item

```bnf
{ expression [AS] column_definition
| table_alias . *
| * }
```

### Parameters

* `expression` - a valid SQL expression that denotes the specific item in the SELECT clause.
* `table_alias` - a qualified table alias to use.

Referenced by:

* [SELECT](/docs/gridgain/gridgain-9/reference/sql/operational-commands.md#select)
* [select\_without\_from](#select_without_from)

## qualified\_table\_name

```bnf
[ schema . ] table_name
```

![Railroad diagram for qualified\_table\_name — equivalent to the BNF above](https://709350093-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoHbGEk22iR73P3x6DryR%2Fuploads%2Fgit-blob-1595b4e7471a6cbe39e3ac4784dead3e19347ee5%2Fgg9-sql-reference-qualified_table_name_bnf.svg?alt=media)

Keywords and parameters:

* `schema` - a name of the table schema.
* `table_name` - a name of the table.

Referenced by:

* [CREATE TABLE](/docs/gridgain/gridgain-9/reference/sql/ddl.md#create-table)
* [ALTER TABLE](/docs/gridgain/gridgain-9/reference/sql/ddl.md#alter-table)
* [DROP TABLE](/docs/gridgain/gridgain-9/reference/sql/ddl.md#drop-table)
* [CREATE INDEX](/docs/gridgain/gridgain-9/reference/sql/ddl.md#create-index)
* [DELETE](/docs/gridgain/gridgain-9/reference/sql/dml.md#delete)
* [INSERT](/docs/gridgain/gridgain-9/reference/sql/dml.md#insert)
* [MERGE](/docs/gridgain/gridgain-9/reference/sql/dml.md#merge)
* [UPDATE](/docs/gridgain/gridgain-9/reference/sql/dml.md#update)
* [table\_primary](#table_primary)

## query

```bnf
{ WITH with_item [, with_item]... query
| { SELECT
  | select_without_from
  | query { UNION | EXCEPT | MINUS | INTERSECT } [ ALL | DISTINCT ] query }
  [ ORDER BY order_item [, order_item]... ]
  [ LIMIT [start] { count | ALL } ]
  [ OFFSET start { ROW | ROWS } ]
  [ FETCH { FIRST | NEXT } [count] { ROW | ROWS } ONLY ] }
```

### Parameters

* `expression` - a valid SQL expression.
* `start` - the number of result to start the query from.
* `count` - the number of values to fetch.

Referenced by:

* [INSERT](/docs/gridgain/gridgain-9/reference/sql/dml.md#insert)
* [with\_item](#with_item)
* [table\_primary](#table_primary)

## select\_without\_from

```bnf
SELECT [ ALL | DISTINCT ] project_item [, project_item]...
```

Referenced by:

* [query](#query)

## sorted\_column\_list

```bnf
( column_name [ ASC | DESC ] [ NULLS { FIRST | LAST } ]
  [, column_name [ ASC | DESC ] [ NULLS { FIRST | LAST } ]]... )
```

Keywords and parameters:

* `column_name` - a column name.
* `NULLS FIRST` - if specified, places any NULL values before all non-NULL in that column's ordering.
* `NULLS LAST` - if specified, places NULLs after all non-NULLs in that column's ordering.

Referenced by:

* [CREATE INDEX](/docs/gridgain/gridgain-9/reference/sql/ddl.md#create-index)
* [constraint](#constraint)

## table\_expression

```bnf
{ table_expression [NATURAL] [ { LEFT | RIGHT | FULL } [OUTER] ] JOIN table_expression [join_condition]
| table_expression CROSS JOIN table_expression
| table_reference [, table_reference]... }
```

### Parameters

Referenced by:

* [SELECT](/docs/gridgain/gridgain-9/reference/sql/operational-commands.md#select)

## table\_primary

```bnf
qualified_table_name ( TABLE qualified_table_name )
{ table_primary [hint_comment]
| ( query )
| TABLE ( function_name ( expression [, expression]... ) ) }
```

### Parameters

* `hint_comment` - an sql optimizer hint.
* `expression` - a valid SQL expression.
* `function_name` - the name of the [SQL function](/docs/gridgain/gridgain-9/reference/sql/operators-and-functions.md) to use.

Referenced by:

* [table\_reference](#table_reference)

## table\_reference

```bnf
table_primary [ [AS] alias [ ( column_alias [, column_alias]... ) ] ]
```

### Parameters

* `alias` - the alias that will be used for the table.
* `column_alias` - the alias used for column.

Referenced by:

* [table\_expression](#table_expression)

## with\_item

```bnf
item_name [column_list] AS ( query )
```

Referenced by:

* [query](#query)
