Skip to content

Error when filtering by UUID in PostgreSQL – "function lower(uuid) does not exist" #1007

Discussion options

You must be logged in to vote

Hi, just wanted to follow up on this.

Turns out I found a solution for filtering UUIDs in PostgreSQL when using spatie/laravel-query-builder.

The issue occurred because the default filter tries to do a LOWER() + LIKE on the UUID column, which throws an error in PostgreSQL since UUIDs aren't compatible with LOWER().

Here's the fix that worked for me:

$results = QueryBuilder::for($query)
    ->allowedFilters([
        ...$fields,
        AllowedFilter::exact('topic_id'), // ✅ this solved the issue
    ])
    ->defaultSort('-created_at')
    ->allowedSorts(generateAllowedSorts($fields))
    ->paginate($request->input('per_page'))
    ->appends(request()->query());

By explicitly defining the …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by dikhimartin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant