I am trying to sort an SQLAlchemy ORM object by field, but with a specific order of values ββ(which is neither ascending nor descending). If I were to make this query in MySQL, it would look like this:
SELECT letter FROM alphabet_table WHERE letter in ('g','a','c','k') ORDER BY FIELDS( letter, 'g','a','c','k');
for output:
letter
For SQLAlchemy, I tried things line by line:
session.query (AlphabetTable) .filter (AlphabetTable.letter.in _ (('g', 'a', 'c', 'k'))). Order_by (AlphabetTable.letter.in _ (('g', 'a', 'c', 'k')))
What doesn't work ... any ideas? This is a small one-time list of constants, and I could just create a table with order and then join, but that seems too big.
source share