Applies to: Databricks SQL Databricks Runtime
Identifies different kinds of objects in Databricks.
The following limitations apply for all object names in Unity Catalog:
.
)
)/
)-
).note
Column names can use special characters, but the name must be escaped with backticks in all SQL statements if special characters are used. Unity Catalog preserves column name casing, but queries against Unity Catalog tables are case-insensitive.
Connection nameâIdentifies a foreign connection. A foreign connection serves as a link to a foreign system, such as PostgreSQL
and can then be used to reference its catalogs, schemas, and tables.
SQL
> CREATE CONNECTION my_postgresql ...;
Catalog nameâ
Identifies a catalog. A catalog provides a grouping of objects which can be further subdivided into schemas.
Syntaxâ ParametersâSQL
> USE CATALOG hive_metastore;
> CREATE CATALOG mycatalog;
> CREATE CATALOG `cat-a-log`;
> USE `ç®å½`;
> CREATE CATALOG `cat a log`;
ERROR
Schema nameâ
Identifies a schema. A schema provides a grouping of objects in a catalog.
Syntaxâ{ [ catalog_name . ] schema_identifier |
IDENTIFIER clause }
Parametersâ
STRING
to a schema name.Schemas created in hive_metastore
can only contain alphanumeric ASCII characters and underscores (INVALID_SCHEMA_OR_RELATION_NAME).
SQL
> USE SCHEMA default;
> CREATE SCHEMA my_sc;
> CREATE SCHEMA hive_metastore.`a-b`;
Error: INVALID_SCHEMA_OR_RELATION_NAME
> CREATE SCHEMA main.`a-b`;
> CREATE SCHEMA `a b`;
Error
> CREATE SCHEMA `æ°æ®åºæ¶æ`;
Database nameâ
A synonym for schema name.
While usage of SCHEMA
, and DATABASE
is interchangeable, SCHEMA
is preferred.
Identifies a table object. The table can be qualified with a schema name or unqualified using a simple identifier.
Syntaxâ{ [ schema_name . ] table_identifier |
IDENTIFIER clause |
{ file_format | `file_format` } . `path_to_table` } [ temporal_spec ] [ options_spec ] }
temporal_spec
{
@ timestamp_encoding |
@V version |
[ FOR ] { SYSTEM_TIMESTAMP | TIMESTAMP } AS OF timestamp_expression |
[ FOR ] { SYSTEM_VERSION | VERSION } AS OF version
}
options_spec
WITH ( { option_key [ = ] option_val } [, ...] )
option_key
{ identifier [. ...] | string_literal }
Parametersâ
schema_name: A qualified or unqualified schema name that contains the table.
table_identifier: An identifier that specifies the name of the table or table_alias.
file_format: One of json
, csv
, avro
, parquet
, orc
, binaryFile
, text
, delta
(case insensitive).
path_to_table: The location of the table in the file system. You must have the ANY_FILE
permission to use this syntax.
IDENTIFIER clause: A mapping of constant STRING
to a table name.
temporal_spec: When used references a Delta table at the specified point in time or version.
You can use a temporal specification only within the context of a query or a MERGE USING.
yyyyMMddHHmmssSSS
format.timestamp_expressiom
must be a constant expression, but may contain current_date()
or current_timestamp()
.option_spec: When used defines directives to be passed to a data source such as a credential to access a storage location or 'write.split-size'
to control INSERT
behavior.
option_key
The option key. The key can consist of one or more identifiers separated by a dot, or a string literal.
Option keys must be unique and are case-sensitive.
option_val
The value for the option. A constant expression of type BOOLEAN
, STRING
, INTEGER
, or DECIMAL
.
Tables created in hive_metastore
can only contain alphanumeric ASCII characters and underscores (INVALID_SCHEMA_OR_RELATION_NAME).
If the name is unqualified and does not reference a known table alias, Databricks first attempts to resolve the table in the current schema.
If the name is qualified with a schema, Databricks attempts to resolve the table in the current catalog.
See Table and view resolution for more information on name resolution.
Databricks raises an error if you use a temporal_spec
for a table that is not in Delta Lake format.
SQL
> SELECT * FROM `Employees`;
> SELECT * FROM employees;
> SELECT * FROM hr.employees;
> SELECT * FROM `hr`.`employees`;
> SELECT * FROM hive_metastore.default.tab;
> SELECT * FROM system.information_schema.columns;
> SELECT * FROM delta.`somedir/delta_table`;
> SELECT * FROM `csv`.`spreadsheets/data.csv`;
> SELECT * FROM `csv`.`spreadsheets/data.csv` WITH (CREDENTIAL some_credential)
> INSERT INTO t WITH ('write.split-size' 10) SELECT * FROM s;
> CREATE TABLE hive_metastore.default.t1(c1 INT);
> CREATE TABLE hive_metastore.default.`表ä¸`(c1 INT);
Error: INVALID_SCHEMA_OR_RELATION_NAME
> CREATE TABLE main.`çèµå¥`.`表ä¸`(c1 INT);
View nameâ
Identifies a view. The view can be qualified with a schema name or unqualified using a simple identifier.
Syntaxâ{ [ schema_name . ] view_identifier |
IDENTIFIER clause }
Parametersâ
STRING
to a view name.Views created in hive_metastore
can only contain alphanumeric ASCII characters and underscores (INVALID_SCHEMA_OR_RELATION_NAME).
SQL
> SELECT * FROM `Employees`;
> SELECT * FROM employees;
> SELECT * FROM hr.employees;
> SELECT * FROM `hr`.`employees`;
> SELECT * FROM hive_metastore.default.tab;
> CREATE VIEW hive_metastore.default.v1(c1) AS SELECT 1;
> CREATE VIEW hive_metastore.default.`æ°æ®åºè§å¾ä¸`(c1 INT);
Error: INVALID_SCHEMA_OR_RELATION_NAME
> CREATE VIEW main.`çèµå¥`.`æ°æ®åºè§å¾ä¸`(c1) AS SELECT 1;
Relation nameâ
Identifies a view or table. Relation can be qualified with a schema name or unqualified using a simple identifier.
Syntaxâ{ table_name | view_name }
Examplesâ
SQL
> SELECT * FROM `Employees`;
> SELECT * FROM employees;
> SELECT * FROM hr.employees;
Column nameâ
Identifies a column within a relation. The column can be qualified with a relation name, or unqualified using a simple identifier.
Syntaxâ{ [ relation_name . ] column_identifier |
IDENTIFIER clause }
Parametersâ
STRING
to a column name.The identified column must exist within the relation.
Databricks supports a special _metadata column. This pseudo column of type struct is part of every table and can be used to retrieve metadata information about the rows in the table.
warning
If the table schema contains a column named _metadata
, queries will return the column from the data source, and not the file metadata. The _metadata
pseudo column will not be accessible.
Column names in Delta Lake tables without column mapping property ('delta.columnMapping.mode' = 'name'
) must not contain the characters ' '
(space), ','
, ';'
, '{'
, '}'
, '('
, ')'
. '\n'
, '\t'
, and '='
.
Column name in AVRO
tables must start with '_'
or a Unicode letter (including non-ASCII letters) and be followed by a combination of '_'
, Unicode letters and digits.
SQL
> SELECT c1 FROM VALUES(1) AS T(c1);
c1
1
> SELECT T.c1 FROM VALUES(1) AS T(c1);
c1
1
> CREATE TABLE T(c1 INT);
> INSERT INTO T VALUES(1);
> SELECT T._metadata.file_size;
574
> CREATE TABLE T(`sütun1`);
Field nameâ
Identifies a field within a struct. The field must be qualified with the path up to the struct containing the field.
Syntaxâ{ expr { . field_identifier [. ...] } |
IDENTIFIER clause }
Parametersâ
STRING
to a field name.A deeply nested field can be referenced by specifying the field identifier along the path to the root struct.
Field names in Delta Lake tables without column mapping property ('delta.columnMapping.mode' = 'name'
) must not contain the characters ' '
(space), ','
, ';'
, '{'
, '}'
, '('
, ')'
. '\n'
, '\t'
, and '='
.
Field name in AVRO
tables must start with '_'
or a Unicode letter (including non-ASCII letters) and be followed by a combination of '_'
, Unicode letters and digits.
SQL
> SELECT addr.address.name
FROM VALUES (named_struct('address', named_struct('number', 5, 'name', 'Main St'),
'city', 'Springfield')) as t(addr);
Main St
> CREATE TABLE T(c1 struct<`аÑÑибÑÑ1` INT, `аÑÑибÑÑ2`>);
> SELECT c1.`аÑÑибÑÑ1` FROM T;
Variable nameâ
Identifies a temporary (session) variable. The variable can be qualified with a schema name (system.session
or session
), or unqualified using a simple identifier.
{ [ schema_name . ] variable_identifier |
IDENTIFIER clause }
Parametersâ
system.session
or session
which contains all temporary variables.SQL
> DECLARE session.myvar = 5;
> SET VAR myvar = 6
> DECLARE system.session.`åå¨ç` = 3.14;
Function nameâ
Identifies a function. The function can be qualified with a schema name, or unqualified using a simple identifier.
Syntaxâ{ [ schema_name . ] function_identifier |
IDENTIFIER clause }
Parametersâ
STRING
to a function name.Functions created in hive_metastore
can only contain alphanumeric ASCII characters and underscores.
SQL
> CREATE FUNCTION math.myplus(x INT, y INT) RETURN x + y;
> SELECT myplus()
> CREATE FUNCTION `åå¨ç`() RETURN 3.14;
Procedure nameâ
Identifies a procedure. The procedure can be qualified with a schema name, or unqualified using a simple identifier.
Syntaxâ{ [ schema_name . ] procedure_identifier |
IDENTIFIER clause }
Parametersâ
STRING
to a procedure name.Identifies a parameter in the body of a SQL user-defined function (SQL UDF) or a procedure. The parameter can be qualified with a routine identifier, or unqualified using a simple identifier.
Syntaxâ[ routine_identifier . ] parameter_identifier
Parametersâ
SQL
> CREATE FUNCTION area(x INT, y INT) RETURNS INT
RETURN area.x + y;
> CREATE FUNCTION full_name(`prénom` STRING, `nom` STRING) RETURNS STRING
RETURN `prénom` + ' ' + `nom`;
Label nameâ
Identifies a label of a compound statement or looping statement.
Syntaxâ ParametersâSQL
> BEGIN
label: LOOP
LEAVE label;
END LOOP label;
END;
Condition nameâ
Identifies a system defined error class or a user defined condition defined in a compound statement.
Syntaxâ ParametersâSQL
BEGIN
DECLARE a INT DEFAULT 1;
DECLARE b INT DEFAULT 5;
DECLARE EXIT HANDLER FOR DIVIDE_BY_ZERO
BEGIN
VALUES (15);
END;
SET a = 10;
SET a = b / 0;
VALUES (a);
END;
15
Table aliasâ
Labels a table reference, query, table function, or other form of a relation.
Syntaxâ[ AS ] table_identifier [ ( column_identifier1 [, ...] ) ]
Parametersâ
If you provide column identifiers, their number must match the number of columns in the matched relation.
If you don't provide column identifiers, their names are inherited from the labeled relation.
ExamplesâSQL
> SELECT a, b FROM VALUES (1, 2) AS t(a, b);
a b
1 2
> DELETE FROM emp AS e WHERE e.c1 = 5;
> SELECT * FROM employee AS `ì§ì`;
Column aliasâ
Labels the result of an expression in a SELECT
list for reference.
If the expression is a table valued generator function, the alias labels the list of columns produced.
Syntaxâ[AS] ( column_identifier [, ...] )
Parametersâ
While column aliases need not be unique within the select list, uniqueness is a requirement to reference an alias by name.
ExamplesâSQL
> SELECT 1 AS a;
a
1
> SELECT 1 a, 2 b;
a b
1 2
> SELECT 3.14 AS `åå¨ç`;
a
1
> SELECT a + a FROM (SELECT 1 AS a);
a
2
Collation nameâ
Identifies a collation for a column or expression.
Syntaxâ ParametersâFor a list of supported collations, see Supported collations. For details about collations see Collation.
ExamplesâSQL
> SELECT 'hello' COLLATE UNICODE_CI;
hello
Credential nameâ
Identifies a credential to access storage at an external location or cloud services with provider SDKs.
Syntaxâ Parametersâ`my_storage_cred`
my_storage_cred
Location nameâ
Identifies an external storage location.
Syntaxâ ParametersâSQL
`s3-json-data`
s3_json_data
Identifies a share to access data shared by a provider.
Syntaxâ ParametersâSQL
`public info`
`public-info`
public_info
Provider nameâ
Identifies a Delta Sharing provider.
Syntaxâ ParametersâAn unqualified identifier that uniquely identifies the provider.
SQL
`Good Corp`
`Good-corp`
Good_Corp
Recipient nameâ
Identifies a recipient for a share.
Syntaxâ ParametersâSQL
`Good Corp`
`Good-corp`
Good_Corp
Clean Room nameâ
Identifies a clean room for a set of collaborators.
Syntaxâ ParametersâIdentifies a Unity Catalog volume. The volume can be qualified with a schema name or unqualified using a simple identifier.
Syntaxâ[ schema_name .] volume_identifier
Parametersâ
SQL
`myVolume`
`my-volume`
myschema.myVolume
my_unity_catalog.my_schema.my_volume
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4