Sorry, I unintentionally clicked the send button, I was going to
transform the DELETE statement to something generic, here is a more
sensible message:

Hi!

I have tried to figure out how to do a multi-table delete (i.e. where
you refer to other tables than the one  you're deleting from) using
SQLAlchemy, but I have not suceeded.

For this to work, something like this needs to be produced (at least for MySQL):

"""DELETE ps FROM phrase_sentiments as ps, phrases as ph WHERE
ps.phrase_id = ph.phrase_id AND ph.al_id = :al_id """

It would be nice if you could call it like this, andhave the proper
FROM get added automatically:

delete(phrase_sentiments, and_(phrases.c.al_id == al_id,
phrase_sentiments.c.phrase_id == phrases.c.phrase_id))

Where phrases and phrase_sentiments are Table objects with the proper
columns. This statement however, produce this SQL, which produces an
error:

sqlalchemy.exc.OperationalError: (OperationalError) (1054, "Unknown
column 'phrases.al_id' in 'where clause'")
u'DELETE FROM phrase_sentiments WHERE phrases.al_id = %s AND
phrase_sentiments.phrase_id = phrases.phrase_id' [35113563L]

I haven't found a way to add a custom from-clause in any other way either.

-- Joakim

2009/5/29 Joakim Lundborg <[email protected]>:
> HI
>
> I have tried to figure out how to do a multi-table delete using
> SQLAlchemy, but I have not suceeded.I was kinda hoping this
> construction would work:
>
> delete(production_phrase_sentiments, and_(production_phrases.c.al_id
> == al_id, production_phrase_sentiments.c.phrase_id ==
> production_phrases.c.phrase_id))
>
> For this to work, it needs to get translated to something like:
> DELETE review.ps FROM review.alasemantic_phrase_sentiments as ps,
> review.alasemantic_phrases as ph
>                    WHERE ps.phrase_id = ph.phrase_id
>                    AND ph.al_id = :al_id""")
>

--~--~---------~--~----~------------~-------~--~----~
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