On Thu, Feb 25, 2016 at 1:19 PM, sector119 <sector...@gmail.com> wrote:
> Hello, > > Can some one help me with that query? I get AttributeError: servings > I expect that sqlalchemy use update from select for that query or it's not > possible and I must use select(...).as_scalar() for every updated column? > > s = > select([func.coalesce(func.avg(product_flavor_t.c.size).label('servings'), > 0), > func.count().label('flavors_count')]).\ > where(and_(product_flavor_t.c.product_id == product_t.c.id, > product_flavor_t.c.quantity > 0)) > > op.execute(product_t.update().values(servings=s.c.servings, > flavors_count=s.c.flavors_count)) > > Your select statement looks something like this: SELECT coalesce(avg(product_flavor.size) as servings), 0), count(*) as flavors_count FROM product_flavor Notice that neither of the columns selected are labelled "servings", so when you try to access "s.c.servings" later, you get an AttributeError. Try moving the ".label('servings')" so that it applies to the result of coalesce(), not avg(). Simon -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.