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] Association table very slow

2020-12-11 Thread Mike Bayer
hey there - that query is not a cartesian product. the child and child_parent tables are linked together in the WHERE clause. I would assume the query here is in fact taking about half a second to run, the problem here is in the composition of Python objects for every row. I am assuming

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

[sqlalchemy] Association table very slow

2020-12-11 Thread marnix....@gmail.com
Dear sqlalchemy users, After look at the docs I arrived at the following structure: ``` Base = declarative_base() parent_child = Table( "parent_child", Base.metadata, Column("parent_id", Integer, ForeignKey("parent.id")), Column("child_id", Integer, ForeignKey("child.id")), ) class

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

[sqlalchemy] conditionals inside column_property

2020-12-11 Thread niuji...@gmail.com
I have a mapped class: class Model(sqlalchemy.declarative_base()): attr_a = Column(String) attr_b = Column(Integer) attr_c = Column(Integer) aggr = column_property(attr_b + attr_c IF attr_a=='go' ELSE attr_b - attr_c) Last line is pseoudo code that requires some conditional