> ## Documentation Index
> Fetch the complete documentation index at: /documents/llms.txt
> Use this file to discover all available pages before exploring further.

# ADD SQLBLACKLIST

> ADD SQLBLACKLIST adds a regular expression to the SQL blacklist to forbid certain SQL patterns.

ADD SQLBLACKLIST adds a regular expression to the SQL blacklist to forbid certain SQL patterns. When the SQL Blacklist feature is enabled, the database compares all SQL statements to be executed against the SQL regular expressions in the blacklist. The database does not execute SQLs that match any regular expression in the blacklist and returns an error. This prevents certain SQLs from triggering cluster crashes or unexpected behavior.

For more about SQL Blacklist, see [Manage SQL Blacklist](/documents/4.2/administration/management/resource_management/Blacklist.md).

**Tip**

* This operation requires the SYSTEM-level BLACKLIST privilege. You can follow the instructions in [GRANT](/documents/4.2/sql-reference/sql-statements/account-management/GRANT.md) to grant this privilege.
* The blacklist is only for SELECT statements, INSERT statements (from v3.1 onwards), and CTAS statements (from v3.4 onwards).

## Syntax

```SQL theme={null}
ADD SQLBLACKLIST "<sql_reg_expr>"
```

## Parameter

`sql_reg_expr`: the regular expression that is used to specify a certain SQL pattern. To distinguish the special characters in the SQL statement and those in the regular expression, you need to use the escape character `\` as a prefix for the special characters in the SQL statement, such as `(`, `)`, and `+`. Whereas `(` and `)` have been often used in SQL statements, the database can identify `(` and `)` in SQL statements directly. You do not need to use the escape character for `(` and `)`.

## Examples

Example 1: Add `count(\*)` to the SQL blacklist.

```Plain theme={null}
mysql> ADD SQLBLACKLIST "select count(\\*) from .+";
```

Example 2: Add `count(distinct )` to the SQL blacklist.

```Plain theme={null}
mysql> ADD SQLBLACKLIST "select count(distinct .+) from .+";
```

Example 3: Add `order by limit x, y, 1 <= x <=7, 5 <=y <=7` to the SQL blacklist.

```Plain theme={null}
mysql> ADD SQLBLACKLIST "select id_int from test_all_type_select1 
    order by id_int 
    limit [1-7], [5-7]";
```

Example 4: Add a complex SQL regular expression to the SQL blacklist. This example is to demonstrate how to use escape characters for `*` and `-` in SQL statements.

```Plain theme={null}
mysql> ADD SQLBLACKLIST 
    "select id_int \\* 4, id_tinyint, id_varchar 
        from test_all_type_nullable 
    except select id_int, id_tinyint, id_varchar 
        from test_basic 
    except select (id_int \\* 9 \\- 8) \\/ 2, id_tinyint, id_varchar 
        from test_all_type_nullable2 
    except select id_int, id_tinyint, id_varchar 
        from test_basic_nullable";
```

Example 5: Prohibit all INSERT INTO statements:

```sql theme={null}
ADD SQLBLACKLIST "(?i)^insert\\s+into\\s+.*";
```

Example 6: Prohibit all INSERT INTO ... VALUES statements:

```sql theme={null}
ADD SQLBLACKLIST "(?i)^insert\\s+into\\s+.*values\\s*\\(";
```

Example 7: Prohibit all INSERT INTO ... VALUES statements except those against the system-defined view `_statistics_.column_statistics`:

```sql theme={null}
ADD SQLBLACKLIST "(?i)^insert\\s+into\\s+(?!column_statistics\\b).*values\\s*\\(";
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.