I want to execute the following MySQL query:

  SELECT group_concat(DISTINCT lower(`role`.`name`) ORDER BY 
lower(`role`.`name`) SEPARATOR '|')
    FROM ...
GROUP BY ...

Using the latest stable release of SQLAlchemy (1.3.20), I've written the 
following code:

class Role(Base):
  __tablename__ = 'role'

  id = Column(BigInteger, primary_key=True)
  _created = Column(DateTime, nullable=False, server_default=text('
CURRENT_TIMESTAMP'))
  _updated = Column(DateTime)
  _deleted = Column(Boolean, nullable=False, server_default=text("'0'"))
  name = Column(String(200), nullable=False)
  description = Column(String(1000))

result = Session.query()\
.add_columns(func.group_concat(func.lower(Role.name).distinct()
.op('ORDER BY')(func.lower(Role.name).asc())
.op('SEPARATOR')(literal_column("'|'")))) \
...

When executed, this emits an extra pair of parentheses in the statement 
which results in a SQL error:

SELECT group_concat((DISTINCT lower(`role`.name) ORDER BY 
lower(`role`.name) ASC) SEPARATOR '|') AS group_concat_1

How can I construct my SQLAlchemy query so it does not include the extra 
parantheses?

Thanks in advance!

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/f92b7a04-d5d6-46e6-8fad-0420f6f840b4n%40googlegroups.com.

Reply via email to