tsm_system_time

TABLESAMPLE method which accepts time in milliseconds as a limit

Overview

PackageVersionCategoryLicenseLanguage
tsm_system_time1.0FUNCPostgreSQLC
IDExtensionBinLibLoadCreateTrustRelocSchema
4890tsm_system_timeNoYesNoYesYesNo-
Relatedrandom permuteseq tsm_system_rows pg_crash pg_idkit pgx_ulid pg_uuidv7 pg_hashids

Version

PG18PG17PG16PG15PG14
1.01.01.01.01.0

Install

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

CREATE EXTENSION tsm_system_time;

Usage

tsm_system_time: time-based TABLESAMPLE method

Provides the SYSTEM_TIME table sampling method that returns as many rows as can be read within a specified time limit.

CREATE EXTENSION tsm_system_time;

TABLESAMPLE Method

SYSTEM_TIME(milliseconds float) – maximum time to spend reading the table.

Examples

-- Sample rows readable within 1 second
SELECT * FROM my_table TABLESAMPLE SYSTEM_TIME(1000);

-- Sample from a large table with a 500ms budget
SELECT count(*) FROM large_table TABLESAMPLE SYSTEM_TIME(500);

Performs block-level sampling (not row-level). If the entire table can be read within the time limit, all rows are returned. Does not support REPEATABLE.


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