Re: How to create a specific table - Mailing list pgsql-general

From Alban Hertroys
Subject Re: How to create a specific table
Date
Msg-id 14364B5E-04E0-458C-884F-BCEEB905A516@gmail.com
Whole thread Raw
In response to How to create a specific table  (Pierre Hsieh <pierre.hsieh@gmail.com>)
List pgsql-general
> On 22 Jan 2015, at 15:54, Pierre Hsieh <pierre.hsieh@gmail.com> wrote:
> rule:
> 1. just one column which type is integer in table
> 2. this columns only has 1 and 2 for 50 times as following
>
> 1
> 2
> 1
> 2
> 1
> 2
> 1
> 2
> .....

create table test as select b from generate_series(1,50) s1(a), generate_series(1,2) s2(b);

But since tables are unordered sets, you'll need something to order your data by when querying, so I'd use this:

create table test as select a, b from generate_series(1,50) s1(a), generate_series(1,2) s2(b);
select b from test order by a,b;


I'm kind of curious what kind of problem you're trying to solve. First you ask how to calculate the standard deviation
ofblocks of 50 records and now this. Are you sure those blocks are ALWAYS 50 records large? Never, say 49 or 51 because
somerecords either weren't stored at all or were stored in the wrong block? If that occurs, you're dealing with an
increasingskew in your statistics. Perhaps the right thing to ask yourself is what groups those 50 records together,
whatdo they have in common? 

Alban Hertroys
--
If you can't see the forest for the trees,
cut the trees and you'll find there is no forest.



pgsql-general by date:

Previous
From: Michael Paquier
Date:
Subject: Re: Retrieving the role in a logical replication plugin
Next
From: Tim Smith
Date:
Subject: In need of some JSONB examples ?