I have two tables in PostgreSQL, A & B, for simplicity with exactly the same structure:
{
id varchar2(32) unique,
data jsonb
}
Is it possible to write query, that will return all rows from A, for which particular B.data is “sub-json” of A.data?
Expressed in SQL alike terms:
SELECT A.*
FROM A, B
WHERE B.id = ? AND B.data is sub-json of A.data
json1 is sub-json of json2 means that by removing some key/value pairs from A you can get B. Example:
{
"key1":"value1",
"key3":"value3"
}
is sub-json of
{
"key1":"value1",
"key2":"value2",
"key3":"value3"
}
json-s could have more complex structure.
If it is possible then how performant would it be compared to decomposing these json-s into rows and doing relational table joins?