drizzle-team/drizzle-orm · error · Error
Cannot use concurrently and withNoData together
Error message
Cannot use concurrently and withNoData together
What it means
PgRefreshMaterializedView.concurrently (refresh-materialized-view.ts:51) refuses to set CONCURRENTLY once WITH NO DATA has already been requested, because Postgres does not allow both on REFRESH MATERIALIZED VIEW. CONCURRENTLY requires the view to be populated and cannot be combined with the no-data initial population option.
Source
Thrown at drizzle-orm/src/pg-core/query-builders/refresh-materialized-view.ts:53
private config: {
view: PgMaterializedView;
concurrently?: boolean;
withNoData?: boolean;
};
constructor(
view: PgMaterializedView,
private session: PgSession,
private dialect: PgDialect,
) {
super();
this.config = { view };
}
concurrently(): this {
if (this.config.withNoData !== undefined) {
throw new Error('Cannot use concurrently and withNoData together');
}
this.config.concurrently = true;
return this;
}
withNoData(): this {
if (this.config.concurrently !== undefined) {
throw new Error('Cannot use concurrently and withNoData together');
}
this.config.withNoData = true;
return this;
}
/** @internal */
getSQL(): SQL {
return this.dialect.buildRefreshMaterializedViewQuery(this.config);
}
View on GitHub (pinned to b7862528fd)
Solutions
- Drop the .withNoData() call when using .concurrently().
- For an initial population, do a non-concurrent refresh first, then subsequent refreshes can be concurrent.
- Make the two options mutually exclusive in your configuration layer.
Example fix
// before db.refreshMaterializedView(view).withNoData().concurrently(); // after db.refreshMaterializedView(view).concurrently(); // view already populated
Defensive patterns
Strategy: validation
Validate before calling
function refresh(view: Parameters<Db['refreshMaterializedView']>[0], opts: { concurrently?: boolean; withNoData?: boolean }) {
if (opts.concurrently && opts.withNoData) {
throw new Error('concurrently and withNoData are mutually exclusive');
}
let q = db.refreshMaterializedView(view);
if (opts.concurrently) q = q.concurrently();
if (opts.withNoData) q = q.withNoData();
return q;
} Type guard
function canRunConcurrently(populated: boolean, wantsNoData: boolean): boolean {
return populated && !wantsNoData;
} Prevention
- Make concurrently and withNoData mutually exclusive in config.
- Populate the view with a normal refresh before using CONCURRENTLY.
- Document that CONCURRENTLY needs a populated view.
When it happens
Trigger: Calling .withNoData() then .concurrently() on the same refresh builder: db.refreshMaterializedView(v).withNoData().concurrently().
Common situations: Chaining options while following an example; building a configurable refresh routine that toggles both flags from config; misunderstanding that CONCURRENTLY only works on already-populated views.
Related errors
- You have an empty array for "${name}" enum values
- Cannot pass undefined values to any set operator
- values() must be called with at least one value
- Insert select error: selected fields are not the same or are
- Alias "${tableName}" is already used in this query
AI-assisted analysis of drizzle-team/drizzle-orm@b7862528fd (2026-08-03).
Data as JSON: /data/errors/2acc99f8367c2a90.json.
Report an issue: GitHub.