contains()

Only relevant for jsonb, array, and range columns. Match only rows where column contains every element appearing in value.

1const { data, error } = await supabase
2  .from('users')
3  .select()
4  .contains('name', ['is:online', 'faction:red'])

Parameters#

  • columnrequired
    ColumnName

    The jsonb, array, or range column to filter on

  • valuerequired
    string
    |
    Record
    |
    array

    The jsonb, array, or range value to filter with

      Properties
    • object
      required
      object

      No description provided.

    • stringrequired
      object

      No description provided.

    • Recordrequired
      object

      No description provided.

Examples#

On array columns#

1create table
2  issues (
3    id int8 primary key,
4    title text,
5    tags text[]
6  );
7
8insert into
9  issues (id, title, tags)
10values
11  (1, 'Cache invalidation is not working', array['is:open', 'severity:high', 'priority:low']),
12  (2, 'Use better names', array['is:open', 'severity:low', 'priority:medium']);

On range columns#

Postgres supports a number of range types. You can filter on range columns using the string representation of range values.

1create table
2  reservations (
3    id int8 primary key,
4    room_name text,
5    during tsrange
6  );
7
8insert into
9  reservations (id, room_name, during)
10values
11  (1, 'Emerald', '[2000-01-01 13:00, 2000-01-01 15:00)'),
12  (2, 'Topaz', '[2000-01-02 09:00, 2000-01-02 10:00)');

On jsonb columns#

1create table
2  users (
3    id int8 primary key,
4    name text,
5    address jsonb
6  );
7
8insert into
9  users (id, name, address)
10values
11  (1, 'Michael', '{ "postcode": 90210, "street": "Melrose Place" }'),
12  (2, 'Jane', '{}');