title: PostgreSQL JOIN with array type with array elements order, how to implement?
body: <p>I have two tables in database:</p>
  
  <pre><code>CREATE TABLE items(
   id SERIAL PRIMARY KEY,
   ... some other fields
  );
  </code></pre>
  
  <p>This table contains come data row with unique ID.</p>
  
  <pre><code>CREATE TABLE some_chosen_data_in_order(
   id SERIAL PRIMARY KEY,
   id_items INTEGER[],
  );
  </code></pre>
  
  <p>This table contains array type field. Each row contains values of IDs from table <code>items</code> in specific order. For example: <code>{2,4,233,5}</code>.</p>
  
  <p>Now, I want to get data from table <code>items</code> for chosen row from table <code>some_chosen_data_in_order</code> with order for elements in array type.</p>
  
  <p>My attempt was JOIN:</p>
  
  <pre><code>SELECT I.* FROM items AS I 
  JOIN some_chosen_data_in_order AS S ON I.id = ANY(S.id_items) WHERE S.id = ?
  </code></pre>
  
  <p>Second attempt was subquery like:</p>
  
  <pre><code>SELECT I.* FROM items AS I 
  WHERE I.id = ANY 
  (ARRAY[SELECT S.id_items FROM some_chosen_data_in_order  WHERE id = ?])
  </code></pre>
  
  <p>But none of them keep IDs in the same order as in array field. Could you help me, how to get data from <code>items</code> table with correspond with array IDs order from <code>some_chosen_data_in_order</code> table for specific row?</p>