I am trying to write a query to check if an element is within an array of Strings.
Here is my simple select query along with the output
select languages from person limit 3;
{CSS,HTML,Java,JavaScript,Python}
{JavaScript,Python,TensorFlow}
{C++,Python}
How do I write a query to find all people who have "Java" as a listed language they know?
I tried following the syntax but it isn't working.
select languages from person where languages @> ARRAY['Java']::varchar[];
You need to use a string constant on the left side, and the ANY operator on the array column:
select languages
from person
where 'Java' = any(languages);
This assumes languages is defined as text[] or varchar[] as your sample output indicates
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With