Skip to content

feat: add filters to pg_changes#1922

Open
filipecabaco wants to merge 5 commits into
mainfrom
feat/pg-changes-added-filters-real-832
Open

feat: add filters to pg_changes#1922
filipecabaco wants to merge 5 commits into
mainfrom
feat/pg-changes-added-filters-real-832

Conversation

@filipecabaco
Copy link
Copy Markdown
Member

What kind of change does this PR introduce?

add filters to pg_changes:

Operator SQL Description
like LIKE Column matches pattern (case-sensitive).
ilike ILIKE Column matches pattern (case-insensitive).
not_like NOT LIKE Column does not match pattern (case-sensitive).
not_ilike NOT ILIKE Column does not match pattern (case-insensitive).
is IS null, true, false, unknown
not_is IS NOT null, true, false, unknown

@filipecabaco filipecabaco changed the title Feat/pg changes added filters real 832 feat: add filters to pg_changes May 28, 2026
@coveralls
Copy link
Copy Markdown

Coverage Status

coverage: 91.461% (-0.2%) from 91.62% — feat/pg-changes-added-filters-real-832 into main

Comment on lines +158 to +165
{:error, %Postgrex.Error{postgres: %{code: :raise_exception, message: msg}}} ->
log_error("SubscriptionFatalError", msg)

for {pid, _id, _ref, _node} <- :ets.tab2list(subscribers_pids_table) do
send(pid, {:subscription_fatal_error, msg})
end

{:noreply, state}
Copy link
Copy Markdown
Member

@edgurgel edgurgel May 28, 2026

Choose a reason for hiding this comment

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

Could you explain why we need this? Is it related to filters?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

handling unknown filters to prevent the user from connecting

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So SubscriptionFatalError is missing in ERROR_CODES.md :)

Copy link
Copy Markdown
Contributor

@leandrocp leandrocp left a comment

Choose a reason for hiding this comment

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

Just minor things, but interesting features!

To resolve the conflict on tenant_db_baseline.json just commit whatever and CI will regenerate it.

Comment thread FEATURES.md
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It would be interesting to add a topic in README linking to this doc, useful for humans and helps AI to discover it too.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

will create a sort of index in README

Comment thread FEATURES.md

| Key | Type | Description |
|-----|------|-------------|
| `key` | string | Custom key to identify this client's presence entry. Defaults to a generated UUID. |
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since v4 is more popular it might be worth noting it generates v1

Suggested change
| `key` | string | Custom key to identify this client's presence entry. Defaults to a generated UUID. |
| `key` | string | Custom key to identify this client's presence entry. Defaults to a generated UUID v1. |

Comment thread FEATURES.md
- Runs `realtime.is_visible_through_filters()` to match the row against each subscription's filters.
5. Matching subscription IDs are returned alongside the change and dispatched to the appropriate clients.

### Subscription parameters
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should add select too?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

wasn't there yet but will do

Comment thread FEATURES.md Outdated
Comment thread FEATURES.md
| `like` | `LIKE` | Column matches pattern (case-sensitive). |
| `ilike` | `ILIKE` | Column matches pattern (case-insensitive). |
| `not_like` | `NOT LIKE` | Column does not match pattern (case-sensitive). |
| `not_ilike` | `NOT ILIKE` | Column does not match pattern (case-insensitive). |
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this documenting realtime.equality_op or the public filter operators? I was expecting to see not.{...} in this doc 🤔

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

not is a weird one as can only "not" on certain ops...

begin
-- IS / IS NOT require keyword RHS, not a typed literal
if op = 'is' or op = 'not_is' then
if val_2 not in ('null', 'true', 'false', 'unknown') then
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Two comments here:

  1. PostgREST supports not_null as valid value for IN operator as well, I think we could easily support that one too.

  2. Value in PostgREST is case-insensitive (null, NULL, etc). Should we adhere to the same behaviour?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yes we should will take that into account

filipecabaco and others added 2 commits May 29, 2026 18:08
Co-authored-by: Leandro Pereira <leandro@leandro.io>
…like_is_not_ops_to_filters.ex

Co-authored-by: Leandro Pereira <leandro@leandro.io>
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.

4 participants