I want to transfer SQL to SQLAlchemy and have the case that I have nested case statements.
The simple case is working:
stmt = sqlalchemy.select([self.tusg_view_specials]).where(
sqlalchemy.case([
(self.tusg_view_specials.c.webo_close_date >= (datetime.date.today() - datetime.timedelta(days=30)), 1),
(self.tusg_view_specials.c.wo_closed_date >= (datetime.date.today() - datetime.timedelta(days=61)), 1)
], else_=0),
)
But when I have a nested case, means that the THEN is a case clause instead of a simple value:
stmt = sqlalchemy.select([self.tusg_view_specials]).where(
sqlalchemy.case([
(self.tusg_view_specials.c.webo_close_date >= (datetime.date.today() - datetime.timedelta(days=30)), 1),
(self.tusg_view_specials.c.wo_closed_date >= (datetime.date.today() - datetime.timedelta(days=61)), 1),
(self.tusg_view_specials.c.work_order_number is None,
sqlalchemy.case([(self.tusg_view_specials.c.flag_is_abw == 1, 1)], else_=0))
], else_=0), <<-- This line is shown to cause the error
)
I get the following error message, I don't know how to deal with it:
sqlalchemy.exc.ArgumentError: Ambiguous literal: False. Use the 'text()' function to indicate a SQL expression literal, or 'literal()' to indicate a bound value.
I can read the text, but don't know how to interpret it. Search results on "nested case" on SQLAlchemy are very little to none.