Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ create type realtime.user_defined_filter as (
and `realtime.equality_op`s are a subset of [postgrest ops](https://postgrest.org/en/v4.1/api.html#horizontal-filtering-rows). Specifically:
```sql
create type realtime.equality_op as enum(
'eq', 'neq', 'lt', 'lte', 'gt', 'gte', 'in'
'eq', 'neq', 'lt', 'lte', 'gt', 'gte', 'in',
'like', 'ilike', 'is', 'match', 'imatch', 'isdistinct'
);
```

Expand All @@ -57,6 +58,42 @@ insert into realtime.subscription(subscription_id, entity, filters, claims)
values ('832bd278-dac7-4bef-96be-e21c8a0023c4', 'public.notes', array[('id', 'eq', '6')], '{"role", "authenticated"}');
```

### Extended operators and negation (`filters_v2`)

The operators `like`, `ilike`, `is`, `match` (`~`), `imatch` (`~*`) and `isdistinct`,
along with negation of any operator, are stored on a separate `filters_v2`
column whose composite type carries an extra `negate` boolean:
```sql
create type realtime.user_defined_filter_v2 as (
column_name text,
op realtime.equality_op,
value text,
negate boolean
);
```
This is an expand/contract rollout: the legacy 3-field `filters` column is left
untouched (so older Realtime server instances keep writing to it during a rolling
deploy), and the new operators are only accepted on `filters_v2`. `apply_rls`
evaluates both columns; for any given subscription one of them is always empty.

When `negate` is `true` the operator's result is inverted (e.g. `like` →
`NOT LIKE`, `in` → `NOT IN`). To subscribe to `public.notes` where `body` does
**not** match the pattern `%draft%`:
```sql
insert into realtime.subscription(subscription_id, entity, filters_v2, claims)
values (
'832bd278-dac7-4bef-96be-e21c8a0023c4',
'public.notes',
array[('body', 'like', '%draft%', true)]::realtime.user_defined_filter_v2[],
'{"role": "authenticated"}'
);
```

Operator notes:
- `is` requires a keyword value: `null`, `true`, `false` or `unknown`. `is true`/`false`/`unknown` are only valid on boolean columns; `is null` works on any type.
- `like`/`ilike`/`match`/`imatch` require a text-compatible column type.
- `match`/`imatch` patterns are validated as regular expressions when the subscription is created.

To subscribe to `INSERT`s only on a table named `public.notes` where the `id` is `6` as the `authenticated` role:
```sql
insert into realtime.subscription(subscription_id, entity, filters, claims, action_filter)
Expand Down
2 changes: 1 addition & 1 deletion bin/installcheck
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ REGRESS="${PGXS}/../test/regress/pg_regress"
TESTS=$(ls ${TESTDIR}/sql | sed -e 's/\..*$//' | sort )

# Execute the test fixtures
psql -v ON_ERROR_STOP=1 -f sql/setup.sql -f sql/walrus--0.1.sql -f sql/walrus_migration_0001*.sql -f sql/walrus_migration_0002*.sql -f sql/walrus_migration_0003*.sql -f sql/walrus_migration_0004*.sql -f sql/walrus_migration_0005*.sql -f sql/walrus_migration_0006*.sql -f sql/walrus_migration_0007*.sql -f sql/walrus_migration_0008*.sql -f sql/walrus_migration_0009*.sql -f sql/walrus_migration_0010*.sql -f sql/walrus_migration_0011*.sql -f sql/walrus_migration_0012*.sql -f sql/walrus_migration_0013*.sql -f sql/walrus_migration_0014*.sql -f test/fixtures.sql -d contrib_regression
psql -v ON_ERROR_STOP=1 -f sql/setup.sql -f sql/walrus--0.1.sql -f sql/walrus_migration_0001*.sql -f sql/walrus_migration_0002*.sql -f sql/walrus_migration_0003*.sql -f sql/walrus_migration_0004*.sql -f sql/walrus_migration_0005*.sql -f sql/walrus_migration_0006*.sql -f sql/walrus_migration_0007*.sql -f sql/walrus_migration_0008*.sql -f sql/walrus_migration_0009*.sql -f sql/walrus_migration_0010*.sql -f sql/walrus_migration_0011*.sql -f sql/walrus_migration_0012*.sql -f sql/walrus_migration_0013*.sql -f sql/walrus_migration_0014*.sql -f sql/walrus_migration_0015*.sql -f test/fixtures.sql -d contrib_regression

# Run tests
${REGRESS} --use-existing --dbname=contrib_regression --inputdir=${TESTDIR} ${TESTS}
Loading
Loading