Hello.
There is an example (found in 
http://discorporate.us/jek/talks/pgwest08-sqlalchemy.pdf)

>>> sql = r'''
... SELECT *
... FROM ticket JOIN ticket_change
... ON (ticket.id = ticket_change.ticket)
... WHERE summary ~ '[[:digit:]]+'
... ORDER BY ticket.time desc
... LIMIT 1
... '''
>>> session.query(Ticket, Change).from_statement(sql).first()
Traceback (most recent call last):
...
InvalidRequestError: Ambiguous column name 'time'
in result set! try 'use_labels' option on select statement.

And as its solution provides the following example:

>>> q3 = session.query(Ticket, Change) \
.select_from(tickets.join(ticket_changes)) \
.filter(Ticket.id==1) \
.order_by(desc(Change.time))
>>> print q3
SELECT ticket.id AS ticket_id, ...
ticket_change.ticket AS ticket_change_ticket, ...
FROM ticket JOIN ticket_change
ON ticket.id = ticket_change.ticket
WHERE ticket.id = %(id_1)s
ORDER BY ticket_change.time DESC
>>> q3.first()
(Ticket(1, 'document arguments for table, column, ...'),
Change(1, 1149120761, 'status', 'closed'))

So can we all still use from_statement for raw queries where there are
joining exists.
Maybe there are some ways to add some labels in query ?

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

Reply via email to