How it works...

The extract mechanism shows off the capabilities of the PostgreSQL command-line tools, psql and pg_dump, as pg_dump allows you to include or exclude objects and dump the entire table (or only its schema), whereas psql allows you to dump out the result of an arbitrary query into a file.

The BERNOULLI clause specifies the sampling method, that is, PostgreSQL takes the random sample by performing a full table scan, and then selecting each row with the required probability, here 1%.

Another built-in sampling method is SYSTEM, which reads a random sample of table pages, and then includes all rows in these pages; this is generally faster, given that samples are normally quite smaller than the original, but the randomness of the ...

Get PostgreSQL 10 Administration Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.