Re: How to create a specific table

From: Alban Hertroys <haramrae(at)gmail(dot)com>
To: Pierre Hsieh <pierre(dot)hsieh(at)gmail(dot)com>
Cc: Brian Dunavant <brian(at)omniti(dot)com>, Rémi Cura <remi(dot)cura(at)gmail(dot)com>, PostgreSQL <pgsql-general(at)postgresql(dot)org>, rod <rod(at)iol(dot)ie>, Paul Jungwirth <pj(at)illuminatedcomputing(dot)com>
Subject: Re: How to create a specific table
Date: 2015-01-23 12:43:43
Message-ID: 14364B5E-04E0-458C-884F-BCEEB905A516@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


> On 22 Jan 2015, at 15:54, Pierre Hsieh <pierre(dot)hsieh(at)gmail(dot)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 of blocks of 50 records and now this. Are you sure those blocks are ALWAYS 50 records large? Never, say 49 or 51 because some records either weren't stored at all or were stored in the wrong block? If that occurs, you're dealing with an increasing skew in your statistics. Perhaps the right thing to ask yourself is what groups those 50 records together, what do 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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tim Smith 2015-01-23 14:00:56 In need of some JSONB examples ?
Previous Message Michael Paquier 2015-01-23 12:18:14 Re: Retrieving the role in a logical replication plugin