You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(postgrest): serialize array and object values in eq, neq and match - #2883
eq(), neq() and match() now send arrays as a Postgres array literal ({"a","b"}) and plain objects as JSON. Everything else goes out as before, including class instances like Date or a Decimal, which keep using their own toString.
Why was this change needed?
The types already accept string[] for a text[] column and objects for jsonb, but the value went into the URL through a template string, so Postgres got a,b and [object Object].
I have run pnpm nx format to ensure consistent code formatting
I have added tests for new functionality (if applicable)
I have updated documentation (if applicable)
📝 Additional notes
For a jsonb column an array value goes out as a Postgres array, not JSON, since the client can't see the column type and text[] looked like the common case. Easy to change if you prefer.
#2882 came in a few minutes after my comment. Differences here: elements are escaped the Postgres way (JSON escapes like \n mean something else inside an array literal), objects nested in arrays work, and a Decimal or other class instance isn't turned into JSON.
No actionable comments were generated in the recent review.
Summary
Summary by CodeRabbit
Bug Fixes
Improved filter handling for eq, neq, and match when values include arrays or objects. Array elements are formatted to preserve types and special characters, while non-plain objects retain their string representation.
Tests
Added coverage for filter values including nested and empty arrays, special characters, scalar values, and custom object representations.
The filter builder now formats values passed to eq, neq, and match. Arrays become PostgreSQL array literals, plain objects become JSON, and other values use string conversion. Tests cover query parameters for arrays, objects, scalar values, and class instances.
Assessment against linked issues
Objective
Addressed
Explanation
Serialize array and JSON values in eq, neq, and match as valid filter values [#2877]
✅
Change: Bug fix · Severity of issue fixed: Medium
Merge Risk: Minimal · up to d239e
Array and plain-object values passed to eq, neq and match are now serialized as PostgreSQL array literals and JSON instead of "a,b" or "[object Object]". Other values behave as before. No merge-blocking risk was identified.
- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
This branch has not been deployed
No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔍 Description
What changed?
eq(),neq()andmatch()now send arrays as a Postgres array literal ({"a","b"}) and plain objects as JSON. Everything else goes out as before, including class instances likeDateor aDecimal, which keep using their owntoString.Why was this change needed?
The types already accept
string[]for atext[]column and objects forjsonb, but the value went into the URL through a template string, so Postgres gota,band[object Object].Closes #2877
📸 Screenshots/Examples
Checked against PostgREST 16.6 with a
text[]and ajsonbcolumn:.eq('tags', ['a', 'b']).eq('tags', ['a,b', 'say "hi"']).neq('meta', { plan: 'pro' }).match({ tags: ['a', 'b'], meta: { plan: 'pro' } })🔄 Breaking changes
Arrays and objects failed before, so nothing that worked changes.
📋 Checklist
<type>(<scope>): <description>pnpm nx formatto ensure consistent code formatting📝 Additional notes
For a
jsonbcolumn an array value goes out as a Postgres array, not JSON, since the client can't see the column type andtext[]looked like the common case. Easy to change if you prefer.#2882 came in a few minutes after my comment. Differences here: elements are escaped the Postgres way (JSON escapes like
\nmean something else inside an array literal), objects nested in arrays work, and aDecimalor other class instance isn't turned into JSON.