title: SQLAlchemy ORDER BY FIELD()
body: <p>I am trying to sort an SQLAlchemy ORM object by a field, but with a specific order of the values (which is neither ascending or descending).  If I was doing this query on MySQL, it would look like;</p>
  
  <pre><code>SELECT letter FROM alphabet_table WHERE letter in ('g','a','c','k')
  ORDER BY FIELDS( letter, 'g','a','c','k');
  </code></pre>
  
  <p>for the output:</p>
  
  <pre><code>letter
  ------
    g
    a
    c
    k
  </code></pre>
  
  <p>For SQLAlchemy, I've been trying things along the lines of:</p>
  
  <p>session.query(AlphabetTable).filter(AlphabetTable.letter.in_(('g','a','c','k'))).order_by(AlphabetTable.letter.in_(('g','a','c','k')))</p>
  
  <p>Which doesn't work... any ideas? It's a small one-time constant list, and I could just create a table with the order and then join, but that seems like a bit too much.</p>