---
title: IDENTIFIER clause
description: The IDENTIFIER clause provides SQL-injection-safe parameterization of identifiers in SQL statements, in Databricks SQL and Databricks Runtime.
canonical_url: https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-names-identifier-clause
---

# IDENTIFIER clause

**Applies to:** ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks SQL ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks Runtime 13.3 LTS and above

The `IDENTIFIER` clause enables SQL-injection-safe parameterization of identifiers in SQL statements.

* **Applies to:** ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks SQL ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks Runtime 18.0 and above

  The clause can be used instead of any [object name](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-names.md) or [identifier](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-identifiers.md) within a multipart name,
  as long as the arguments consist only of a [string literal](https://docs.databricks.com/aws/en/sql/language-manual/data-types/string-type.md) or string [parameter marker](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-parameter-marker.md).
  This includes coalesced strings such as: `'myschema' :table 'mycolumn'` or `:schema :table :column`.

  In [SQL scripting](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-scripting.md), this includes:

  * [Labels](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-names.md#label-name) of compound and looping statements, including end labels and the targets of [LEAVE](https://docs.databricks.com/aws/en/sql/language-manual/control-flow/leave-stmt.md) and [ITERATE](https://docs.databricks.com/aws/en/sql/language-manual/control-flow/iterate-stmt.md).
  * The variable name of a [FOR](https://docs.databricks.com/aws/en/sql/language-manual/control-flow/for-stmt.md) statement.
  * [Cursor names](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-names.md#cursor-name), in Databricks Runtime 18.1 and above, where cursors are available.

* **Applies to:** ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks SQL ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks Runtime 13.3 LTS and above

  The IDENTIFIER clause interprets a constant string such as `'myschema' || :table || 'mycolumn'` or `:schema || :table || :column` as a:

  * relation (table or view) name
  * function name
  * column name
  * field name
  * schema name
  * catalog name

  The IDENTIFIER clause is limited to the following statements:

  * The table, view, or function subject name of a CREATE, ALTER, DROP, or UNDROP statement.
  * The target table name of a MERGE, UPDATE, DELETE, INSERT, COPY INTO statements.
  * The target of a SHOW or DESCRIBE statement.
  * USE of a schema or catalog
  * A function invocation
  * A column, table or view referenced in a query. This includes queries embedded in a DDL or DML statement.

> [!NOTE]
>
> Where the IDENTIFIER clause is not supported and SQL injection is not a concern, you can use [EXECUTE IMMEDIATE](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-aux-execute-immediate.md) instead.
> For example:
> `EXECUTE IMMEDIATE 'CREATE TABLE ' || :tab || '(' || :col || 'INT)';`

## Syntax

```
IDENTIFIER ( strLiteral )

IDENTIFIER ( strExpr )
```

## Parameters

* **strLiteral**: A `STRING` literal typically composed of one or more string [parameter markers](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-parameter-marker.md) and literal components which are coalesced;
* **strExpr**: A constant `STRING` expression typically including one or more [parameter markers](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-parameter-marker.md).
  Starting with Databricks Runtime 18.0 this notation is deprecated.

## Examples

### Scala

```scala
// Creation of a table using parameter marker.
spark.sql("CREATE TABLE IDENTIFIER(:mytab)(c1 INT)", args = Map("mytab" -> "tab1"))

// Altering a table with a fixed schema and a parameterized table name.
spark.sql("ALTER TABLE IDENTIFIER('default.' || :mytab) ADD COLUMN c2 INT", args = Map("mytab" -> "tab1"))

// Altering a table with a fixed schema and a parameterized table name in :re[DBR] 18.0 and above.
spark.sql("ALTER TABLE IDENTIFIER('default.' :mytab) ADD COLUMN c2 INT", args = Map("mytab" -> "tab1"))

// Dropping a table with separate schema and table parameters.
spark.sql("DROP TABLE IDENTIFIER(:myschema || '.' || :mytab)", args = Map("myschema" -> "default", "mytab" -> "tab1"))

// Dropping a table with separate schema and table parameters in :re[DBR] 18.0 and above.
spark.sql("DROP TABLE IDENTIFIER(:myschema '.' :mytab)", args = Map("myschema" -> "default", "mytab" -> "tab1"))

// A parameterized reference to a table in a query. The table name is qualified and uses back-ticks.
spark.sql("SELECT * FROM IDENTIFIER(:mytab)", args = Map("mytab" -> "`default`.`tab1`"))

// You cannot qualify the IDENTIFIER clause or use it as a qualifier itself.
spark.sql("SELECT * FROM myschema.IDENTIFIER(:mytab)", args = Map("mytab" -> "`tab1`"))

spark.sql("SELECT * FROM IDENTIFIER(:myschema).mytab", args = Map("myschema" -> "`default`"))

// A parameterized column reference
spark.sql("SELECT IDENTIFIER(:col) FROM VALUES(1) AS T(c1)", args = Map("col" -> "t.c1"))

// Passing in an aggregate function name as a parameter
spark.sql("SELECT IDENTIFIER(:agg)(c1) FROM VALUES(1), (2) AS T(c1)", args = Map("agg" -> "max"))
```

### SQL

```sql

-- Using a catalog using a variable.
> DECLARE mycat = 'main';
> USE CATALOG IDENTIFIER(mycat);

-- Creation of a table using variable.
> DECLARE mytab = 'tab1';
> CREATE TABLE IDENTIFIER(mytab)(c1 INT);

-- Altering a table with a fixed schema and a parameterized table name.
> ALTER TABLE IDENTIFIER('default.' || mytab) ADD COLUMN c2 INT;

-- Altering a table with a fixed schema and a parameterized table name in :re[DBR] 18.0 and above.
> ALTER TABLE IDENTIFIER('default.' || mytab) ADD COLUMN c2 INT;

-- Inserting using a parameterized table name. The table name is qualified and uses back-ticks.
> SET VAR mytab = '`default`.`tab1`';
> INSERT INTO IDENTIFIER(mytab) VALUES(1, 2);

-- A parameterized reference to a table in a query.
> SELECT * FROM IDENTIFIER(mytab);
  1   2

-- Dropping a table with separate schema and table parameters.
> DECLARE myschema = 'default';
> SET VAR mytab = 'tab1';
> DROP TABLE IDENTIFIER(myschema || '.' || mytab);
-- In :re[DBR] 18.0 and above:
> DROP TABLE IDENTIFIER(myschema '.' mytab);

-- You cannot qualify the IDENTIFIER clause or use it as a qualifier itself prior to :re[DBR] 18.0.
> SELECT * FROM myschema.IDENTIFIER('tab');
Error: PARSE_SYNTAX_ERROR

> SELECT * FROM IDENTIFIER('default').mytab;
Error: PARSE_SYNTAX_ERROR

-- A parameterized column reference
> DECLARE col = 't.c1';
> SELECT IDENTIFIER(col) FROM VALUES(1) AS T(c1);
  1

-- Passing in an aggregate function name as a parameter
> DECLARE agg = 'max';
> SELECT IDENTIFIER(agg)(c1) FROM VALUES(1), (2) AS T(c1);
  2

-- Specifying a SQL script label in :re[DBR] 18.0 and above.
> BEGIN
    IDENTIFIER('my_loop'): LOOP
      LEAVE IDENTIFIER('my_loop');
    END LOOP IDENTIFIER('my_loop');
    VALUES (42);
  END;
  42
```

### Python

```python
# Creation of a table using parameter marker.
spark.sql("CREATE TABLE IDENTIFIER(:mytab)(c1 INT)", args = {"mytab": "tab1"})

# Altering a table with a fixed schema and a parameterized table name.
spark.sql("ALTER TABLE IDENTIFIER('default.' || :mytab) ADD COLUMN c2 INT", args = {"mytab": "tab1"})

# Altering a table with a fixed schema and a parameterized table name in :re[DBR] 18.0 and above.
spark.sql("ALTER TABLE IDENTIFIER('default.' :mytab) ADD COLUMN c2 INT", args = {"mytab": "tab1"})

# Dropping a table with separate schema and table parameters.
spark.sql("DROP TABLE IDENTIFIER(:myschema || '.' || :mytab)", args = {"myschema": "default", "mytab": "tab1"})

# Dropping a table with separate schema and table parameters in :re[DBR] 18.0 and above.
spark.sql("DROP TABLE IDENTIFIER(:myschema '.' :mytab)", args = {"myschema": "default", "mytab": "tab1"})

# A parameterized reference to a table in a query. The table name is qualified and uses back-ticks.
spark.sql("SELECT * FROM IDENTIFIER(:mytab)", args = {"mytab": "`default`.`tab1`"})

# You cannot qualify the IDENTIFIER clause or use it as a qualifier itself.
spark.sql("SELECT * FROM myschema.IDENTIFIER(:mytab)", args = {"mytab": "`tab1`"})

spark.sql("SELECT * FROM IDENTIFIER(:myschema).mytab", args = {"myschema": "`default`"})

# A parameterized column reference
spark.sql("SELECT IDENTIFIER(:col) FROM VALUES(1) AS T(c1)", args = {"col": "t.c1"})

# Passing in an aggregate function name as a parameter
spark.sql("SELECT IDENTIFIER(:agg)(c1) FROM VALUES(1), (2) AS T(c1)", args = {"agg": "max"})
```

## Related

* [EXECUTE IMMEDIATE](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-aux-execute-immediate.md)
* [Identifiers](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-identifiers.md)
* [Parameter markers](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-parameter-marker.md)
* [Names](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-names.md)
