Re: [sqlalchemy] conditionals inside column_property

2020-12-11 Thread niuji...@gmail.com
extremely helpful, like a beacon for a lost ship:) thanks On Friday, December 11, 2020 at 5:59:50 AM UTC-8 Simon King wrote: > I think this page might explain it: > > > https://docs.sqlalchemy.org/en/13/core/sqlelement.html#column-elements-and-expressions > > The "case" function, like many other

Re: [sqlalchemy] conditionals inside column_property

2020-12-11 Thread Simon King
I think this page might explain it: https://docs.sqlalchemy.org/en/13/core/sqlelement.html#column-elements-and-expressions The "case" function, like many other SQLAlchemy functions, returns an instance of a ClauseElement subclass. This instance is used later when building SQL queries. Columns

Re: [sqlalchemy] conditionals inside column_property

2020-12-11 Thread Jinghui Niu
Thanks. One thing to clarify, I noticed that here you used `case` without using in a context of `select`. Is this considered a shorthand within sqlalchemy? On Fri, Dec 11, 2020 at 2:16 AM Simon King wrote: > You can do it, but you need to use an SQL conditional rather than a > python one. In

Re: [sqlalchemy] conditionals inside column_property

2020-12-11 Thread Simon King
You can do it, but you need to use an SQL conditional rather than a python one. In this case that would probably be a CASE expression: https://docs.sqlalchemy.org/en/13/core/sqlelement.html#sqlalchemy.sql.expression.case I think it would look something like this: from sqlalchemy.sql import case