Skip to content

Postgres throws "undefined column" when using searchable in tables #18467

@robinvda

Description

@robinvda

Package

filament/filament

Package Version

v4.2.0

Laravel Version

v12.37.0

Livewire Version

v3.6.4

PHP Version

8.4.1

Problem description

An Undefined column error is thrown when searching a table which uses ->searchable([...]) on the Table object. It works fine when using ->searchable() on Columns.

I found that adding a driver check in the generate_search_column_expression helper method fixes it for me. It makes sure that for Postgres it always returns an expression, never a string, but I'm not sure if this breaks other things.
https://github.com/filamentphp/filament/blob/4.x/packages/support/src/helpers.php#L294

if (
    $driverName === 'pgsql' ||
    str($column)->contains('(') || // This checks if the column name probably contains a raw expression like `lower()` or `json_extract()`.
    filled($collation)
) {
    return new Expression($column);
}

Expected behavior

Searching a table should filter the table based on the input, instead of throwing an error.

Steps to reproduce

  • Use a Postgres database
  • Create a resource like CustomerResource
  • Add ->searchable(['any_column']) to the table in the CustomersTable class
  • Open the browser and try to search for something in the table
  • The error is thrown

Reproduction repository (issue will be closed if this is not valid)

https://github.com/robinvda/filament-postgres-search-bug

Relevant log output

Illuminate\Database\QueryException
vendor/laravel/framework/src/Illuminate/Database/Connection.php:824

SQLSTATE[42703]: Undefined column: 7 ERROR: column ""name"::text" does not exist LINE 1: ...ect count(*) as aggregate from "customers" where ("""name"":... ^ (Connection: pgsql, SQL: select count(*) as aggregate from "customers" where ("""name""::text"::text like %a%))

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Status

    Todo

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions