Created
September 18, 2023 16:52
-
-
Save marcomalva/1720b0fec0f24f13a4457914e35c28a9 to your computer and use it in GitHub Desktop.
[psql - search value in array ]Postgres: check if array field contains value? #psql
This file contains 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
-- check if array contains a value or multiple values | |
-- answer copied from https://stackoverflow.com/a/54069718 | |
-- search for single value in array | |
SELECT * FROM mytable WHERE 'Book' = ANY(pub_types); | |
-- search an array that contains multiple values **together** | |
SELECT * FROM mytable WHERE pub_types @> '{"Journal", "Book"}'; | |
--search an array that contains **one of** some values. | |
SELECT * FROM mytable WHERE pub_types && '{"Journal", "Book"}'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment