Re: TABLESAMPLE usage

From: Tom Smith <tomsmith1989sk(at)gmail(dot)com>
To: Simon Riggs <simon(at)2ndquadrant(dot)com>
Cc: Matija Lesar <matija(dot)lesar(at)gmail(dot)com>, Vik Fearing <vik(at)2ndquadrant(dot)fr>, PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: TABLESAMPLE usage
Date: 2016-01-25 16:33:31
Message-ID: CAKwSVFHLTJ1w0njMzNyh3nXmeax26_kgsyKFBtHRiU50QVV4eA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Yeah. I am looking for fastest possible method that Postgresql would
use its internal data structure knowledge to walk through the timestamp
index
and resturns every "nth" row

On Mon, Jan 25, 2016 at 5:56 AM, Simon Riggs <simon(at)2ndquadrant(dot)com> wrote:

> On 25 January 2016 at 09:44, Matija Lesar <matija(dot)lesar(at)gmail(dot)com> wrote:
>
>
>> you can accomplish this with row_number()
>> <http://www.postgresql.org/docs/8.4/static/functions-window.html#FUNCTIONS-WINDOW-TABLE>
>> :
>>
>> WITH data_cte as (
>> SELECT
>> id,
>> clock_timestamp() as ctimestamp
>> FROM generate_series(1,1000) as id
>> )
>> SELECT
>> *
>> FROM
>> (SELECT
>> id,
>> ctimestamp,
>> row_number() OVER (ORDER BY ctimestamp) as rownum
>> FROM data_cte
>> ) as data_withrownumbers
>> WHERE
>> rownum%100=1;
>>
>
> You can, but its not very fast.
>
> --
> Simon Riggs http://www.2ndQuadrant.com/
> <http://www.2ndquadrant.com/>
> PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Brian Dunavant 2016-01-25 16:39:25 Re: CoC [Final v2]
Previous Message Shulgin, Oleksandr 2016-01-25 16:16:35 Re: help:error while running postgres after installing postgresql server from source code