PostgreSQL 9.5alpha1 Documentation | |||
---|---|---|---|
Prev | Up | Appendix F. Additional Supplied Modules | Next |
The tsm_system_rows module provides the tablesample method SYSTEM_ROWS, which can be used inside the TABLESAMPLE clause of a SELECT.
This tablesample method uses a linear probing algorithm to read sample of a table and uses actual number of rows as limit (unlike the SYSTEM tablesample method which limits by percentage of a table).
Here is an example of selecting sample of a table with SYSTEM_ROWS. First install the extension:
CREATE EXTENSION tsm_system_rows;
Then you can use it in SELECT command same way as other tablesample methods:
SELECT * FROM my_table TABLESAMPLE SYSTEM_ROWS(100);
The above command will return a sample of 100 rows from the table my_table (less if the table does not have 100 visible rows).