Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When using multiple filters on the same column, only the last is applied #58

Open
jasonccox opened this issue Nov 21, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@jasonccox
Copy link

jasonccox commented Nov 21, 2024

Bug report

Describe the bug

When running a query with multiple filters on the same column, only the last filter on that column is applied. The previously applied filters are silently overwritten.

To Reproduce

The simplest way to reproduce is just to observe the HTTP request emitted by the library:

  1. Start netcat running on port 3000:

    netcat -l -p 3000
    
  2. In another terminal, run the following go code:

    package main
    
    import (
    	"github.com/supabase-community/postgrest-go"
    )
    
    func main() {
    	client := postgrest.NewClient("http://localhost:3000", "", nil)
    	if client.ClientError != nil {
    		panic(client.ClientError)
    	}
    
    	client.
    		From("users").
    		Select("name, age", "", false).
    		Lt("age", "30").
    		Gt("age", "20").
    		Execute()
    }
  3. Observe that the query string in the GET request printed by netcat only includes the greater than condition:

    GET /users?age=gt.20&select=name%2Cage HTTP/1.1
    

You could also test by spinning up a Postgrest instance, adding some rows to a table, and then making a similar query to the one shown above.

Expected behavior

Both the less than and greater than conditions should be applied. I believe the correct way to do that with Postgrest is using the query parameter and=(age.lt.30,age.gt.20).

Screenshots

N/A

System information

  • OS: Linux
  • Browser (if applies): N/A
  • Version of postgrest-go: v0.0.11
  • Version of Go: go version go1.23.2 linux/amd64

Additional context

A viable workaround is to manually construct the and filter instead:

	client.
		From("users").
		Select("name, age", "", false).
		And("age.lt.30,age.gt.20", "").
		Execute()

However, I think that the library should construct the and filter automatically. If not, it should at least return an error to let the user know that their query won't work as intended.

Thanks for this useful client library! I can probably submit a PR fixing this if desired.

@jasonccox jasonccox added the bug Something isn't working label Nov 21, 2024
@muratmirgun
Copy link
Member

i am working on it

@muratmirgun muratmirgun self-assigned this Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants