Re: TABLESAMPLE usage

From: Vik Fearing <vik(at)2ndquadrant(dot)fr>
To: Tom Smith <tomsmith1989sk(at)gmail(dot)com>, PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: TABLESAMPLE usage
Date: 2016-01-25 08:48:01
Message-ID: 56A5E141.7040503@2ndquadrant.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 01/25/2016 05:09 AM, Tom Smith wrote:
> Hello:
>
> I have a big table with that is always appended with new data with a unique
> sequence id (always incremented, or timestamp as unique index) each row.
> I'd like to sample, say 100 rows out of say 1000 rows evently across all
> the rows,
> so that it would return rows of1, 101, 201, 301 you get idea.
> can TABLESAMPLE get one row for every 100 rows, based on the order
> of the rows added to table using the timestamp as already indexed/sorted
> sequence

No, TABLESAMPLE is intended to take a random sampling of the data using
various methods.

You're looking for something more like this:

select t.*
from generate_series(1, (select max(id) from t), 100) g
join t on t.id = g;
--
Vik Fearing +33 6 46 75 15 36
http://2ndQuadrant.fr PostgreSQL : Expertise, Formation et Support

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Smith 2016-01-25 08:55:20 Re: TABLESAMPLE usage
Previous Message Andreas Kretschmer 2016-01-25 08:04:36 Re: Performance options for CPU bound multi-SUM query