Skip to content

fix(postgrest): serialize array and object values in eq, neq and match - #2883

Open
victuribdev wants to merge 2 commits into
supabase:masterfrom
victuribdev:fix/postgrest-eq-array-object-values
Open

victuribdev wants to merge 2 commits into
supabase:masterfrom
victuribdev:fix/postgrest-eq-array-object-values

Conversation

@victuribdev

Copy link
Copy Markdown

🔍 Description

What changed?

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].

Closes #2877

📸 Screenshots/Examples

Checked against PostgREST 16.6 with a text[] and a jsonb column:

Call Before After
.eq('tags', ['a', 'b']) malformed array literal row 1
.eq('tags', ['a,b', 'say "hi"']) malformed array literal row 2
.neq('meta', { plan: 'pro' }) invalid input syntax for type json rows 2, 3
.match({ tags: ['a', 'b'], meta: { plan: 'pro' } }) malformed array literal row 1

🔄 Breaking changes

  • This PR contains no breaking changes

Arrays and objects failed before, so nothing that worked changes.

📋 Checklist

  • I have read the Contributing Guidelines
  • My PR title follows the conventional commit format: <type>(<scope>): <description>
  • 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.

@victuribdev
victuribdev requested review from a team as code owners November 19, 2026 16:28
@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Explain Change →

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.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1bb8867d-f073-4adf-beac-4b74ed048a96
Commits

Reviewing files that changed from the base of the PR and between 02d2e8f and d239e8f.

Files selected for processing: 2

  • packages/core/postgrest-js/src/PostgrestFilterBuilder.ts
  • packages/core/postgrest-js/test/filter-value-serialization.test.ts

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
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.

postgrest-js: eq(), neq() and match() accept array and JSON values by type, but send them as a,b and [object Object]

1 participant