0

How to covert given SQL Case expression with an alias to SQL Alchemy ORM

SELECT `id` AS `emailId`, `email`, `type`,
CASE WHEN `type` = 'Home' THEN 1
WHEN `type` = 'Work' THEN 2
ELSE 4 END `s_order`
FROM `emails`
WHERE `id` = '1121212'
ORDER BY `s_order` ASC'

I know case can be used like this

from sqlalchemy import case

stmt = select([users_table]).\
            where(
                case(
                    [
                        (users_table.c.name == 'wendy', 'W'),
                        (users_table.c.name == 'jack', 'J')
                    ],
                    else_='E'
                )
            )

but how do I include s_order ??

Ilja Everilä
  • 50,538
  • 7
  • 126
  • 127
Vaibhav Jain
  • 5,287
  • 10
  • 54
  • 114

0 Answers0