Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>SQLAlchemy currently supports UPDATE..FROM across Postgresql, MySQL and others, but we haven't as of yet tried to support DELETE..JOIN.</p> <p>However, it does appear to work (almost?), as far as generating the SQL string:</p> <pre><code>class Path(Base): __tablename__ = "path" id = Column(Integer, primary_key=True) descendant = Column(Integer) ancestor = Column(Integer) j = join(Path, p1, p1.ancestor == 5) d = delete(j).where(Path.descendant == p1.descendant) print d </code></pre> <p>prints:</p> <pre><code>DELETE FROM path JOIN path AS p1 ON p1.ancestor = :ancestor_1 WHERE path.descendant = p1.descendant </code></pre> <p>However, my MySQL database isn't accepting this, by default it renders INNER JOIN, which fails, but if I modify the MySQL compiler to not do this, still fails :</p> <pre><code>s.execute(d) (ProgrammingError) (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'JOIN path AS p1 ON p1.ancestor = 5 WHERE path.descendant = p1.descendant' at line 1") 'DELETE FROM path JOIN path AS p1 ON p1.ancestor = %s WHERE path.descendant = p1.descendant' (5,) </code></pre> <p>looks like your SQL verbatim (oh, except for 'delete paths FROM paths'? is that right?) ?</p> <p>In any case, if the built in compiler is not doing it, your options are to use <code>session.execute("some sql")</code> or to build a custom construct with the <a href="http://docs.sqlalchemy.org/en/rel_0_8/core/compiler.html" rel="nofollow">compiler extension</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload