I have a question about SQLAlchemy.

If I have added a query_property [1] field in my SQLAlchemy Table
class, is it possible to narrow down the SELECTed fields?

Here is what I mean.

Suppose my class Comments has this:

class Comments:
    query = Session.query_property()
    ...

Then if I do the following:

>>> print Session.query(Comment)

Then SQLAlchemy generates the following query which includes ALL the
columns in my comments table:

SELECT comments.comment_id AS comments_comment_id,
       comments.comment    AS comments_comment
       ... more columns ...
FROM comments

But I want to narrow down this query and select only (let's say) the
comment field as in the following construct:

>>> print Session.query(Comment.comment)
SELECT comments.comment AS comments_comment
FROM comments

Is it possible to do this via Comment.query construct?

I tried the following but it didn't work:

>>> print Comment.query(Comment.comment)
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
TypeError: 'Query' object is not callable

Please help me with an advice.

Thanks, Boda Cydo.

[1] 
http://www.sqlalchemy.org/docs/reference/orm/sessions.html#sqlalchemy.orm.scoping.ScopedSession.query_property

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to