Skip to main content

DB_Table.limit

limitmax_rows

Group: Selections
Aliases: order_by

Documentation

Returns a new Table that will include at most max_rows rows from the original Table.

Since this Table is backed by an SQL database, the Table returned by the limit method is deterministic only if the Table has been ordered (using the order_by method). Otherwise, no order is imposed, so the returned Table will include at most max_rows rows, but there are no guarantees on which rows will be selected. Moreover, even if the underlying table in the database did not change, different sets of rows may be returned each time the returned Table is materialized. The limit is applied at the very end, so the new Table behaves exactly as the old one, just limiting its results when being materialized. Specifically, applying further filters will still apply to the whole result set and the limit will be taken after applying these filters.

Arguments

  • max_rows: The maximum number of rows to get from the table.

Examples

In the call below, assuming that the table of t1 contains rows for

numbers 1, 2, ..., 10, will return rows starting from 6 and not an empty result as one could expect if the limit was applied before the filters.

      t1 = table.sort [..Name "A"] . limit 5
t2 = t1.filter 'A' (..Greater than=5)
t2.read