laravel / telescope

An elegant debug assistant for the Laravel framework.
https://laravel.com/docs/telescope
MIT License
4.87k stars 583 forks source link

SQL error "operator does not exist: boolean = integer" with Postgres #1511

Closed allantatter closed 1 month ago

allantatter commented 2 months ago

Telescope Version

5.2.1

Laravel Version

11.21.0

PHP Version

8.2.21

Database Driver & Version

psql (PostgreSQL) 14.12 (Homebrew)

Description

Telescope views do not load with Postgres as a database driver. Tested with different Postges versions: 14 and 16.

SQLSTATE[42883]: Undefined function: 7 ERROR:  operator does not exist: boolean = integer
LINE 1: ... "type" = 'command' and "should_display_on_index" = 1 order ...
                                                             ^
HINT:  No operator matches the given name and argument types. You might need to add explicit type casts. (Connection: pgsql, SQL: select * from "telescope_entries" where "type" = command and "should_display_on_index" = 1 order by "sequence" desc limit 50) {"userId":1,"exception":"[object] (Illuminate\\Database\\QueryException(code: 42883): SQLSTATE[42883]: Undefined function: 7 ERROR:  operator does not exist: boolean = integer

Steps To Reproduce

Fresh Laravel and Laravel Telescope install with Postgres.

github-actions[bot] commented 2 months ago

Thank you for reporting this issue!

As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.

If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.

Thank you!

hafezdivandari commented 1 month ago

Please add the following lines to config\database.php file and let me know the result:

'connections' => [
    //...

    'pgsql' => [
        //...
        'sslmode' => 'prefer',
+       'options' => [
+           PDO::ATTR_EMULATE_PREPARES => false,
+       ],
    ],
],
allantatter commented 1 month ago

@hafezdivandari I needed to have emulate prepares as true for other parts of the application to work. I found a workaround to put change the emulate prepares config dynamically within TelescopeProvider's register() method:

if ($this->app->request->is('telescope/*')) {
    Config::set('database.connections.pgsql.options.' . PDO::ATTR_EMULATE_PREPARES, false);
}