question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`Count` will not return same value counted as in `data.length` when filtered by nested `!inner` criteria.

See original GitHub issue

Bug 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

  1. Given a no limited query, data.length and count should match in all the cases (when using {count: 'exact'}).
  2. 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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
Egnuscommented, Dec 8, 2021

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.

0reactions
Egnuscommented, Dec 7, 2021

Done, with support ticket 3838, and also, to add more info to the test I did.

I executed:

GET https://__.supabase.co/rest/v1/trips?id=is.anything

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:

{
    "message": "syntax error at or near \"'anything'\"",
    "code": "42601",
    "hint": null,
    "details": null
}

I hope you have all you need (together with the email) to check this issue deeper.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found