When I used "aliased" with query.delete(), the fetch query seems to get 
confused. 


   - I'm using SQLAlchemy 1.0.11, which 'pip' tells me is the latest 
   version.
   - My backend database is PostgreSQL 9.5
   

Code snippet:

from sqlalchemy.orm import aliased

myTable = aliased(some_table, name='t')

purgeQuery = dbSession.query(myTable).filter(myTable.some_column == 
someValue)

queryString = str(purgeQuery.statement.compile(compile_kwargs={
"literal_binds": True}))

purgeQuery.delete(synchronize_session='fetch')




*queryString* shows the expected query.  Something like:

select t.id, t.some_column, t.some_other_column from some_table as *t* where
>  t.some_column = 
> *someValue*



However, when the fetch query actually runs, it includes the non aliased 
table name as well as the aliased table name in the from statement:

select t.id from *some_table, some_table as t* where t.some_column = 
> *someValue*



This was a surprise to notice in the database logs.  This query seems to 
get stuck on my database anyway, actually.

For now, I'll work around it by not aliasing my table name when I use a 
query.delete().  I thought I'd mention it in case I'm doing something wrong 
by using aliased() this way, or in case it was a bug ...

Thanks in advance for your attention to this matter!


-- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to