`Count` will not return same value counted as in `data.length` when filtered by nested `!inner` criteria.
See original GitHub issueBug report
I think I found a bug when counting !inner
joined tables with foreign filters.
Describe the bug
When a table is filtered by properties of the same table, count
and data.length
will match (considering no limit and count to be ‘exact’).
When a table is filtered by !inner
properties of other tables, data.length
returns correct number of results, but count
still return the correct one considering there are no foreign filters.
To Reproduce
Given 2 tables, Users
and Roles
for instance. If I activate count and filter by a Correct filter of User_id but an Inexistent Incorrect role inner filter the count will return 1 but with no data in the array.
const {data, error, count} = await supabase.from('users')
.select('*, role:roles!inner(*)', {count: 'exact'})
.eq('user_id', 123) // This is a matching correct user
.eq('role.name', 'whatever') // This will never be true.
data.length === 0 // true (This is correct since roles will never match here)
count === 0 // false (This should be true, count should be 0)
count === 1 // true (This should be false, but returns 1 because the filter by user still is valid)
Expected behavior
- Given a no limited query,
data.length
andcount
should match in all the cases (when using{count: 'exact'}
). - Filtering inner joined tables should also affect the count of the query.
System information
- OS: macOS
- Browser (if applies) node.js
- Version of supabase-js: 1.28.5
- Version of Node.js: 14.18.1
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Inaccurate total record count returned when top-level filtering ...
Count will not return same value counted as in data.length when filtered by nested !inner criteria. supabase/postgrest-js#230.
Read more >Excel FILTER Function – How To Use
The FILTER function returns an array of values that are spilled onto your worksheet unless the function is nested to relay the output...
Read more >How to count unique values in Excel an easy way
The trick is to "feed" the entire range to UNIQUE so that it finds the unique combinations of values in multiple columns. After...
Read more >Counting rows from a subquery - mysql
SELECT COUNT(DISTINCT ip_address) FROM `ports`;. This returns 5 because it only counts distinct values and the subquery is not needed anymore. However this ......
Read more >Filtering nested JSON array in javascript and returning ...
With reduce ": data.products.reduce((p, c) => ( (c.SKUs = c.SKUs.filter( sku => sku.Attributes.some(att => att.value === "Color") && sku.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The Support team managed to upgrade me to PostgREST 9 and now the test query returns the commented correct response in #4170. And of course, the count now matches the expected results for all the cases I had already a test case implemented.
Thanks and closing issue.
Done, with support ticket
3838
, and also, to add more info to the test I did.I executed:
Despite that
trips
is not existent for me, the answer to this query should be (and was) similar (if not the same) than with<9.0 versions
with this response:I hope you have all you need (together with the email) to check this issue deeper.