{"id":"066d1b4bb3ba6358","repo":"laravel/framework","slug":"this-database-engine-does-not-support-insert-or-ig","errorCode":null,"errorMessage":"This database engine does not support insert or ignore with returning.","messagePattern":"This database engine does not support insert or ignore with returning\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Database/Query/Grammars/Grammar.php","lineNumber":1291,"sourceCode":"    public function compileInsertOrIgnore(Builder $query, array $values)\n    {\n        throw new RuntimeException('This database engine does not support inserting while ignoring errors.');\n    }\n\n    /**\n     * Compile an insert or ignore statement with a returning clause into SQL.\n     *\n     * @param  \\Illuminate\\Database\\Query\\Builder  $query\n     * @param  array  $values\n     * @param  array  $returning\n     * @param  array|null  $uniqueBy\n     * @return string\n     *\n     * @throws \\RuntimeException\n     */\n    public function compileInsertOrIgnoreReturning(Builder $query, array $values, array $returning, ?array $uniqueBy)\n    {\n        throw new RuntimeException('This database engine does not support insert or ignore with returning.');\n    }\n\n    /**\n     * Compile an insert and get ID statement into SQL.\n     *\n     * @param  \\Illuminate\\Database\\Query\\Builder  $query\n     * @param  array  $values\n     * @param  string|null  $sequence\n     * @return string\n     */\n    public function compileInsertGetId(Builder $query, $values, $sequence)\n    {\n        return $this->compileInsert($query, $values);\n    }\n\n    /**\n     * Compile an insert statement using a subquery into SQL.\n     *","sourceCodeStart":1273,"sourceCodeEnd":1309,"githubUrl":"https://github.com/laravel/framework/blob/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Database/Query/Grammars/Grammar.php#L1273-L1309","documentation":"The base Grammar::compileInsertOrIgnoreReturning() throws because this engine cannot combine INSERT IGNORE semantics with a RETURNING clause. Only SQLite and Postgres override compileInsertOrIgnoreReturning; MySQL and SQL Server do not, so insertOrIgnoreReturning() on those engines reaches this base throw.","triggerScenarios":"Calling DB::table(..)->insertOrIgnoreReturning($values, $returning, $uniqueBy) on a mysql or sqlsrv connection.","commonSituations":"Using insertOrIgnoreReturning to get back inserted rows on Postgres/SQLite, then running the same code against MySQL where INSERT IGNORE exists but RETURNING (without 8.0 RETURNING support wiring) is not implemented by the grammar.","solutions":["On MySQL, call insertOrIgnore() then re-select the matching rows with a subsequent query.","Switch to Postgres or SQLite where the combined operation is supported.","Restrict insertOrIgnoreReturning to pgsql/sqlite via a driver check and provide a two-step fallback elsewhere."],"exampleFix":"// before\n$rows = DB::table('imports')->insertOrIgnoreReturning($data, ['id']);\n\n// after (MySQL fallback)\n$driver = DB::getDriverName();\nif (in_array($driver, ['pgsql','sqlite'])) {\n    $rows = DB::table('imports')->insertOrIgnoreReturning($data, ['id']);\n} else {\n    DB::table('imports')->insertOrIgnore($data);\n    $rows = DB::table('imports')->whereIn('hash', $hashes)->get(['id']);\n}","handlingStrategy":"validation","validationCode":"$driver = DB::getDriverName();\nif (in_array($driver, ['pgsql','sqlite'])) {\n    $rows = DB::table('imports')->insertOrIgnoreReturning($data, ['id']);\n} else {\n    throw new \\LogicException('insertOrIgnoreReturning requires Postgres/SQLite.');\n}","typeGuard":"function supportsInsertOrIgnoreReturning(\\Illuminate\\Database\\Connection $connection): bool\n{\n    return $connection instanceof \\Illuminate\\Database\\PostgresConnection\n        || $connection instanceof \\Illuminate\\Database\\SQLiteConnection;\n}","tryCatchPattern":null,"preventionTips":["On MySQL, follow insertOrIgnore with a re-select to fetch inserted rows.","Restrict insertOrIgnoreReturning to Postgres/SQLite code paths.","Centralise bulk-import helpers to handle per-engine differences."],"tags":["insert-ignore","returning","database-engine","mysql","sqlsrv"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}