Re: How can I select rows by comparing an array data type column with multiple values ? - Mailing list pgsql-general

From Steve Crawford
Subject Re: How can I select rows by comparing an array data type column with multiple values ?
Date
Msg-id 538C98FB.2070306@pinpointresearch.com
Whole thread Raw
In response to How can I select rows by comparing an array data type column with multiple values ?  (Arup Rakshit <aruprakshit@rocketmail.com>)
Responses Re: How can I select rows by comparing an array data type column with multiple values ?
List pgsql-general
On 06/02/2014 03:54 AM, Arup Rakshit wrote:
Hi,

Suppose, I have a table as below :-

id |    title     |    content     |       tags
----+--------------+----------------+-------------------
  1 | sample post  | lorem ipsum    | {apple,orange}
  2 | another post | fruits are bad | {apple,hamburger}
  3 | third post   | foo bar            | { banana, lemon }
  4 | third post   | foo baz           | { watermelon, lemon }

Now I want to select all rows, for which tags will having either one or all value from the this array [apple,banana] ? how should I write the query using such a set ?

output should select 1,2,3.
 
Regards,
Arup Rakshit

Perhaps the && (overlaps) operator will work best for you. Check out the available operators at:
http://www.postgresql.org/docs/current/static/functions-array.html

Cheers,
Steve

pgsql-general by date:

Previous
From: Raymond O'Donnell
Date:
Subject: Re: How can I select rows by comparing an array data type column with multiple values ?
Next
From: Arup Rakshit
Date:
Subject: Re: How can I select rows by comparing an array data type column with multiple values ?