{"id":"2acc99f8367c2a90","repo":"drizzle-team/drizzle-orm","slug":"cannot-use-concurrently-and-withnodata-together-2acc99","errorCode":null,"errorMessage":"Cannot use concurrently and withNoData together","messagePattern":"Cannot use concurrently and withNoData together","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"drizzle-orm/src/pg-core/query-builders/refresh-materialized-view.ts","lineNumber":53,"sourceCode":"\n\tprivate config: {\n\t\tview: PgMaterializedView;\n\t\tconcurrently?: boolean;\n\t\twithNoData?: boolean;\n\t};\n\n\tconstructor(\n\t\tview: PgMaterializedView,\n\t\tprivate session: PgSession,\n\t\tprivate dialect: PgDialect,\n\t) {\n\t\tsuper();\n\t\tthis.config = { view };\n\t}\n\n\tconcurrently(): this {\n\t\tif (this.config.withNoData !== undefined) {\n\t\t\tthrow new Error('Cannot use concurrently and withNoData together');\n\t\t}\n\t\tthis.config.concurrently = true;\n\t\treturn this;\n\t}\n\n\twithNoData(): this {\n\t\tif (this.config.concurrently !== undefined) {\n\t\t\tthrow new Error('Cannot use concurrently and withNoData together');\n\t\t}\n\t\tthis.config.withNoData = true;\n\t\treturn this;\n\t}\n\n\t/** @internal */\n\tgetSQL(): SQL {\n\t\treturn this.dialect.buildRefreshMaterializedViewQuery(this.config);\n\t}\n","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/drizzle-team/drizzle-orm/blob/b7862528fd8fc39bc2653a6c18dad7c1f4e68d10/drizzle-orm/src/pg-core/query-builders/refresh-materialized-view.ts#L35-L71","documentation":"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.","triggerScenarios":"Calling .withNoData() then .concurrently() on the same refresh builder: db.refreshMaterializedView(v).withNoData().concurrently().","commonSituations":"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.","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."],"exampleFix":"// before\ndb.refreshMaterializedView(view).withNoData().concurrently();\n\n// after\ndb.refreshMaterializedView(view).concurrently(); // view already populated","handlingStrategy":"validation","validationCode":"function refresh(view: Parameters<Db['refreshMaterializedView']>[0], opts: { concurrently?: boolean; withNoData?: boolean }) {\n  if (opts.concurrently && opts.withNoData) {\n    throw new Error('concurrently and withNoData are mutually exclusive');\n  }\n  let q = db.refreshMaterializedView(view);\n  if (opts.concurrently) q = q.concurrently();\n  if (opts.withNoData) q = q.withNoData();\n  return q;\n}","typeGuard":"function canRunConcurrently(populated: boolean, wantsNoData: boolean): boolean {\n  return populated && !wantsNoData;\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["materialized-view","refresh","validation"],"analyzedSha":"b7862528fd8fc39bc2653a6c18dad7c1f4e68d10","analyzedAt":"2026-08-03T18:11:14.318Z","schemaVersion":2}