Here's the case you've outlined, show me exactly what you're doing:
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class A(Base):
__tablename__ = 'a'
id = Column(Integer, primary_key=True)
foo = Column(String)
s = Session()
q1 = s.query(func.array_agg(A.foo))
q2 = q1.with_entities(func.group_concat(A.foo))
print q1
print q2
output:
SELECT array_agg(a.foo) AS array_agg_1
FROM a
SELECT group_concat(a.foo) AS group_concat_1
FROM a
On 05/02/2016 04:07 AM, Антонио Антуан wrote:
Hm, now it is ok, but previously, during another task, I checked the
method and it returned the result with subquery, like this:
|
SELECT a.c FROM (SELECT t.c FROM t)asa
|
Why did I get the result with subquery? Does it depend on something
specific?
суббота, 30 апреля 2016 г., 16:05:12 UTC+3 пользователь Mike Bayer написал:
yes please use query.with_entities
http://docs.sqlalchemy.org/en/rel_1_0/orm/query.html?highlight=query.with_entities#sqlalchemy.orm.query.Query.with_entities
<http://docs.sqlalchemy.org/en/rel_1_0/orm/query.html?highlight=query.with_entities#sqlalchemy.orm.query.Query.with_entities>
On 04/30/2016 02:33 AM, Антонио Антуан wrote:
>
> I have the query:
> |
> q =Session.query(func.array_agg(Order.col))
> |
>
> The compiled query will be:
> |
> SELECT array_agg(order.col)FROM orders
> |
>
> I want dynamically replace the existing column. After replacing
query
> have to be:
> |
> SELECT group_concat(orders.col)FROM orders
> |
>
> I have to use Session and model. I don't have to use SQLAlchemy
core. I
> don't have to use subqueries. And, of course, there can be some
other
> columns, but I need to replace only one. I tried to replace
objects in
> `column_descriptions` property, I tried to use
`q.selectable.replace`(or
> something like this, sorry, but I don't remember right names) and I
> didn't get right result.
>
> Can I do what I want?
>
> --
> 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] <javascript:>
> <mailto:[email protected] <javascript:>>.
> To post to this group, send email to [email protected]
<javascript:>
> <mailto:[email protected] <javascript:>>.
> Visit this group at https://groups.google.com/group/sqlalchemy
<https://groups.google.com/group/sqlalchemy>.
> For more options, visit https://groups.google.com/d/optout
<https://groups.google.com/d/optout>.
--
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]
<mailto:[email protected]>.
To post to this group, send email to [email protected]
<mailto:[email protected]>.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
--
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.