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 = "*",
)
| 861 | |
| 862 | @_generative |
| 863 | def with_hint( |
| 864 | self, |
| 865 | text: str, |
| 866 | selectable: Optional[_DMLTableArgument] = None, |
| 867 | dialect_name: str = "*", |
| 868 | ) -> Self: |
| 869 | """Add a table hint for a single table to this |
| 870 | INSERT/UPDATE/DELETE statement. |
| 871 | |
| 872 | .. note:: |
| 873 | |
| 874 | :meth:`.UpdateBase.with_hint` currently applies only to |
| 875 | Microsoft SQL Server. For MySQL INSERT/UPDATE/DELETE hints, use |
| 876 | :meth:`.UpdateBase.prefix_with`. |
| 877 | |
| 878 | The text of the hint is rendered in the appropriate |
| 879 | location for the database backend in use, relative |
| 880 | to the :class:`_schema.Table` that is the subject of this |
| 881 | statement, or optionally to that of the given |
| 882 | :class:`_schema.Table` passed as the ``selectable`` argument. |
| 883 | |
| 884 | The ``dialect_name`` option will limit the rendering of a particular |
| 885 | hint to a particular backend. Such as, to add a hint |
| 886 | that only takes effect for SQL Server:: |
| 887 | |
| 888 | mytable.insert().with_hint("WITH (PAGLOCK)", dialect_name="mssql") |
| 889 | |
| 890 | :param text: Text of the hint. |
| 891 | :param selectable: optional :class:`_schema.Table` that specifies |
| 892 | an element of the FROM clause within an UPDATE or DELETE |
| 893 | to be the subject of the hint - applies only to certain backends. |
| 894 | :param dialect_name: defaults to ``*``, if specified as the name |
| 895 | of a particular dialect, will apply these hints only when |
| 896 | that dialect is in use. |
| 897 | """ |
| 898 | if selectable is None: |
| 899 | selectable = self.table |
| 900 | else: |
| 901 | selectable = coercions.expect(roles.DMLTableRole, selectable) |
| 902 | self._hints = self._hints.union({(selectable, dialect_name): text}) |
| 903 | return self |
| 904 | |
| 905 | @property |
| 906 | def entity_description(self) -> Dict[str, Any]: |