Is there an operator in PostgreSQL to test whether an element is in an array?
Currently, I'm doing such tests in a slightly complex way by first constructing a singleton array for the element and then using the <@ operator between arrays.
SELECT ARRAY[1] <@ ARRAY[1,2,3];
( SELECT 1 <@ ARRAY[1,2,3]; does not work).
Is there a more succinct/clear way?
SELECT ARRAY_POSITION(ARRAY[1,2,3], '2')return 2?2<> 2 as far as I know.. – Rafs Apr 05 '23 at 12:08ARRAY[1,2,3]defaults toint[], the untyped (!) literal'2'is coerced to the matching typeint. The value is found at position 2. What would you expect it to return? – Erwin Brandstetter Apr 05 '23 at 12:23null. – Erwin Brandstetter Apr 06 '23 at 14:02