あなたがマスクにjsonbフィールドの試合で配列の任意の要素かどうかを確認したい場合:
SELECT *
FROM jtable
WHERE EXISTS (
SELECT 1
FROM jsonb_array_elements_text(jfield->'EmailAddresses') AS j
WHERE j ~ 'bob'
)
jfield
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
{"FName": "Bob", "LName": "Marley", "State": null, "Title": null, "DisplayName": "Bob marley", "EmailAddresses": ["[email protected]", "[email protected]"]}
{"FName": "Bob ", "LName": "Martin", "State": null, "Title": null, "DisplayName": "Bob martin", "EmailAddresses": ["[email protected]", "[email protected]"]}
(2 rows)
それとも、マスクに一致する電子メールのリストをしたい場合:
WITH w AS (
SELECT jsonb_array_elements_text(jfield->'EmailAddresses') AS emails,
*
FROM jtable
)
SELECT * FROM w WHERE emails ~ 'bobm'
emails | jfield
---------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------
[email protected] | {"FName": "Bob", "LName": "Marley", "State": null, "Title": null, "DisplayName": "Bob marley", "EmailAddresses": ["[email protected]", "[email protected]"]}
[email protected] | {"FName": "Bob ", "LName": "Martin", "State": null, "Title": null, "DisplayName": "Bob martin", "EmailAddresses": ["[email protected]", "[email protected]"]}
(2 rows)
グレート、ありがとうを – puneet