Skip to content

feat: Adds new filters to increase Postgrest parity#81

Open
filipecabaco wants to merge 2 commits into
masterfrom
feat/add-filters-real-832
Open

feat: Adds new filters to increase Postgrest parity#81
filipecabaco wants to merge 2 commits into
masterfrom
feat/add-filters-real-832

Conversation

@filipecabaco

Copy link
Copy Markdown
Member

What kind of change does this PR introduce?

Adds like, ilike, is, match, imatch, and isdistinct filter operators to realtime subscriptions, along with a negate flag on user_defined_filter to support NOT variants (e.g. IS NOT, IS NOT DISTINCT FROM).

This increases our parity with Postgrest filters

https://linear.app/supabase/issue/REAL-832/improve-filter-parity-based-on-postgrest

Adds like, ilike, is, match, imatch, and isdistinct filter operators to realtime subscriptions, along with a negate flag on user_defined_filter to support NOT variants (e.g. IS NOT, IS NOT DISTINCT FROM).

This increases our parity with Postgrest filters
language sql
immutable
as $$
select

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we restore the previous NULL handling here? The old implementation treated a NULL comparison result as a failed filter via bool_and(coalesce(check_equality_op(...), false)). This
version can turn unknown comparisons into visible rows because the outer coalesce(..., true) defaults to allow. For example, page_id = 5 should not match a row where page_id is
NULL.

true
)
from
unnest(filters) f

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably "fail closed" when a filtered column is missing from the WAL payload. With the inner join, a filter whose column is absent can produce zero evaluated rows, and the
function can default to visible. For DELETEs without replica identity full, this means a filter on a non-PK column may pass even though we cannot evaluate it. Could we left join filters
to columns and require every filter to have a matching column, e.g. count(col.name) = count(f.column_name)?


alter type realtime.user_defined_filter add attribute negate boolean;

create or replace function realtime.check_equality_op(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This creates a 5-arg overload with negate DEFAULT false, but the existing 4-arg check_equality_op remains. That makes old calls like check_equality_op('eq', 'text', 'aaa', 'aaa')
ambiguous. If the default is intended to preserve compatibility, can we drop the old 4-arg function in this migration after dependents are updated, or otherwise avoid the overload
ambiguity?

} | | |
(1 row)

-- Expect 0 subscriptions: filters do match 5 <> null

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This expected output looks like it accepts a regression. The test comment says the NULL row should match 0 subscriptions for page_id = 5, but the expected output includes the
subscription id. Can we keep this expectation as {} and fix the filter logic instead?

"name": "page_id", +| | |
"type": "int4" +| | |
} +| | |
], +| | |

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This expected output also looks too permissive. In the non-full replica identity case, the WAL payload only has the PK, so the body = 'bbb' filter cannot be evaluated and should not
match. Can we keep the previous expectation where only the PK-based filter matches?

@filipecabaco filipecabaco force-pushed the feat/add-filters-real-832 branch 3 times, most recently from 6e8535b to 3cbb2cb Compare June 2, 2026 16:02
@filipecabaco filipecabaco force-pushed the feat/add-filters-real-832 branch from 3cbb2cb to 6f02022 Compare June 2, 2026 16:40
@filipecabaco filipecabaco requested a review from samrose June 2, 2026 16:44
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.

2 participants