From 24c97f178d2802216be487dc5ddb8d25806a27a5 Mon Sep 17 00:00:00 2001 From: Lukas Mateffy Date: Tue, 8 Jul 2025 13:48:28 +0200 Subject: [PATCH 1/2] fix: pgsql exception in global search with periods in table names --- packages/support/src/helpers.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/packages/support/src/helpers.php b/packages/support/src/helpers.php index 0c9761a80d..847000e911 100644 --- a/packages/support/src/helpers.php +++ b/packages/support/src/helpers.php @@ -163,15 +163,11 @@ if (! function_exists('Filament\Support\generate_search_column_expression')) { { $driverName = $databaseConnection->getDriverName(); - if (Str::lower($column) !== $column) { - $column = match ($driverName) { - 'pgsql' => (string) str($column)->wrap('"'), - default => $column, - }; - } - $column = match ($driverName) { - 'pgsql' => "{$column}::text", + 'pgsql' => (string) str($column) + ->explode('.') + ->map(fn (string $part) => str($part)->wrap('"')) + ->implode('.') . '::text', default => $column, }; From 1523a9e5a3982660e20fb9059b7e3ed63e92edca Mon Sep 17 00:00:00 2001 From: Lukas Mateffy Date: Tue, 8 Jul 2025 14:49:55 +0200 Subject: [PATCH 2/2] fix: add JSON support to colon column fix and add tests --- packages/support/src/helpers.php | 9 +++++++-- tests/src/Support/helpersTest.php | 21 ++++++++++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/packages/support/src/helpers.php b/packages/support/src/helpers.php index 3dfc678bd6..62c72e6339 100644 --- a/packages/support/src/helpers.php +++ b/packages/support/src/helpers.php @@ -166,8 +166,13 @@ if (! function_exists('Filament\Support\generate_search_column_expression')) { $column = match ($driverName) { 'pgsql' => ( str($column)->contains('->') - ? str($column) - ->beforeLast('->') + ? str( + str($column) + ->beforeLast('->') + ->explode('.') + ->map(fn (string $part) => str($part)->wrap('"')) + ->implode('.') + ) ->append('->>') ->append("'") ->append(str($column)->afterLast('->')) diff --git a/tests/src/Support/helpersTest.php b/tests/src/Support/helpersTest.php index 627373d5ea..a5c8d2a29a 100644 --- a/tests/src/Support/helpersTest.php +++ b/tests/src/Support/helpersTest.php @@ -75,5 +75,24 @@ it('will generate json search column expression for pgsql', function () { $expression = generate_search_column_expression($column, $isSearchForcedCaseInsensitive, $databaseConnection); expect($expression->getValue($grammar)) - ->toBe("lower(data->>'name'::text)"); + ->toBe("lower(\"data\"->>'name'::text)"); }); + +it('will generate column expression for pgsql with colons in the name', function (string $column, string $text) { + $isSearchForcedCaseInsensitive = true; + + $databaseConnection = Mockery::mock(Connection::class); + $databaseConnection->shouldReceive('getDriverName')->andReturn('pgsql'); + $databaseConnection->shouldReceive('getConfig')->with('search_collation')->andReturn(null); + + $grammar = new PostgresGrammar($databaseConnection); + + $expression = generate_search_column_expression($column, $isSearchForcedCaseInsensitive, $databaseConnection); + + expect($expression->getValue($grammar)) + ->toBe($text); +}) + ->with([ + ['blog:posts.title', 'lower("blog:posts"."title"::text)'], + ['blog:posts:comments.author.name', 'lower("blog:posts:comments"."author"."name"::text)'], + ]);