F
Filament13mo ago
Shavik

Table Summarizer Bug on PostgreSQL

So I have a table column defined as such:
Tables\Columns\TextColumn::make('price')
->money()
// Old simple way
// ->summarize(Sum::make()->money()->label('Total Price')),
// New Way with custom query
->summarize(
Summarizer::make()
->label('Total')
->money()
->using(fn (\Illuminate\Database\Query\Builder $query) => $query->sum(DB::raw('price * quantity'))),
Tables\Columns\TextColumn::make('price')
->money()
// Old simple way
// ->summarize(Sum::make()->money()->label('Total Price')),
// New Way with custom query
->summarize(
Summarizer::make()
->label('Total')
->money()
->using(fn (\Illuminate\Database\Query\Builder $query) => $query->sum(DB::raw('price * quantity'))),
I had asked yesterday how do to this price * quantity calculation but I was getting this error: SQLSTATE[42601]: Syntax error: 7 ERROR: zero-length delimited identifier at or near """" The query that is generated is
SELECT
sum(price * quantity) AS aggregate
FROM
(
SELECT
"line_items".*
FROM
"line_items"
INNER JOIN "invoices" ON "invoices"."id" = "line_items"."invoice_id"
WHERE
"invoices"."requisition_id" = 1
) AS ""
SELECT
sum(price * quantity) AS aggregate
FROM
(
SELECT
"line_items".*
FROM
"line_items"
INNER JOIN "invoices" ON "invoices"."id" = "line_items"."invoice_id"
WHERE
"invoices"."requisition_id" = 1
) AS ""
Clearly it's the last line ) AS "". I dug into the Summarizer.php file on line 108. $query = DB::table($query->toBase()); I haven't really looked at the source code for any of the Filament query stuff before it I changed the line to $query = DB::table($query->toBase(), 'test'); The above code now works. I'm not saying the table alias needs to be 'test' but I just needed a name to try. I'm not really sure what the best practice (naming) for this would be but I might also cross post this as a GitHub issue. Just wasn't sure if there was something else on the 'user' side (me, the dev) that I need to do to get this working? (since it also seems like a postgres quirk)
19 Replies
Shavik
ShavikOP13mo ago
This is the page working with the modified Summarizer.php
No description
Shavik
ShavikOP13mo ago
I have made a sample project demostrating the issue. Here is the flare page for it. I will have the latest code pushed to it in a moment and will link the repo/file showing the issue.
Shavik
ShavikOP13mo ago
Flare
SQLSTATE[42601]: Syntax error: 7 ERROR: zero-length delimited identifier at or near """" LINE 1: ...ity) as aggregate from (select * from "invoice_items") as "" ^ (Connection: pgsql, SQL: select sum(price * quantity) as aggregate from (select * from "invoice_items") as "") - T...
Shavik
ShavikOP13mo ago
Sample repo and linked to line causing the issue
Shavik
ShavikOP13mo ago
GitHub
filament/packages/tables/src/Columns/Summarizers/Summarizer.php at ...
A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS. - filamentphp/filament
Shavik
ShavikOP13mo ago
GitHub
filament/packages/tables/src/Concerns/CanSummarizeRecords.php at 62...
A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS. - filamentphp/filament
Shavik
ShavikOP13mo ago
Will try that here and see if it fixes it Hmm maybe that was just an accidental omission. Looks like that fixes it
awcodes
awcodes13mo ago
GitHub
Bug with custom summarize in groupings · Issue #9073 · filamentphp/...
Package filament/filament Package Version v3.0.74 Laravel Version v10.28.0 Livewire Version v3.0.8 PHP Version PHP 8.2.11 Problem description With custom summarize-functions and grouping the summar...
Shavik
ShavikOP13mo ago
Maybe? I haven't done those types yet but mine is a 'hard crash' Flare link above like PostgreSQL query error I am totally uneducated on this part of the Filament source code but I wonder if there is any reason the 'same' line in different in the Summarizer vs the CanSummarizeRecords class. If I copy the line from CanSummarizeRecords to Summarizer, it works great
awcodes
awcodes13mo ago
Could be a bug. I honestly don’t know. I’ve personally never worked with the summerizers except one time where I had a problem with them not working with Orbit and an sqlite db instance. I’ve never once actually working with a Postgres db. Lol. Sorry.
Shavik
ShavikOP13mo ago
I use it exclusively for every client and project I work on heh Haven't used MySQL/MariaDB in maybe 5ish years? maybe 4
Shavik
ShavikOP13mo ago
GitHub
Summarize Query Bug on PostgreSQL · Issue #9177 · filamentphp/filam...
Package filament/filament Package Version v3.0.80 Laravel Version v10.28.0 Livewire Version v3.0.10 PHP Version v8.2.11 Problem description When using a custom Summarizer on PostgreSQL, I get the f...
Shavik
ShavikOP13mo ago
Bug Posted First issue posted, Tried to include as much detail as possible. Should I go ahead and submit a PR? Understandably needs to be reviewed but just figured while I'm in the middle of this
awcodes
awcodes13mo ago
If it’s a solution that doesn’t break anything else then yes submit the PR. Most of us don’t work with Postgres day to day, so if it solves the problem without breaking existing functionality we are definitely open to it.
Shavik
ShavikOP13mo ago
Happy to help here where I can Maybe one of the guys that works on this part of the core will say oh yea, it should have been that way the whole time. ¯\_(ツ)_/¯ I haven't really done $query = DB::table($query->toBase(), $query->getModel()->getTable()); before but can easily see in the resulting query that leaving out the second argument, generates an invalid query on Postgres
Shavik
ShavikOP13mo ago
GitHub
Fixes Summarize Query Bug on PostgreSQL #9177 by chrisreedio · Pull...
This fixes the bug I documented in #9177 . Summary When using a custom Summarizer on PostgreSQL, I get the following QueryException: SQLSTATE[42601]: Syntax error: 7 ERROR: zero-length delimited id...
Shavik
ShavikOP13mo ago
I almost feel bad submitting a PR / bug on one hand, it fixes things, on the other, its more work for you guys lol
awcodes
awcodes13mo ago
Don’t feel bad. We appreciate it. We are busy but we do care about making a better product when it makes sense. Thank you.
Want results from more Discord servers?
Add your server