r"""Return a new selectable with the given FETCH FIRST criterion applied. This is a numeric value which usually renders as ``FETCH {FIRST | NEXT} [ count ] {ROW | ROWS} {ONLY | WITH TIES}`` expression in the resulting select. This functionality is is currently implem
(
self,
count: _LimitOffsetType,
with_ties: bool = False,
percent: bool = False,
**dialect_kw: Any,
)
| 4245 | |
| 4246 | @_generative |
| 4247 | def fetch( |
| 4248 | self, |
| 4249 | count: _LimitOffsetType, |
| 4250 | with_ties: bool = False, |
| 4251 | percent: bool = False, |
| 4252 | **dialect_kw: Any, |
| 4253 | ) -> Self: |
| 4254 | r"""Return a new selectable with the given FETCH FIRST criterion |
| 4255 | applied. |
| 4256 | |
| 4257 | This is a numeric value which usually renders as ``FETCH {FIRST | NEXT} |
| 4258 | [ count ] {ROW | ROWS} {ONLY | WITH TIES}`` expression in the resulting |
| 4259 | select. This functionality is is currently implemented for Oracle |
| 4260 | Database, PostgreSQL, MSSQL. |
| 4261 | |
| 4262 | Use :meth:`_sql.GenerativeSelect.offset` to specify the offset. |
| 4263 | |
| 4264 | .. note:: |
| 4265 | |
| 4266 | The :meth:`_sql.GenerativeSelect.fetch` method will replace |
| 4267 | any clause applied with :meth:`_sql.GenerativeSelect.limit`. |
| 4268 | |
| 4269 | .. versionadded:: 1.4 |
| 4270 | |
| 4271 | :param count: an integer COUNT parameter, or a SQL expression |
| 4272 | that provides an integer result. When ``percent=True`` this will |
| 4273 | represent the percentage of rows to return, not the absolute value. |
| 4274 | Pass ``None`` to reset it. |
| 4275 | |
| 4276 | :param with_ties: When ``True``, the WITH TIES option is used |
| 4277 | to return any additional rows that tie for the last place in the |
| 4278 | result set according to the ``ORDER BY`` clause. The |
| 4279 | ``ORDER BY`` may be mandatory in this case. Defaults to ``False`` |
| 4280 | |
| 4281 | :param percent: When ``True``, ``count`` represents the percentage |
| 4282 | of the total number of selected rows to return. Defaults to ``False`` |
| 4283 | |
| 4284 | :param \**dialect_kw: Additional dialect-specific keyword arguments |
| 4285 | may be accepted by dialects. |
| 4286 | |
| 4287 | .. versionadded:: 2.0.41 |
| 4288 | |
| 4289 | .. seealso:: |
| 4290 | |
| 4291 | :meth:`_sql.GenerativeSelect.limit` |
| 4292 | |
| 4293 | :meth:`_sql.GenerativeSelect.offset` |
| 4294 | |
| 4295 | """ |
| 4296 | self._validate_dialect_kwargs(dialect_kw) |
| 4297 | self._limit_clause = None |
| 4298 | if count is None: |
| 4299 | self._fetch_clause = self._fetch_clause_options = None |
| 4300 | else: |
| 4301 | self._fetch_clause = self._offset_or_limit_clause(count) |
| 4302 | self._fetch_clause_options = { |
| 4303 | "with_ties": with_ties, |
| 4304 | "percent": percent, |