Skip to content

fix: use query.Add for same column filters instead of and operator#84

Open
zugdev wants to merge 1 commit intosupabase-community:mainfrom
zugdev:fix/same-column-filters
Open

fix: use query.Add for same column filters instead of and operator#84
zugdev wants to merge 1 commit intosupabase-community:mainfrom
zugdev:fix/same-column-filters

Conversation

@zugdev
Copy link
Copy Markdown

@zugdev zugdev commented Mar 30, 2026

What kind of change does this PR introduce?

Bug fix. Resolves #53, #58, supabase-community/supabase-go#13

What is the current behavior?

Chaining multiple filters on the same column (i.e. .Gte("age", "18").Lte("age", "65")) produces incorrect query parameters. The appendFilter() function manually constructs a PostgREST and expression, which has bugs: column name prefix collisions, fragile TrimSuffix(")") for nested expressions, and percent encoded parentheses from url.Values.Encode().

This was originally a valid workaround when filters were stored in a map[string]string, which can only hold one value per key. After the refactor to url.Values, query.Add() became available but no one updated appendFilter() to use it.

What is the new behavior?

Use query.Add(column, filterValue) in appendFilter() body. PostgREST natively supports duplicate query parameters for the same column and implicitly ANDs them, this is how postgrest-js works with URLSearchParams.append() for instance.

Query output changes from ?and=(age.gte.18,age.lte.65) to ?age=gte.18&age=lte.65, but both produce identical SQL at PostgREST.

Tests updated to expect url.Values with multiple values per key instead of a single and parameter.

Replace the 25-line appendFilter() implementation that manually
constructed PostgREST "and" expressions with a single query.Add() call.
PostgREST natively supports duplicate query parameters for the same
column and implicitly ANDs them, which is how postgrest-js works
(URLSearchParams.append).

The previous implementation had bugs: column name prefix collisions,
fragile parenthesis string manipulation, and URL encoding issues with
the and operator.

Update tests to expect duplicate query params (url.Values with slices)
instead of a single "and" parameter.

Fixes supabase-community#53
Fixes supabase-community#58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Filter conditions on the same column overwrite each other

1 participant