Re: Statistical Analysis

From: Guillaume Perréal <perreal(at)lyon(dot)cemagref(dot)fr>
To: Steve Heaven <steve(at)thornet(dot)co(dot)uk>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-general(at)postgresql(dot)org
Subject: Re: Statistical Analysis
Date: 2000-07-25 14:06:45
Message-ID: 397D9EF5.6A9EC571@lyon.cemagref.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Steve Heaven wrote:
>
> At 20:18 24/07/00 -0400, you wrote:
> >Sigh, forgot to mention the solution. There's an undocumented function:
> >
> > * bool oidrand (oid o, int4 X)-
> > * takes in an oid and a int4 X, and will return 'true'
> > * about 1/X of the time.
> >
> >typically used like this:
> >
> >-- select roughly 1/10 of the tuples
> >SELECT * FROM onek WHERE oidrand(onek.oid, 10);
> >
>
> It doesnt seem to work as you explain.
> For a value of 1 you expect (nearly) all the tuples and two should return
> half, but that not what I'm finding.
>
> galore=> select count(*) from topten where room='HI';
> count
> -----
> 14
> (1 row)
>
> galore=> SELECT * FROM topten WHERE room='HE' and oidrand(topten.oid, 1);
> type|data |norder|room |grp
> ----+-------------------------+------+------+---
> B |0764552503 | 1|HE |
> B |0751327190 | 1|HE |
> B |0718144392 | |HE |
> B |0500280754 | |HE |
> B |0028610091 | 1|HE |
> (5 rows)
> galore=> SELECT * FROM topten WHERE room='HE' and oidrand(topten.oid, 2);
> type|data |norder|room |grp
> ----+-------------------------+------+------+---
> B |0764552503 | 1|HE |
> B |0751327190 | 1|HE |
> B |0718144392 | |HE |
> (3 rows)
> galore=> SELECT * FROM topten WHERE room='HE' and oidrand(topten.oid, 7);
> type|data |norder|room |grp
> ----+-------------------------+------+------+---
> B |0751327190 | 1|HE |
> B |0718144392 | |HE |
> (2 rows)
> --
> thorNET - Internet Consultancy, Services & Training
> Phone: 01454 854413
> Fax: 01454 854412
> http://www.thornet.co.uk

Isn't it because oidrand evals as 'random() < 1/X' ? or maybe 'random() <
1/(X+1)' ?

--
Guillaume Perréal - Stagiaire MIAG
Cemagref (URH), Lyon, France
Tél: (+33) 4.72.20.87.64

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Wilkinson Charlie E 2000-07-25 14:42:06 RE: Describe structure.
Previous Message bmccoy 2000-07-25 14:06:10 Re: Describe structure.