Names

Applies to: check marked yes Databricks SQL check marked yes Databricks Runtime

Identifies different kinds of objects in Databricks.

The following limitations apply for all object names in Unity Catalog:

  • Object names cannot exceed 255 characters.

  • The following special characters are not allowed:

    • Period (.)

    • Space ( )

    • Forward slash (/)

    • All ASCII control characters (00-1F hex)

    • The DELETE character (7F hex)

  • Unity Catalog stores all object names as lowercase.

  • When referencing UC names in SQL, you must use backticks to escape names that contain special characters such as hyphens (-).

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.

Syntax

connection_identifier

Parameters

Examples

> CREATE CONNECTION my_postgresql ...;

Catalog name

Identifies a catalog. A catalog provides a grouping of objects which can be further subdivided into schemas.

Syntax

catalog_identifier

Parameters

Examples

> USE CATALOG hive_metastore;

> CREATE CATALOG mycatalog;

-- Creating a catalog with a special character requires back ticks
> CREATE CATALOG `cat-a-log`;

-- Creating a catalog with non ASCII characters requires back ticks
> USE `目录`;

-- space (' '), '/', and '.' are not allowed in catalog names, even with back ticks.
> 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

Schemas created in hive_metastore can only contain alphanumeric ASCII characters and underscores (INVALID_SCHEMA_OR_RELATION_NAME).

Examples

> USE SCHEMA default;

> CREATE SCHEMA my_sc;

-- In Hive Metastore, schema names must only consist of ASCII letters, digits and '_'
> CREATE SCHEMA hive_metastore.`a-b`;
Error: INVALID_SCHEMA_OR_RELATION_NAME

-- In Unity Catalog only space (' '), '/', and '.' are not allowed
> CREATE SCHEMA main.`a-b`;

> CREATE SCHEMA `a b`;
Error

-- Use back-ticks to reference or create schemas in Unity Catalog with non-ASCII characters
> CREATE SCHEMA `数据库架构`;

Database name

A synonym for schema name.

While usage of SCHEMA, and DATABASE is interchangeable, SCHEMA is preferred.

Table name

Identifies a table object. The table can be qualified with a schema name or unqualified using a simple identifier.

Syntax

{ [ schema_name . ] table_identifier [ temporal_spec ] |
  IDENTIFIER clause [ temporal_spec ] |
  { file_format | `file_format` } . `path_to_table` [ temporal_spec ] [ credential_spec ] }

temporal_spec
{
  @ timestamp_encoding |
  @V version |
  [ FOR ] { SYSTEM_TIMESTAMP | TIMESTAMP } AS OF timestamp_expression |
  [ FOR ] { SYSTEM_VERSION | VERSION } AS OF version
}

credential_spec
  WITH ( CREDENTIAL credential_name )

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.

    • @ timestamp_encoding: A positive Bigint literal that encodes a timestamp in yyyyMMddHHmmssSSS format.

    • @V version: A positive Integer literal identifying the version of the Delta table.

    • timestamp_expression: A simple expression that evaluates to a TIMESTAMP. timestamp_expressiom must be a constant expression, but may contain current_date() or current_timestamp().

    • version: A Integer literal or String literal identifying the version of the Delta table.

  • credential_name

    The name of the credential used to access the storage location.

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.

Examples

-- A back quoted table name
> SELECT * FROM `Employees`;

-- A table name without back quotes
> SELECT * FROM employees;

-- A schema qualified table name
> SELECT * FROM hr.employees;

-- A schema qualified table name with back quotes for schema and table
> SELECT * FROM `hr`.`employees`;

-- A fully qualified table name
> SELECT * FROM hive_metastore.default.tab;

-- A reference to an information schema table.
> SELECT * FROM system.information_schema.columns;

-- Referencing a path as a table requires back ticks
> SELECT * FROM delta.`somedir/delta_table`;

> SELECT * FROM `csv`.`spreadsheets/data.csv`;

> SELECT * FROM `csv`.`spreadsheets/data.csv` WITH (CREDENTIAL some_credential)

-- Tables in `hive_metastore` can only contain alphanumeric ASCII characters and underscores
> CREATE TABLE hive_metastore.default.t1(c1 INT);

> CREATE TABLE hive_metastore.default.`表一`(c1 INT);
Error: INVALID_SCHEMA_OR_RELATION_NAME

-- Use back-ticks to reference or create tables in Unity Catalog with non ASCII characters
> 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

  • schema_name: The qualified or unqualified name of the schema that contains the view.

  • view_identifier: An identifier that specifies the name of the view or the view identifier of a CTE.

  • IDENTIFIER clause: A mapping of constant STRING to a view name.

Views created in hive_metastore can only contain alphanumeric ASCII characters and underscores (INVALID_SCHEMA_OR_RELATION_NAME).

Examples

-- A back quoted view name
> SELECT * FROM `Employees`;

-- A view name without back quotes
> SELECT * FROM employees;

-- A schema qualified view name
> SELECT * FROM hr.employees;

-- A schema qualified view name with back quotes for schema and table
> SELECT * FROM `hr`.`employees`;

-- A fully qualified view name
> SELECT * FROM hive_metastore.default.tab;

-- Views in `hive_metastore` can only contain alphanumeric ASCII characters and underscores
> CREATE VIEW hive_metastore.default.v1(c1) AS SELECT 1;

> CREATE VIEW hive_metastore.default.`数据库视图一`(c1 INT);
Error: INVALID_SCHEMA_OR_RELATION_NAME

-- Use back-ticks to reference or create tables in Unity Catalog with non ASCII characters
> CREATE VIEW main.`瑞赛奇`.`数据库视图一`(c1) AS SELECT 1;

Column name

Identifies a column within a table or view. The column can be qualified with a table or view name, or unqualified using a simple identifier.

Syntax

{ [ { table_name | view_name } . ] column_identifier |
  IDENTIFIER clause }

Parameters

  • table_name: A qualified or unqualified table name of the table containing the column.

  • view_name: A qualified or unqualified view name of the view containing the column.

  • column_identifier: An identifier that specifies the name of the column.

  • IDENTIFIER clause: A mapping of constant STRING to a column name.

The identified column must exist within the table or view.

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.

Examples

-- An unqualified column name
> SELECT c1 FROM VALUES(1) AS T(c1);
 c1
 1

-- A qualified column name
> SELECT T.c1 FROM VALUES(1) AS T(c1);
 c1
 1

-- Using _metadata to retrieve information about rows retrieved from T.
> CREATE TABLE T(c1 INT);
> INSERT INTO T VALUES(1);
> SELECT T._metadata.file_size;
  574

-- A delimited column name
> 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

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.

Examples

> SELECT addr.address.name
    FROM VALUES (named_struct('address', named_struct('number', 5, 'name', 'Main St'),
                              'city', 'Springfield')) as t(addr);
  Main St

-- Delimited field names with non ASCII letters
> 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.

Syntax

{ [ schema_name . ] variable_identifier |
  IDENTIFIER clause }

Parameters

  • schema_name: system.session or session which contains all temporary variables.

  • variable_identifier: An identifier that specifies the name of the variable.

Examples

-- Declaring a session variable with a qualified name.
> DECLARE session.myvar = 5;

-- Setting a session variable with an unqualified name.
> SET VAR myvar = 6

-- Declaring a session variable with a fully qualified name an non-ASCII characters.
> 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

Functions created in hive_metastore can only contain alphanumeric ASCII characters and underscores.

Examples

-- Creating a SQL function with a qualified name
> CREATE FUNCTION math.myplus(x INT, y INT) RETURN x + y;

-- Invoking a function with an unqualified name
> SELECT myplus()

-- Creating a SQL function with non-ASCII characters;
> CREATE FUNCTION `圆周率`() RETURN 3.14;

Parameter name

Identifies a parameter in the body of a SQL user-defined function (SQL UDF). The function can be qualified with a function identifier, or unqualified using a simple identifier.

Syntax

[ function_identifier . ] parameter_identifier

Parameters

Examples

-- Create a function with undelimited parameters and reference them as qualified and nonqualified.
> CREATE FUNCTION area(x INT, y INT) RETURNS INT
  RETURN area.x + y;

-- Create a function with non-ASCII character parameters
> CREATE FUNCTION full_name(`prénom` STRING, `nom` STRING) RETURNS STRING
  RETURN `prénom` + ' ' + `nom`;

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

-- Defining a table alias with column list
> SELECT a, b FROM VALUES (1, 2) AS t(a, b);
 a  b
 1  2

-- Defining a table alias without column list
> DELETE FROM emp AS e WHERE e.c1 = 5;

-- Defining a table alias with non ASCII characters
> 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
[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

-- An undelimited alias
> SELECT 1 AS a;
 a
 1

> SELECT 1 a, 2 b;
 a b
 1 2

-- A delimited alias with non-ASCII characters
> SELECT 3.14 AS `圆周率`;
 a
 1

-- Referencing a passed column alias
> SELECT a + a FROM (SELECT 1 AS a);
 a
 2

Credential name

Identifies a credential to access storage at an external location.

Syntax

credential_identifier

Parameters

Examples

Location name

Identifies an external storage location.

Syntax

location_identifier

Parameters

Examples

`s3-json-data`

s3_json_data

Share name

Identifies a share to access data shared by a provider.

Syntax

share_identifier

Parameters

  • share_identifier: An unqualified identifier that uniquely identifies the share.

Examples

`public info`

`public-info`

public_info

Provider name

Identifies a Delta Sharing provider.

Syntax

provider_identifier

Parameters

Examples

`Good Corp`

`Good-corp`

Good_Corp

Recipient name

Identifies a recipient for a share.

Syntax

recipient_identifier

Parameters

Examples

`Good Corp`

`Good-corp`

Good_Corp

Volume name

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

  • schema_name: A qualified or unqualified schema name that contains the volume.

  • volume_identifier: An unqualified identifier that uniquely identifies the volume within the schema.

Examples

`myVolume`

`my-volume`

myschema.myVolume

my_unity_catalog.my_schema.my_volume