Skip to content

Query Params Do Not Support Multiple Filters on the Same Key (e.g. created_at=gte...&created_at=lte...) #296

@putheng

Description

@putheng

Description:

I'm encountering an issue where query parameters do not support multiple filters on the same key when using array values. For example, filtering with:

created_at=gte.2025-04-03&created_at=lte.2025-04-05

is a common pattern in PostgREST to filter by a range, but the library currently fails to handle this correctly.


Reproduction Code:

ref.expenseEntities.findAll(params: {
  'created_at': ['gte.2025-04-03', 'lte.2025-04-05']
});

Decoded URL:

created_at=[gte.2025-04-03,+lte.2025-04-05]

Error from PostgREST:

unhandled Exception: DataException: 
{
  code: PGRST100,
  details: unexpected "[" expecting "not" or operator (eq, gt, ...),
  message: "failed to parse filter ([gte.2025-04-03, lte.2025-04-05])"
}

Temporary Workaround:

I resolved this by manually constructing the URI to ensure repeated keys are supported:

final parseUri = Uri.parse(baseUrl);
final uri = parseUri.replace(
  path: '${parseUri.path}/${urlForFindAll(params)}'.replaceAll('//', '/'),
  queryParameters: params,
);
sendRequest<List<T>>(
  uri,
  method: methodForFindAll(params),
  headers: headers,
  label: label,
);

This works for now, but it feels like a workaround rather than a clean solution. Ideally, the library should support multiple filters for the same key in a proper way compatible with PostgREST.


Expected Behavior:

The library should generate query strings with repeated keys when array values are provided in the params, like:

...?created_at=gte.2025-04-03&created_at=lte.2025-04-05

Additional Notes:

Let me know if I’m missing a proper way to handle this use case within the current API. Otherwise, I hope this can be improved in a future release!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions