{"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/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Database/Query/Grammars/Grammar.php#L794-L830","documentation":"The base Grammar::compileJsonLength() throws because this engine has no JSON length function mapping. All four bundled grammars (SQLite, MySQL, Postgres, SQL Server) override compileJsonLength, so the base throw is only hit by a custom Grammar subclass that does not implement JSON length.","triggerScenarios":"Calling whereJsonLength($column, $operator, $value) on a connection whose grammar extends the base Grammar without overriding compileJsonLength. None of the bundled drivers reach this base method.","commonSituations":"A custom/third-party grammar integration that is missing JSON length support. Building a new driver and forgetting to implement the JSON where-clause family.","solutions":["Implement compileJsonLength($column, $operator, $value) on the custom Grammar using the engine's native JSON length function.","Switch to a bundled driver that supports JSON length operations.","Substitute whereRaw with the native JSON length function for the specific engine."],"exampleFix":"// before (custom grammar missing impl)\n$q->whereJsonLength('meta->items', '>', 3);\n\n// after\nprotected function compileJsonLength($column, $operator, $value)\n{\n    return \"json_length({$column}) {$operator} {$value}\";\n}","handlingStrategy":"validation","validationCode":"$driver = $query->getConnection()->getDriverName();\nif (! in_array($driver, ['mysql','sqlite','pgsql','sqlsrv'])) {\n    throw new \\LogicException('whereJsonLength is not supported by this engine.');\n}\n$query->whereJsonLength('meta->items', '>', 3);","typeGuard":"function supportsJsonLength(\\Illuminate\\Database\\Connection $connection): bool\n{\n    return method_exists($connection->getQueryGrammar(), 'compileJsonLength');\n}","tryCatchPattern":null,"preventionTips":["Implement compileJsonLength on any custom grammar.","Keep JSON length checks on bundled drivers.","Cover JSON methods in driver capability tests."],"tags":["json","where-json-length","custom-grammar","database-engine"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}