jussi jussi - 5 months ago 8
SQL Question

Search in integer array in Postgres

Is there any other way to search for a certain value in an

integer[]
column in Postgres?

My currently installed Postgres version does not allow the following statement:

SELECT * FROM table WHERE values *= 10;


Array examples:

'{11043,10859,10860,10710,10860,10877,10895,11251}'
'{11311,10698,10697,10710,10712,10711,10708}'


The statement should return every row where the array contains
'10710'
.

Answer

For equality checks you can simply:

SELECT * FROM table WHERE 10 = ANY (values);

Read about ANY/SOME in the manual.