On 02/01/2016 11:18 AM, Rick Otten wrote:

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:

|
fromsqlalchemy.orm importaliased

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.idfrom *some_table, some_table as t* where t.some_column =
    /someValue/

well that's not a DELETE statement. query.delete() emits a DELETE statement and you'd have to look in the SQL logs to see it.

There's no "bug" here as DELETE does not support deleting directly from an alias of a table; it's likely emitting DELETE .. FROM and assuming you want to do some kind of join against the aliased form of your table.

Otherwise what SQL are you looking for this to produce that has DELETE but also an aliased form of the table?






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
<mailto:sqlalchemy+unsubscr...@googlegroups.com>.
To post to this group, send email to sqlalchemy@googlegroups.com
<mailto:sqlalchemy@googlegroups.com>.
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 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