1

im using postgresql 11.2 on a docker container and im trying to get data on this column that containes arrays "event_type" :

   event_type
-----------------
 {ERROR}
 {INFO}
 {ERROR,VERBOSE}
 {ERROR,VERBOSE}
 {INFO,NOTIFY}

event_type column schema :

event_type | text[]

Selecting all rows which contained 'ERROR': (works fine)

 SELECT event_type FROM events WHERE event_type @> ARRAY['ERROR'];
   event_type
-----------------
 {ERROR}
 {ERROR,VERBOSE}
 {ERROR,VERBOSE}
(3 rows)

If i want to get all rows which contained 'ERROR' AND \ OR ' NOTIFY' :

 SELECT event_type FROM events WHERE event_type @> ARRAY['ERROR', 'NOTIFY'];
 event_type
------------
(0 rows)

The desired response would be :

   event_type
-----------------
 {ERROR}
 {ERROR,VERBOSE}
 {ERROR,VERBOSE}
 {INFO,NOTIFY}

1 Answer 1

3

You can use overlap operator &&

SELECT event_type FROM events WHERE event_type && ARRAY['ERROR', 'NOTIFY'];

https://www.postgresql.org/docs/current/functions-array.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.