I have two tables:
create table device_group_v2
(
id uuid not null primary key,
name varchar(255),
filter jsonb
);
with one entry:
+--------------------------------------+------------+-------------------------------------+
| id | name | filter |
+--------------------------------------+------------+-------------------------------------+
| 92f9ac68-7baa-4322-8eb1-e6b9e83dd2ef | Devices-UK | [{"key": "country", "value": "uk"}] |
+--------------------------------------+------------+-------------------------------------+
and
create table device_entity
(
id uuid not null primary key,
name varchar(255),
metadata jsonb
);
With one entry:
+--------------------------------------+---------------------+-------------------+
| id | name | metadata |
+--------------------------------------+---------------------+-------------------+
| 75cf91d0-01b7-42e0-9791-86def0dc4b7b | Device 7 - Metadata | {"country": "uk"} |
+--------------------------------------+---------------------+-------------------+
Is it possible to join both tables, so I get all devices having key/value as defined in the filter in TestGroup?
In the given example it's this query, but I need to fill 'country' and 'uk' dynamically from the "filter" column in the device_group_v2 table.
SELECT * from device_entity where (metadata ->> 'country') = 'uk';
If there are multiple key-value entries, all should be combined with an OR. I need to fetch any of these elements that match the given filters.