On Wed, Jul 11, 2018 at 12:12 AM, kimtaeyang <[email protected]> wrote: > I will use with_entities function... > > I define the User.memberType with enum Class. > So if use with_entities(User.name, User.age, User.memberType, ...), then > result is 'name', 33, <MemberType.Admin: 1> > > and i define the __str__ in MemberType Class like that: > def __str__(self): > if self.value == 1: return "admin" > return "others" > > and i want get the result like ("name", 33, "admin") > > of course that it can solve with for loop.. but i want to know other ways..
you can use a SQL case statement: with_entities(case([(User.memberType == "1": "admin")], else_="others")) http://docs.sqlalchemy.org/en/latest/core/sqlelement.html?highlight=case#sqlalchemy.sql.expression.case > > > -- > SQLAlchemy - > The Python SQL Toolkit and Object Relational Mapper > > http://www.sqlalchemy.org/ > > To post example code, please provide an MCVE: Minimal, Complete, and > Verifiable Example. See http://stackoverflow.com/help/mcve for a full > description. > --- > 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 [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/sqlalchemy. > For more options, visit https://groups.google.com/d/optout. -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
