0

In the following example the column parents is an array of int (parents INT[]).

If I want to select all rows in which the array of parents contains 42, I can run this query:

SELECT * FROM records WHERE 42 = ANY (parents);

Now I want to do the opposite and select each row in which parents does not contain 42.

I tried this:

SELECT * FROM records WHERE 42 != ANY (parents);

without luck... Does anyone know how this can be done?

I'm using Postgresql 10.3.

Rotareti
  • 41,172
  • 18
  • 102
  • 102

2 Answers2

1
SELECT * FROM records WHERE NOT (42 = ANY (parents))

Demo

http://sqlfiddle.com/#!17/394c0/1

Jay Shankar Gupta
  • 5,777
  • 1
  • 8
  • 26
0

check example. Reference -> Refrence link

SELECT value_variable = ANY ('{1,2,3}'::int[])
M Danish
  • 480
  • 2
  • 5