tsm_system_rows

TABLESAMPLE method which accepts number of rows as a limit

Overview

PackageVersionCategoryLicenseLanguage
tsm_system_rows1.0FUNCPostgreSQLC
IDExtensionBinLibLoadCreateTrustRelocSchema
4910tsm_system_rowsNoYesNoYesYesNo-
Relatedrandom permuteseq tsm_system_time pg_crash pg_idkit pgx_ulid pg_uuidv7 pg_hashids
Depended Bydocumentdb

Version

PG18PG17PG16PG15PG14
1.01.01.01.01.0

Install

Note: This is a built-in contrib extension of PostgreSQL

CREATE EXTENSION tsm_system_rows;

Usage

tsm_system_rows: row-count-based TABLESAMPLE method

Provides the SYSTEM_ROWS table sampling method that returns exactly the specified number of rows.

CREATE EXTENSION tsm_system_rows;

TABLESAMPLE Method

SYSTEM_ROWS(count int) – maximum number of rows to return.

Examples

-- Sample exactly 100 rows
SELECT * FROM my_table TABLESAMPLE SYSTEM_ROWS(100);

-- Quick peek at 10 rows from a large table
SELECT * FROM large_table TABLESAMPLE SYSTEM_ROWS(10);

Performs block-level sampling (may exhibit clustering effects with small samples). Returns all rows if the table has fewer rows than requested. Does not support REPEATABLE.


Last Modified 2026-03-12: add pg extension catalog (95749bf)