Skip to content
Advertisement

(Postgresql) How to get all match from array of integer

I want all row matching with group_id pass as input

ex.

Here is my table:-

id |      name      | group_id 
----+----------------+----------
  1 | Alice John     | {1,2,3}
  2 | joshn shukla   | {1,4}
  3 | rishikesh jain | {2,8}

when I execute below query:-

select * from employee where group_id::TEXT ~ '[{,]2,8[,}]'

then it returns result become

 id |      name      | group_id 
----+----------------+----------
  3 | rishikesh jain | {2,8}

expected result all match:-

 id |      name      | group_id 
----+----------------+----------
  1 | Alice John     | {1,2,3}
  3 | rishikesh jain | {2,8}

because 2 present in both rows. any solution ?

Advertisement

Answer

Try:

select * from employee  where  (group_id  && '{2,8}');
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement