0

I have column array[] named tags.

i have here f.e.:

{{dogs, cats, phones, bottles}}
{{pistols,politican,juices}}
{{dogs,pistols}}
etc..

I want to find in all of them f.e. word "dogs" and select only entries with "dogs". I tried to use:

SELECT * FROM question WHERE tags[0] = ANY(ARRAY['dogs']);
3
  • this answer not working for me. Commented Sep 11, 2018 at 12:44
  • Given your sample data, what exactly is the result you want? Commented Sep 11, 2018 at 12:47
  • Have you tried "reversing" the ANY like 'dogs' = ANY (tags[0])? Commented Sep 11, 2018 at 12:47

1 Answer 1

4

You need to do it the other way round:

SELECT * 
FROM question 
WHERE 'dogs' = ANY(tags);

The above assumes that tags is a one-dimensional array, e.g. text[]

Sign up to request clarification or add additional context in comments.

1 Comment

I love you. In my angry i lost easiest result. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.