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

  1. Drop the .withNoData() call when using .concurrently().
  2. For an initial population, do a non-concurrent refresh first, then subsequent refreshes can be concurrent.
  3. 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

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


AI-assisted analysis of drizzle-team/drizzle-orm@b7862528fd (2026-08-03). Data as JSON: /data/errors/2acc99f8367c2a90.json. Report an issue: GitHub.