Created
November 17, 2021 17:31
-
-
Save dillonstreator/85672df13cedd00c5cf3066191d32e3a to your computer and use it in GitHub Desktop.
postgres jsonb path query retrieve field in object with field that is array of objects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
id, | |
jsonb_path_query(json_field::jsonb, '$.arrayfield[*] ? (@.fieldid == $fieldid)', '{"fieldid": "field-id-value-to-find"}')->>'fieldvalue' as field_value | |
FROM table | |
WHERE json_field::jsonb->'arrayfield' @> '[{"fieldid": "field-id-value-to-find"}]'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment