MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / fetch

Method fetch

lib/sqlalchemy/sql/selectable.py:4362–4421  ·  view source on GitHub ↗

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,
    )

Source from the content-addressed store, hash-verified

4360
4361 @_generative
4362 def fetch(
4363 self,
4364 count: _LimitOffsetType,
4365 with_ties: bool = False,
4366 percent: bool = False,
4367 **dialect_kw: Any,
4368 ) -> Self:
4369 r"""Return a new selectable with the given FETCH FIRST criterion
4370 applied.
4371
4372 This is a numeric value which usually renders as ``FETCH {FIRST | NEXT}
4373 [ count ] {ROW | ROWS} {ONLY | WITH TIES}`` expression in the resulting
4374 select. This functionality is is currently implemented for Oracle
4375 Database, PostgreSQL, MSSQL.
4376
4377 Use :meth:`_sql.GenerativeSelect.offset` to specify the offset.
4378
4379 .. note::
4380
4381 The :meth:`_sql.GenerativeSelect.fetch` method will replace
4382 any clause applied with :meth:`_sql.GenerativeSelect.limit`.
4383
4384 .. versionadded:: 1.4
4385
4386 :param count: an integer COUNT parameter, or a SQL expression
4387 that provides an integer result. When ``percent=True`` this will
4388 represent the percentage of rows to return, not the absolute value.
4389 Pass ``None`` to reset it.
4390
4391 :param with_ties: When ``True``, the WITH TIES option is used
4392 to return any additional rows that tie for the last place in the
4393 result set according to the ``ORDER BY`` clause. The
4394 ``ORDER BY`` may be mandatory in this case. Defaults to ``False``
4395
4396 :param percent: When ``True``, ``count`` represents the percentage
4397 of the total number of selected rows to return. Defaults to ``False``
4398
4399 :param \**dialect_kw: Additional dialect-specific keyword arguments
4400 may be accepted by dialects.
4401
4402 .. versionadded:: 2.0.41
4403
4404 .. seealso::
4405
4406 :meth:`_sql.GenerativeSelect.limit`
4407
4408 :meth:`_sql.GenerativeSelect.offset`
4409
4410 """
4411 self._validate_dialect_kwargs(dialect_kw)
4412 self._limit_clause = None
4413 if count is None:
4414 self._fetch_clause = self._fetch_clause_options = None
4415 else:
4416 self._fetch_clause = self._offset_or_limit_clause(count)
4417 self._fetch_clause_options = {
4418 "with_ties": with_ties,
4419 "percent": percent,

Calls 2