MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / with_hint

Method with_hint

lib/sqlalchemy/sql/dml.py:881–921  ·  view source on GitHub ↗

Add a table hint for a single table to this INSERT/UPDATE/DELETE statement. .. note:: :meth:`.UpdateBase.with_hint` currently applies only to Microsoft SQL Server. For MySQL INSERT/UPDATE/DELETE hints, use :meth:`.UpdateBase.prefix_with`. The te

(
        self,
        text: str,
        selectable: Optional[_DMLTableArgument] = None,
        dialect_name: str = "*",
    )

Source from the content-addressed store, hash-verified

879
880 @_generative
881 def with_hint(
882 self,
883 text: str,
884 selectable: Optional[_DMLTableArgument] = None,
885 dialect_name: str = "*",
886 ) -> Self:
887 """Add a table hint for a single table to this
888 INSERT/UPDATE/DELETE statement.
889
890 .. note::
891
892 :meth:`.UpdateBase.with_hint` currently applies only to
893 Microsoft SQL Server. For MySQL INSERT/UPDATE/DELETE hints, use
894 :meth:`.UpdateBase.prefix_with`.
895
896 The text of the hint is rendered in the appropriate
897 location for the database backend in use, relative
898 to the :class:`_schema.Table` that is the subject of this
899 statement, or optionally to that of the given
900 :class:`_schema.Table` passed as the ``selectable`` argument.
901
902 The ``dialect_name`` option will limit the rendering of a particular
903 hint to a particular backend. Such as, to add a hint
904 that only takes effect for SQL Server::
905
906 mytable.insert().with_hint("WITH (PAGLOCK)", dialect_name="mssql")
907
908 :param text: Text of the hint.
909 :param selectable: optional :class:`_schema.Table` that specifies
910 an element of the FROM clause within an UPDATE or DELETE
911 to be the subject of the hint - applies only to certain backends.
912 :param dialect_name: defaults to ``*``, if specified as the name
913 of a particular dialect, will apply these hints only when
914 that dialect is in use.
915 """
916 if selectable is None:
917 selectable = self.table
918 else:
919 selectable = coercions.expect(roles.DMLTableRole, selectable)
920 self._hints = self._hints.union({(selectable, dialect_name): text})
921 return self
922
923 @property
924 def entity_description(self) -> Dict[str, Any]:

Callers 14

test_hintsMethod · 0.45
test_with_hint_tableMethod · 0.45
CoreFixturesClass · 0.45
test_hintsMethod · 0.45
test_from_onlyMethod · 0.45
test_join_with_hintMethod · 0.45
test_insert_hintMethod · 0.45
test_update_hintMethod · 0.45
test_delete_hintMethod · 0.45

Calls 1

unionMethod · 0.45

Tested by 13

test_hintsMethod · 0.36
test_with_hint_tableMethod · 0.36
test_hintsMethod · 0.36
test_from_onlyMethod · 0.36
test_join_with_hintMethod · 0.36
test_insert_hintMethod · 0.36
test_update_hintMethod · 0.36
test_delete_hintMethod · 0.36