hints for INSERT, UPDATE, DELETE
Issue #2430
resolved
These are table hints that apply generally to the table that's the subject of INSERT, UPDATE, DELETE, and in more of an edge case can also apply to the tables mentioned in the FROM clause implemented by UPDATE and DELETE.
def with_hint(self, text, selectable=None, dialect_name="*"):
"""Add a table hint for a single table to this
INSERT/UPDATE/DELETE statement.
The text of the hint is rendered in the appropriate
location for the database backend in use, relative
to the :class:`.Table` that is the subject of this
statement, or optionally to that of the given
:class:`.Table` passed as the *selectable* argument.
The ``dialect_name`` option will limit the rendering of a particular
hint to a particular backend. Such as, to add a hint
that only takes effect for SQL Server::
mytable.insert().with_hint("PAGLOCK", dialect_name="mssql")
:param text: Text of the hint.
:param selectable: optional :class:`.Table` that specifies
an element of the FROM clause within an UPDATE or DELETE
to be the subject of the hint - applies only to certain backends.
:param dialect_name: defaults to ``*``, if specified as the name
of a particular dialect, will apply these hints only when
that dialect is in use.
"""
table.insert().with_hint("READPAST, NOLOCK")
table.update().with_hint("PAGLOCK")
table.update().where(table.c.foo==table2.c.bar).with_hint("PAGLOCK", table2)
table.delete().with_hint("PAGLOCK", dialect_name="mssql")
for starters we'll target INSERT, UPDATE, DELETE on SQL server and try to hit MySQL as well:
http://msdn.microsoft.com/en-us/library/aa933206%28v=sql.80%29.aspx
http://msdn.microsoft.com/en-us/library/aa260662%28v=sql.80%29.aspx
http://msdn.microsoft.com/en-us/library/aa258847%28v=sql.80%29.aspx
http://dev.mysql.com/doc/refman/5.5/en/insert.html
Comments (3)
-
reporter -
reporter - changed status to resolved
-
reporter - removed milestone
Removing milestone: 0.7.6 (automated comment)
- Log in to comment
correction, for MySQL we already have "prefix". Add a note to the docs regarding this.