Re: Statistical Analysis - Mailing list pgsql-general

From Guillaume Perréal
Subject Re: Statistical Analysis
Date
Msg-id 397D9EF5.6A9EC571@lyon.cemagref.fr
Whole thread Raw
In response to RE: Statistical Analysis  ("Nathan Barnett" <nbarnett@cellularphones.com>)
List 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

pgsql-general by date:

Previous
From:
Date:
Subject: Re: Describe structure.
Next
From: Wilkinson Charlie E
Date:
Subject: RE: Describe structure.