JSONB 搜索值是否存在:来自另一个 table

JSONB search if values exist: from another table

我有 2 个 table:

在 info.parts 中,我有一个映射到 info.complete table 的 uuid 列,它包含在一个 JSONB 列中。所以

info.part

part.uuid                           |id      |INFO    | 
------------------------------------|--------|--------|
5189b83e-6b00-4f53-b912-9df79d0a45c4|58241750|xxxxxxxx|
a5397fdc-9345-4c43-a9f0-7856a11725df|58165291|xxxxxxxx|
3065bebe-427f-4bcd-bb55-ed4efd0b3134|58162690|xxxxxxxx|
c9d52360-85b0-4d1b-b5ed-63d54f0b966c|58156063|xxxxxxxx|
bd49eaa1-5f25-4603-adab-06633a807f7c|58129750|xxxxxxxx|
d0c58fa9-24fc-4bc9-9735-688a347b6727|58129571|xxxxxxxx|
3fcd06c4-ded5-4f68-b960-caab9c292c61|58125347|xxxxxxxx|
c557f54e-cdd7-447f-9a3c-e6a5b7143689|58120561|xxxxxxxx|

info.complete

complete.uuid                       |id      |part.uuids                                                                                                              
------------------------------------|--------|------------------------------------------------------------------------------------------------------------------------
242c5458-9cf3-4fb4-be67-643a735522df|69745210|["833c0581-89b3-4f1c-98ea-7717b16e47ff", "15edabee-4092-4b1f-9d67-aeb2c53bd617", "7b170aba-b6de-4801-8360-342c702fe65a"] 
a02f1f6b-c9c1-43a6-963c-7e11021e47f5|69745260|["c90201f0-abe0-4285-9778-e6b0c77f7895", "17a5bd4b-bb21-4bdc-a13c-20c2bff950e1"] 
87091e3d-c634-48c0-b6a2-6a3ce5e2c2ee|69745267|["a18f5cda-fa5e-45c8-907a-3b9a2531047c", "138f51e8-5bce-4c16-a565-39e1ca00fbc1", "1a8c6a14-240c-45fb-9acf-db0dc4b4b34e"] 

我如何 运行 查询来检查 info.part 中的 uuid 是否存在于 info.complete 中的任何 uuids::JSONB 列中?

您可以使用 EXISTS 条件:

select ip.*
from info.part ip
where exists (select * 
              from info.complete ic
              where ic.uuids ? ip.uuid::text);