{"record":{"id":"97d1a5bea992382d","repo":"n8n-io/n8n","slug":"output-or-returning-clause-only-supported-by-micro-97d1a5","errorCode":null,"errorMessage":"OUTPUT or RETURNING clause only supported by Microsoft SQL Server or PostgreSQL or MariaDB databases.","messagePattern":"OUTPUT or RETURNING clause only supported by Microsoft SQL Server or PostgreSQL or MariaDB databases\\.","errorType":"exception","errorClass":"ReturningStatementNotSupportedError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/typeorm/src/query-builder/InsertQueryBuilder.ts","lineNumber":253,"sourceCode":"\n\t/**\n\t * Optional returning/output clause.\n\t * Returning is a SQL string containing returning statement.\n\t */\n\treturning(returning: string): this;\n\n\t/**\n\t * Optional returning/output clause.\n\t */\n\treturning(returning: string | string[]): this;\n\n\t/**\n\t * Optional returning/output clause.\n\t */\n\treturning(returning: string | string[]): this {\n\t\t// not all databases support returning/output cause\n\t\tif (!this.connection.driver.isReturningSqlSupported('insert')) {\n\t\t\tthrow new ReturningStatementNotSupportedError();\n\t\t}\n\n\t\tthis.expressionMap.returning = returning;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Indicates if entity must be updated after insertion operations.\n\t * This may produce extra query or use RETURNING / OUTPUT statement (depend on database).\n\t * Enabled by default.\n\t */\n\tupdateEntity(enabled: boolean): this {\n\t\tthis.expressionMap.updateEntity = enabled;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Adds additional ON CONFLICT statement supported in postgres and cockroach.","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/typeorm/src/query-builder/InsertQueryBuilder.ts#L235-L271","documentation":"InsertQueryBuilder.returning() has the same guard as the delete variant but checks isReturningSqlSupported('insert'). It throws ReturningStatementNotSupportedError before building the INSERT, so no statement reaches the database. Drivers that support RETURNING/OUTPUT (Postgres family, SQL Server, modern SQLite) pass; others (MySQL, Oracle, SAP, Mongo) fail.","triggerScenarios":"Calling .insert().into(Entity).values(...).returning(['id']).execute() on a driver where isReturningSqlSupported('insert') is false. Also surfaces when updateEntity behaviour (enabled by default) is forced to use RETURNING on an unsupported driver.","commonSituations":"Migrating a Postgres-only insert-and-get-id flow to MySQL/MariaDB. CI matrix tests running SQLite where RETURNING is conditionally supported. Library code that unconditionally requests returning primary keys.","solutions":["Remove .returning() and rely on .generatedMap or the returned identifer after insert (insert().values().execute().identifiers).","Branch on driver.isReturningSqlSupported('insert') before calling .returning().","Use repository.save() which handles id retrieval per-driver instead of a raw insert with returning.","Switch to Postgres/SQLite if RETURNING-on-insert is a hard requirement."],"exampleFix":"// before\nconst { raw } = await dataSource.createQueryBuilder()\n  .insert().into(User).values({ email })\n  .returning(['id']).execute(); // throws on MySQL\n\n// after\nconst res = await dataSource.createQueryBuilder()\n  .insert().into(User).values({ email }).execute();\nconst id = res.identifiers[0]?.id;","handlingStrategy":"validation","validationCode":"function supportsInsertReturning(ds: DataSource): boolean {\n  return ds.driver.isReturningSqlSupported('insert');\n}\nif (!supportsInsertReturning(dataSource)) { /* use identifiers from execute() */ }","typeGuard":"function supportsInsertReturning(driver: import('../driver/Driver').Driver): boolean {\n  return driver.isReturningSqlSupported('insert');\n}","tryCatchPattern":"try {\n  return qb.insert().into(E).values(v).returning(cols).execute();\n} catch (e) {\n  if (e instanceof ReturningStatementNotSupportedError) { /* use execute().identifiers */ }\n  throw e;\n}","preventionTips":["Check driver.isReturningSqlSupported('insert') before .returning() on inserts.","Use repository.save() or insert().execute().identifiers for portable id retrieval.","Branch upsert/return logic on connection.options.type in shared repositories.","Test RETURNING-dependent features against every supported DB in CI."],"tags":["query-builder","insert","returning","driver-capability"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}