title: How do I write a where statement a composite type?
body: <p>Lets say I create a type such as</p>
  
  <pre><code>CREATE TYPE testpair AS (key int, value int);
  </code></pre>
  
  <p>and put it in a table</p>
  
  <pre><code>create table test(id SERIAL PRIMARY KEY, a testpair[]);
  </code></pre>
  
  <p>with these test values</p>
  
  <pre><code>insert into test(a) values (ARRAY[(1,2)::testpair]), (ARRAY[(5,9)::testpair]), (ARRAY[(4,16)::testpair]), (ARRAY[(9, 1)::testpair]);
  </code></pre>
  
  <p>I will get a result if I write this</p>
  
  <pre><code>select * from test where (4,16)::testpair = ANY(a);
  </code></pre>
  
  <p>How do I write my query if I want to know if any of these pairs start with 4 or for all pairs that are <code>&gt;= 9</code>? I know I can write <code>select ((5,8)::testpair).key;</code> to get 5 but the following is wrong</p>
  
  <pre><code>select * from test where 5  = ANY((a).key);
  </code></pre>
  
  <p>The error given is </p>
  
  <pre><code>ERROR:  column notation .key applied to type testpair[], which is not a composite type
  </code></pre>
  
  <p>which makes sense since <code>a</code> is an array. But I have no idea how to write the query to use any 'key'</p>