{"record":{"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/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Database/Query/Grammars/Grammar.php#L1273-L1309","documentation":"The base Grammar's compileInsertOrIgnoreReturning throws by default. Only PostgresGrammar and SQLiteGrammar override it (using INSERT ... ON CONFLICT DO NOTHING RETURNING / INSERT OR IGNORE ... RETURNING). MySqlGrammar/MariaDbGrammar and SqlServerGrammar do not override it, so calling insertOrIgnore with a returning clause on MySQL or SQL Server triggers the throw. MySQL's INSERT IGNORE does not support a RETURNING clause.","triggerScenarios":"Calling ->insertOrIgnore($values, returning: ['id']) or using the returning parameter on a MySQL, MariaDB, or SQL Server connection.","commonSituations":"Developer assumes MySQL INSERT IGNORE supports RETURNING (it does not — RETURNING is PostgreSQL/SQLite-specific). Code written for PostgreSQL deployed on MySQL.","solutions":["Switch to a PostgreSQL or SQLite connection — the only grammars that override compileInsertOrIgnoreReturning","On MySQL, drop the returning parameter and call insertOrIgnore() without it, then use lastInsertId() or a follow-up SELECT to retrieve inserted rows","On MySQL, use upsert() without a returning clause if you need insert-or-update semantics","On MySQL 8.0+, use a raw INSERT ... ON DUPLICATE KEY UPDATE statement and SELECT the affected rows afterward"],"exampleFix":"// before — fails on MySQL (RETURNING not supported)\n$id = DB::table('users')->insertOrIgnore(['email' => 'a@b.com'], returning: ['id']);\n\n// after — omit returning, retrieve ID separately\nDB::table('users')->insertOrIgnore(['email' => 'a@b.com']);\n$id = DB::table('users')->where('email', 'a@b.com')->value('id');","handlingStrategy":"type-guard","validationCode":"$driver = DB::connection()->getDriverName();\n\nif (in_array($driver, ['pgsql', 'sqlite'])) {\n    $id = DB::table('users')->insertOrIgnore($values, returning: ['id']);\n} else {\n    // MySQL / SQL Server: omit returning, query afterward\n    DB::table('users')->insertOrIgnore($values);\n    $id = DB::table('users')->where('email', $values['email'])->value('id');\n}","typeGuard":"function supportsInsertOrIgnoreReturning(): bool {\n    return in_array(DB::connection()->getDriverName(), ['pgsql', 'sqlite']);\n}","tryCatchPattern":"try {\n    $result = DB::table('users')->insertOrIgnore($values, returning: ['id']);\n} catch (\\RuntimeException $e) {\n    if (str_contains($e->getMessage(), 'insert or ignore with returning')) {\n        DB::table('users')->insertOrIgnore($values);\n        $result = DB::table('users')->where('email', $values['email'])->value('id');\n    } else {\n        throw $e;\n    }\n}","preventionTips":["Treat the returning parameter on insertOrIgnore as PostgreSQL/SQLite-only","On MySQL, plan to retrieve IDs with a follow-up query","Document RETURNING clause support per engine in project docs"],"tags":["insert","returning","mysql","postgres","database"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}