title: Postgres array of custom types - how to query by custom type property
body: <p>I want to use Postgres array to store events per each sender.
  Each event is persisted as a Postgres custom type (object).</p>
  
  <p>How can I query records by custom type properties? Is it possible or not?</p>
  
  <p>If yes, can I put any index type on array column to speed up the queries?</p>
  
  <p>Create custom type:</p>
  
  <pre class="lang-sql prettyprint-override"><code>CREATE TYPE sender_event AS (
    event_timestamp TIMESTAMP(3),
    message TEXT
  );
  </code></pre>
  
  <p>Create table with array of custom types:</p>
  
  <pre class="lang-sql prettyprint-override"><code>CREATE TABLE sender_history (
      sender varchar(30),
      events  sender_event[]
  );
  </code></pre>
  
  <p>Insert few records to the table:</p>
  
  <pre class="lang-sql prettyprint-override"><code>INSERT INTO sender_history VALUES 
  ('sender1', ARRAY[(now(), 'Message text 1')::sender_event]),
  ('sender2', ARRAY[(now(), 'Message text 2')::sender_event])
  </code></pre>
  
  <p>How can I find all records which 'events' array contain object with "message" property equal to 'Message text 2'?</p>
  
  <p>E.g. something like this (this does not work):</p>
  
  <pre class="lang-sql prettyprint-override"><code>SELECT * FROM sender_history
  WHERE events.message = 'Message text 2'
  </code></pre>
  
  <p>Expected result should be the second record in that table.</p>