---
title: ROW FILTER clause
description: Apply a function as a row filter when rows are read from a table with the ROW FILTER clause in Databricks SQL and Databricks Runtime.
canonical_url: https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-row-filter
---

# `ROW FILTER` 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 12.2 LTS and above ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Unity Catalog only

Specifies a function that is applied as a filter whenever rows are fetched from the relation.

You can add row filters when you:

* Create a table using [CREATE TABLE](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-create-table-using.md).
* Alter a table using [ALTER TABLE](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-alter-table.md).
* Create a materialized view using [CREATE MATERIALIZED VIEW](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-create-materialized-view.md).
* Alter a materialized view using [ALTER MATERIALIZED VIEW](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-alter-materialized-view.md).
* Create a streaming table using [CREATE STREAMING TABLE](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-create-streaming-table.md).
* Alter a streaming table using [ALTER STREAMING TABLE](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-alter-streaming-table.md).

> [!IMPORTANT]
>
> The row filter is applied as soon as the row is fetched from the data source.

For more information on how to use row filters, see [Row filters and column masks](https://docs.databricks.com/aws/en/data-governance/unity-catalog/filters-and-masks/index.md).

## Required privileges

To assign a function that adds a row filter to a table, you must have the `EXECUTE` privilege on the function, `USE SCHEMA` on the schema, and `USE CATALOG` on the parent catalog.

If you are adding a row filter when you create a *new* table, you must have the `CREATE TABLE` privilege on the schema.

If you are adding or removing a row filter on an *existing* table, you must be the table owner, or have both the `MANAGE` and `SELECT` privileges on the table.

If the same statement also changes the table schema, you additionally need the `MODIFY` privilege on the table.

## Syntax

```
ROW FILTER func_name ON ( [ column_name | constant_literal [, ...] ] ) [...]
```

## Parameters

* **[func\_name](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-names.md#function-name)**

  A scalar [SQL UDF](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-create-sql-function.md).

  The return type of the function must be `BOOLEAN`.
  If the function returns `FALSE` or `NULL` the row is filtered out.

* **[column\_name](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-names.md#column-name)**

  Specifies columns of the subject relation to pass to `func_name`.
  Each `column_name` must be castable to the corresponding parameter of `func_name`.
  You must provide as many columns as are required by the signature of the function.
  This feature supports passing zero input columns, in which case the
  SQL UDF must accept zero parameters and return a Boolean result independent of
  the values of the input rows.

  > [!IMPORTANT]
  >
  > If a column's data type doesn't exactly match the corresponding function parameter type, the column value is implicitly cast. With [ANSI\_MODE](https://docs.databricks.com/aws/en/sql/language-manual/parameters/ansi_mode.md) disabled, values that can't be cast are silently converted to `NULL`, which can produce unexpected filter results. UDF parameter types must match the data types of the columns passed to them. See [Data type mismatch behavior](https://docs.databricks.com/aws/en/data-governance/unity-catalog/filters-and-masks/index.md#type-mismatch).

* **constant\_literal**

  Specifies a constant parameter with the type matching a function parameter. The following types are supported: `STRING`, numeric (`INTEGER`, `FLOAT,` `DOUBLE`, `DECIMAL` …), `BOOLEAN`, `INTERVAL`, `NULL`.

## Examples

You can find more examples in [Row filters and column masks](https://docs.databricks.com/aws/en/data-governance/unity-catalog/filters-and-masks/index.md).

```sql
-- Create a table with a row filter column
> CREATE FUNCTION filter_emps(dept STRING) RETURN is_account_group_member(dept);
> CREATE TABLE employees(emp_name STRING, dept STRING) WITH ROW FILTER filter_emps ON (dept);
> INSERT INTO employees VALUES ('Jones', 'Engineering'), ('Smith', 'Sales');

-- As a member of engineering
> SELECT * FROM employees;
  Jones Engineering

-- As a member of sales
> SELECT * FROM employees;
  Smith Sales
```

## Related articles

* [MASK clause](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-column-mask.md)
* [ALTER MATERIALIZED VIEW](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-alter-materialized-view.md)
* [ALTER STREAMING TABLE](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-alter-streaming-table.md)
* [ALTER TABLE](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-alter-table.md)
* [CREATE MATERIALIZED VIEW](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-create-materialized-view.md)
* [CREATE STREAMING TABLE](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-create-streaming-table.md)
* [CREATE TABLE](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-create-table-using.md)
