| --- |
| title: Grammar Reference |
| sidebar_label: Grammar Reference |
| --- |
| |
| {/* |
| Licensed to the Apache Software Foundation (ASF) under one or more |
| contributor license agreements. See the NOTICE file distributed with |
| this work for additional information regarding copyright ownership. |
| The ASF licenses this file to You under the Apache License, Version 2.0 |
| (the "License"); you may not use this file except in compliance with |
| the License. You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
| */} |
| |
| This section describes grammar elements that are common to multiple SQL functions ([DDL](ddl.md), [Distribution Zones](distribution-zones.md), etc.). |
| |
| ## assign |
| |
| {/* Railroad diagram omitted - see 3.1.0 docs */} |
| |
| ### 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 |
| * UPDATE |
| |
| ## column_definition |
| |
| {/* Railroad diagram omitted - see 3.1.0 docs */} |
| |
| {/* Railroad diagram omitted - see 3.1.0 docs */} |
| |
| Keywords and parameters: |
| |
| * `column_name` - a column name. |
| * `DATA TYPE` - the [data type](data-types.md) allowed in the column. |
| * `identifier` - the random identifier for the row. Can be generated by using the `RAND_UUID` 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` - the time interval by which the timestamp will be offset. Required if `CURRENT_TIMESTAMP` is used. The interval can be specified in: |
| |
| - `SECONDS` |
| - `MINUTES` |
| - `HOURS` |
| - `DAYS` |
| - `MONTHS` |
| |
| If the interval is `0`, current time is used. |
| |
| Referenced by: |
| |
| * [CREATE TABLE](ddl.md#create-table) |
| * [ALTER TABLE](ddl.md#alter-table) |
| * [project_item](#project_item) |
| * [join_condition](#join_condition) |
| |
| ## column_definition_or_list |
| |
| {/* Railroad diagram omitted - see 3.1.0 docs */} |
| |
| Keywords and parameters: |
| |
| * `column_name` - a column name. |
| * `data_type` - a valid [data type](data-types.md). |
| |
| Referenced by: |
| |
| * [ALTER TABLE](ddl.md#alter-table) |
| * [with_item](#with_item) |
| |
| ## column_list |
| |
| {/* Railroad diagram omitted - see 3.1.0 docs */} |
| |
| Keywords and parameters: |
| |
| * `column_name` - a column name. |
| |
| Referenced by: |
| |
| * [INSERT](dml.md#insert) |
| * [join_condition ](#join_condition) |
| |
| ## column_name_or_list |
| |
| {/* Railroad diagram omitted - see 3.1.0 docs */} |
| |
| Keywords and parameters: |
| |
| * `column_name` - a column name. |
| |
| Referenced by: |
| |
| * [ALTER TABLE](ddl.md#alter-table) |
| |
| ## constraint |
| |
| {/* Railroad diagram omitted - see 3.1.0 docs */} |
| |
| Keywords and parameters: |
| |
| * `constraint_name` - a name of the constraint. |
| |
| Referenced by: |
| |
| * [CREATE TABLE](ddl.md#create-table) |
| |
| ## group_item |
| |
| {/* Railroad diagram omitted - see 3.1.0 docs */} |
| |
| ### Parameters |
| |
| - `expression` - a valid SQL expression that returns the values that must be assigned to the `identifier`. |
| |
| Referenced by: |
| |
| * [SELECT](operational-commands.md#select) |
| |
| ## join_condition |
| |
| {/* Railroad diagram omitted - see 3.1.0 docs */} |
| |
| ### 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 |
| |
| {/* Railroad diagram omitted - see 3.1.0 docs */} |
| |
| ### Parameters |
| |
| - `expression` - a valid SQL expression that denotes the specific item in the SELECT clause. |
| |
| Referenced by: |
| |
| * [query](#query) |
| |
| ## parameter |
| |
| {/* Railroad diagram omitted - see 3.1.0 docs */} |
| |
| 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: |
| |
| ``` |
| CREATE ZONE test_zone; |
| CREATE TABLE test_table (id INT PRIMARY KEY, val INT) WITH PRIMARY_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. |
| |
| ``` |
| CREATE ZONE "test_zone"; |
| CREATE TABLE test_table (id INT PRIMARY KEY, val INT) WITH PRIMARY_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. |
| |
| ``` |
| CREATE ZONE test_zone; |
| CREATE TABLE test_table (id INT PRIMARY KEY, val INT) WITH PRIMARY_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](distribution-zones.md#create-zone) |
| * [ALTER ZONE](distribution-zones.md#alter-zone) |
| |
| ## project_item |
| |
| {/* Railroad diagram omitted - see 3.1.0 docs */} |
| |
| ### 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](operational-commands.md#select) |
| * [select_without_from](#select_without_from) |
| |
| ## qualified_table_name |
| |
| {/* Railroad diagram omitted - see 3.1.0 docs */} |
| |
| Keywords and parameters: |
| |
| * `schema` - a name of the table schema. |
| * `table_name` - a name of the table. |
| |
| Referenced by: |
| |
| * [CREATE TABLE](ddl.md#create-table) |
| * [ALTER TABLE](ddl.md#alter-table) |
| * [DROP TABLE](ddl.md#drop-table) |
| * [CREATE INDEX](ddl.md#create-index) |
| * [DELETE](dml.md#delete) |
| * [INSERT](dml.md#insert) |
| * [MERGE](dml.md#merge) |
| * [UPDATE](dml.md#update) |
| * [table_primary](#table_primary) |
| |
| ## query |
| |
| {/* Railroad diagram omitted - see 3.1.0 docs */} |
| |
| ### 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](dml.md#insert) |
| * [with_item](#with_item) |
| * [table_primary](#table_primary) |
| |
| ## select_without_from |
| |
| {/* Railroad diagram omitted - see 3.1.0 docs */} |
| |
| Referenced by: |
| |
| * [query](#query) |
| |
| ## sorted_column_list |
| |
| {/* Railroad diagram omitted - see 3.1.0 docs */} |
| |
| 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](ddl.md#create-index) |
| * [constraint](#constraint) |
| |
| ## table_expression |
| |
| {/* Railroad diagram omitted - see 3.1.0 docs */} |
| |
| ### Parameters |
| |
| Referenced by: |
| |
| * [SELECT](operational-commands.md#select) |
| |
| ## table_primary |
| |
| {/* Railroad diagram omitted - see 3.1.0 docs */} |
| |
| {/* Railroad diagram omitted - see 3.1.0 docs */} |
| |
| ### Parameters |
| |
| - `hint_comment` - an sql [optimizer hint](../sql-tuning/sql-tuning.md#optimizer-hints). |
| - `expression` - a valid SQL expression. |
| - `function_name` - the name of the [SQL function](operators-and-functions.md) to use. |
| |
| Referenced by: |
| |
| * [table_reference](#table_reference) |
| |
| ## table_reference |
| |
| {/* Railroad diagram omitted - see 3.1.0 docs */} |
| |
| ### 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 |
| |
| {/* Railroad diagram omitted - see 3.1.0 docs */} |
| |
| Referenced by: |
| |
| * [query](#query) |