From: | Raymond O'Donnell <rod(at)iol(dot)ie> |
---|---|
To: | Arup Rakshit <aruprakshit(at)rocketmail(dot)com>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: How can I select rows by comparing an array data type column with multiple values ? |
Date: | 2014-06-02 11:21:31 |
Message-ID: | 538C5E3B.3060109@iol.ie |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 02/06/2014 11:54, 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 ?
You can use the array "overlap" operator, something like this:
SELECT .... WHERE tags && ARRAY['apple', 'banana'];
See here:
http://www.postgresql.org/docs/9.3/static/functions-array.html
Ray.
--
Raymond O'Donnell :: Galway :: Ireland
rod(at)iol(dot)ie
From | Date | Subject | |
---|---|---|---|
Next Message | Steve Crawford | 2014-06-02 15:32:11 | Re: How can I select rows by comparing an array data type column with multiple values ? |
Previous Message | Arup Rakshit | 2014-06-02 10:54:58 | How can I select rows by comparing an array data type column with multiple values ? |