28

There is an array[10,20] and I want to know if it is a subset of array[20,30,10] or not. Is there a postgresql function or operation to determine if one array contains another?

Desired outcomes:

[10,20] and [30,20,10] - true
[10,20] and [10,30]    - false
[10,20] and [20,10]    - true
[10,20] and [10,20]    - true
5
  • 'An array in PostgreSQL'?? Is this part of some code block? If not, what data structures are we talking about? Commented Feb 28, 2014 at 10:50
  • 2
    @JanDoggen Arrays exist in PostgreSQL at least since version 7, first released in 2001. So I didn't get your question, or the reason why this question was closed. Commented Mar 4, 2021 at 19:42
  • @Rodrigo The reason why this question was closed is clearly written in the blue box at the top Commented Mar 4, 2021 at 19:54
  • 4
    @JanDoggen Yes, I've seen it and disagree. Many questions don't show half of this, and they're still open, and sometimes with hundreds, if not thousands, of upvotes. If one understands what arrays are, the question is perfectly clear. And I also didn't understand your question. "What data structures?" Arrays, of course! Commented Mar 4, 2021 at 20:14
  • 1
    @JanDoggen I also do not understand why this was closed. Could you explain further? Your response "The reason why this question was closed is clearly written in the blue box at the top" is very unhelpful and not descriptive to people less experienced on the site. This question and the accepted answer below was extremely helpful to me and I assume the 7k other viewers this question has had since 2014. Please reconsider reopening the question for new updated answers in the future. Please explain why you think it is off topic and should remain closed if you disagree. Commented Oct 6, 2021 at 18:10

1 Answer 1

45

Like this,perhaps:

SELECT ARRAY[10,20]  <@ ARRAY[30,20,10];

http://www.postgresql.org/docs/current/static/functions-array.html

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

2 Comments

Worked like charm.
postgresql.org/docs/current/functions-array.html explains other ones too but <@ was exactly what I needed!

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.