Skip to content

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

@jasonccox

Description

@jasonccox

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.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions