{"record":{"id":"0b49c6adb21acea4","repo":"laravel/framework","slug":"the-returning-columns-must-not-be-empty","errorCode":null,"errorMessage":"The returning columns must not be empty.","messagePattern":"The returning columns must not be empty\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Database/Query/Builder.php","lineNumber":4217,"sourceCode":"    /**\n     * Insert new records into the database and returning specified columns with optional ignoring specific conflicts.\n     *\n     * @param  non-empty-array<non-empty-string>  $returning\n     * @param  non-empty-string|non-empty-array<non-empty-string>|null  $uniqueBy\n     * @return \\Illuminate\\Support\\Collection\n     */\n    public function insertOrIgnoreReturning(array $values, array $returning = ['*'], array|string|null $uniqueBy = null)\n    {\n        if (empty($values)) {\n            return new Collection;\n        }\n\n        if ($uniqueBy === [] || $uniqueBy === '') {\n            throw new InvalidArgumentException('The unique columns must not be empty.');\n        }\n\n        if ($returning === []) {\n            throw new InvalidArgumentException('The returning columns must not be empty.');\n        }\n\n        if (! is_array(array_first($values))) {\n            $values = [$values];\n        } else {\n            foreach ($values as $key => $value) {\n                ksort($value);\n\n                $values[$key] = $value;\n            }\n        }\n\n        $this->applyBeforeQueryCallbacks();\n\n        $sql = $this->grammar->compileInsertOrIgnoreReturning($this, $values, $returning, $uniqueBy === null ? null : Arr::wrap($uniqueBy));\n\n        $result = new Collection(\n            $this->connection->selectFromWriteConnection($sql, $this->cleanBindings(Arr::flatten($values, 1)))","sourceCodeStart":4199,"sourceCodeEnd":4235,"githubUrl":"https://github.com/laravel/framework/blob/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Database/Query/Builder.php#L4199-L4235","documentation":"insertOrIgnoreReturning() builds a RETURNING clause from $returning; an empty list would emit 'INSERT ... RETURNING' with no columns, which most engines reject. The default is ['*'], and the method explicitly guards against an explicit empty array to fail loudly rather than emit broken SQL.","triggerScenarios":"->insertOrIgnoreReturning($rows, [], 'id'), usually because the calling code computed the returning list and ended up with no columns.","commonSituations":"Mapping a user-supplied 'fields' parameter that resolved to nothing; refactoring a SELECT-style column list into the returning slot; copy-paste from insert() which does not take a returning argument.","solutions":["Pass ['*'] (the default) when you want all columns back.","List the concrete columns you need: ->insertOrIgnoreReturning($rows, ['id', 'created_at'], 'id').","If you do not need any returned rows, use insertOrIgnore() instead."],"exampleFix":"// before\n->insertOrIgnoreReturning($rows, $fields, 'id')  // $fields = []\n\n// after\n->insertOrIgnoreReturning($rows, ['id'], 'id')","handlingStrategy":"validation","validationCode":"if ($returning === []) {\n    $returning = ['*'];\n}\n$query->insertOrIgnoreReturning($rows, $returning, $uniqueBy);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default $returning to ['*'] in your service layer.","Use insertOrIgnore() when no RETURNING columns are needed.","Whitelist requested columns against the table schema to avoid empty lists."],"tags":["query-builder","insert","returning","database","postgresql"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}