---
title: When to use REPLACE WHERE vs. materialized views
description: Choose between REPLACE WHERE flows and standalone materialized views for batch ETL. Use REPLACE WHERE for incremental overwrites and materialized views for query acceleration.
canonical_url: https://docs.databricks.com/gcp/en/sql/mv-st/replace-where-vs-materialized-views
---

# When to use REPLACE WHERE vs. materialized views

Both REPLACE WHERE flows and standalone materialized views let you maintain derived tables that stay current as source data changes, but they solve different problems. For most batch extract, transform, and load (ETL) workloads that periodically overwrite a time window or a partition, use an incremental REPLACE WHERE flow. Use materialized views for a query-acceleration layer that serves precomputed results to dashboards and reports.

This page covers standalone streaming tables and materialized views. For REPLACE WHERE flows in a Lakeflow pipeline, see [Batch processing with REPLACE WHERE flows](https://docs.databricks.com/gcp/en/ldp/flows-replace-where.md).

## <a id="recommendation" />Use REPLACE WHERE for batch overwrites

A [REPLACE WHERE flow](https://docs.databricks.com/gcp/en/sql/mv-st/flows-replace-where.md) recomputes and overwrites only the rows that match a predicate, such as a time window or a partition. All other rows stay untouched. Because the flow re-evaluates the source query for just that predicate range, the cost of each refresh depends on the size of the range, not the size of the table.

A materialized view maintains the full result of its defining query. Databricks refreshes a materialized view incrementally when the query and source data support it, and otherwise runs a full refresh. Whether a refresh is incremental depends on the query structure and the source tables, so the cost of each refresh is harder to predict. See [How are standalone materialized views refreshed?](https://docs.databricks.com/gcp/en/sql/mv-st/materialized.md#mv-refresh-processing).

For a batch ETL data model that changes in bounded ranges, a REPLACE WHERE flow lets you control exactly which rows each refresh rewrites. A materialized view is the better fit when readers need fast access to a precomputed result.

## <a id="medallion" />Map constructs to medallion layers

The following table maps each layer of a [medallion architecture](https://docs.databricks.com/gcp/en/lakehouse/medallion.md) to the construct Databricks recommends:

| Layer                               | Construct                                                                                                                                                                                            | Why                                                                                                                                     |
| ----------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| Bronze (raw ingestion)              | Ingestion with [Lakeflow Connect](https://docs.databricks.com/gcp/en/ingestion/overview.md) or [Auto Loader](https://docs.databricks.com/gcp/en/ingestion/cloud-object-storage/auto-loader/index.md) | Lands raw records incrementally as they arrive, without reprocessing history.                                                           |
| Silver (facts)                      | Incremental [REPLACE WHERE flow](https://docs.databricks.com/gcp/en/sql/mv-st/flows-replace-where.md)                                                                                                | Overwrites only the affected time windows or partitions for fact updates, late-arriving data, and corrections.                          |
| Silver (dimensions)                 | [`AUTO CDC` flow](https://docs.databricks.com/gcp/en/sql/language-manual/sql-ref-syntax-ddl-create-streaming-table-auto-cdc.md)                                                                      | Applies insert, update, and delete semantics automatically and preserves history with slowly changing dimension (SCD) Type 1 or Type 2. |
| Gold (aggregations and data models) | Incremental [REPLACE WHERE flow](https://docs.databricks.com/gcp/en/sql/mv-st/flows-replace-where.md)                                                                                                | Recomputes only the predicate range for aggregates and models, avoiding full-table recomputes.                                          |
| Query acceleration and serving      | [materialized view](https://docs.databricks.com/gcp/en/sql/language-manual/sql-ref-syntax-ddl-create-materialized-view.md)                                                                           | Serves precomputed results to dashboards and reports and keeps query results current.                                                   |

## <a id="decision-guide" />Decision guide

Use the following guide to choose between the two constructs.

Use a REPLACE WHERE flow when you:

* Run periodic batch overwrites of a time window or partition.
* Correct late-arriving data.
* Apply compliance deletions to a bounded range.
* Refresh data at the partition level.

Use a materialized view when you:

* Accelerate dashboard queries.
* Serve precomputed aggregations to readers.
* Keep query results current for a serving layer.

## <a id="example" />Example: incremental overwrite with REPLACE WHERE

The following example defines a target table that overwrites only the last 7 days of data on each refresh. During refresh, the flow deletes the rows matching the predicate, recomputes the source query for that same range, and inserts the results. Rows outside the window are left untouched:

```sql
CREATE OR REFRESH STREAMING TABLE payments_latest
FLOW REPLACE WHERE payment_date >= date_add(current_date(), -7) BY NAME
SELECT payment_id, booking_id, status, payment_date
FROM samples.wanderbricks.payments;
```

`BY NAME` is required so that columns match by name rather than position. For the full syntax, predicate overrides, backfills, and incremental refresh behavior, see [REPLACE WHERE flows for standalone streaming tables](https://docs.databricks.com/gcp/en/sql/mv-st/flows-replace-where.md).

## <a id="next-steps" />Additional resources

* [REPLACE WHERE flows for standalone streaming tables](https://docs.databricks.com/gcp/en/sql/mv-st/flows-replace-where.md)
* [CREATE MATERIALIZED VIEW](https://docs.databricks.com/gcp/en/sql/language-manual/sql-ref-syntax-ddl-create-materialized-view.md)
* [AUTO CDC FLOW Clause](https://docs.databricks.com/gcp/en/sql/language-manual/sql-ref-syntax-ddl-create-streaming-table-auto-cdc.md)
* [Choose an ETL approach on Databricks](https://docs.databricks.com/gcp/en/data-engineering/choose-etl-approach.md)
