Re: stored procedure

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Peter Choe <choepete(at)mindspring(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: stored procedure
Date: 2003-04-01 20:48:57
Message-ID: 3555.1049230137@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Peter Choe <choepete(at)mindspring(dot)com> writes:
> i do the following:
> select c from charkey where idx=((4 * random())::int)%4;
> sometimes i get one character back (which is good), but other times, i
> get two characters or none.

The WHERE clause is re-evaluated at each row, so you get a new random
value each time. You need to compute *one* random value and then pull
the matching row out of the table.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Dennis Gearon 2003-04-01 21:09:33 Re: Earth distance
Previous Message Tom Lane 2003-04-01 20:24:34 Re: mariposa