filament icon indicating copy to clipboard operation
filament copied to clipboard

Postgres throws "undefined column" when using searchable in tables

Open robinvda opened this issue 2 months ago • 2 comments

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%))

robinvda avatar Nov 11 '25 08:11 robinvda

The same error with searching by relationship field searchable(['signal.uuid']) column signal does not exists

indigoram89 avatar Nov 20 '25 11:11 indigoram89

Is there a reason why the generate_search_column_expression function returns a string or an expression? Why not always an expression? I was just trying this with mysql and postgres and at first glance i don't see any issues.

Another issue (not exactly related to this one) is that when using searchable() on a table, it will always search case sensitive. This seems to be caused by the CanSearchRecords trait passing isSearchForcedCaseInsensitive: false to the helper method.

robinvda avatar Dec 08 '25 12:12 robinvda