{"record":{"id":"5429a636aae6c906","repo":"laravel/framework","slug":"this-database-engine-does-not-support-json-length","errorCode":null,"errorMessage":"This database engine does not support JSON length operations.","messagePattern":"This database engine does not support JSON length operations\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Database/Query/Grammars/Grammar.php","lineNumber":812,"sourceCode":"            $where['column'],\n            $where['operator'],\n            $this->parameter($where['value'])\n        );\n    }\n\n    /**\n     * Compile a \"JSON length\" statement into SQL.\n     *\n     * @param  string  $column\n     * @param  string  $operator\n     * @param  string  $value\n     * @return string\n     *\n     * @throws \\RuntimeException\n     */\n    protected function compileJsonLength($column, $operator, $value)\n    {\n        throw new RuntimeException('This database engine does not support JSON length operations.');\n    }\n\n    /**\n     * Compile a \"JSON value cast\" statement into SQL.\n     *\n     * @param  string  $value\n     * @return string\n     */\n    public function compileJsonValueCast($value)\n    {\n        return $value;\n    }\n\n    /**\n     * Compile a \"where fulltext\" clause.\n     *\n     * @param  \\Illuminate\\Database\\Query\\Builder  $query\n     * @param  array  $where","sourceCodeStart":794,"sourceCodeEnd":830,"githubUrl":"https://github.com/laravel/framework/blob/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Database/Query/Grammars/Grammar.php#L794-L830","documentation":"The base Grammar's compileJsonLength throws by default. All four major engine grammars (MySQL, PostgreSQL, SQLite, SQL Server) override it with engine-specific JSON_ARRAY_LENGTH / jsonb_array_length / json_array_length / OPENJSON functions. This error fires only for a custom grammar extending the base Grammar without an override.","triggerScenarios":"Using whereJsonLength() on a query builder whose grammar is a custom class extending Grammar without implementing compileJsonLength. This occurs with third-party database drivers.","commonSituations":"Using a community database package that extends the base Grammar but has not implemented JSON length operations. Rare in practice since the four built-in engines all support it.","solutions":["Switch to a built-in connection (mysql, pgsql, sqlite, or sqlsrv) — all four override compileJsonLength","Override compileJsonLength in your custom grammar with the correct SQL function for your engine","Replace whereJsonLength with a raw clause, e.g., ->whereRaw('json_array_length(metadata) > ?', [2])"],"exampleFix":"// before — custom grammar without JSON length support\nDB::table('users')->whereJsonLength('roles', '>', 2)->get();\n\n// after — raw clause for a custom engine\nDB::table('users')->whereRaw('json_array_length(roles) > ?', [2])->get();","handlingStrategy":"try-catch","validationCode":"$grammar = DB::connection()->getQueryGrammar();\n$method = new ReflectionMethod($grammar, 'compileJsonLength');\n\nif ($method->getDeclaringClass()->getName() !== 'Illuminate\\\\Database\\\\Query\\\\Grammars\\\\Grammar') {\n    DB::table('users')->whereJsonLength('roles', '>', 2)->get();\n}","typeGuard":"function grammarSupportsJsonLength(): bool {\n    $grammar = DB::connection()->getQueryGrammar();\n    $method = new ReflectionMethod($grammar, 'compileJsonLength');\n    return $method->getDeclaringClass()->getName() !== 'Illuminate\\\\Database\\\\Query\\\\Grammars\\\\Grammar';\n}","tryCatchPattern":"try {\n    DB::table('users')->whereJsonLength('roles', '>', 2)->get();\n} catch (\\RuntimeException $e) {\n    if (str_contains($e->getMessage(), 'JSON length')) {\n        DB::table('users')->whereRaw('json_array_length(roles) > ?', [2])->get();\n    } else {\n        throw $e;\n    }\n}","preventionTips":["Use a built-in connection — all four override compileJsonLength","If using a custom grammar, override compileJsonLength before calling whereJsonLength","Keep a raw json_array_length equivalent ready for custom drivers"],"tags":["json","grammar","database","custom-driver"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}