Re: stored procedure

From: Peter Choe <choepete(at)mindspring(dot)com>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: stored procedure
Date: 2003-04-01 20:07:00
Message-ID: 3E89F164.6040904@mindspring.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


i tested the random thing and it seems to do something strange. i have
the following table set up:
| idx | c |
|-----|--- |
| 0 | o |
| 1 | a |
| 2 | b |
| 3 | c |
----------

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.

by the way, i am using postgres 7.2 on freebsd 4.8.

Peter Choe

Dennis Gearon wrote:

> then do ( ( 6 * random() )::int ) % 6
>
> Bruno Wolff III wrote:
>
>> On Tue, Apr 01, 2003 at 11:26:47 -0500,
>> Peter Choe <choepete(at)mindspring(dot)com> wrote:
>>
>>> thanks. i just tried it out and it seems that it would generate a
>>> random number between 0 and 1. is that a valid assumption? if that
>>> is the case, how can i cast it to an int value? i assume that there
>>> is a cast function somewhere, but i can't tell by the names of the
>>> pronames.
>>
>>
>>
>> Normally you multiply by the range you want and then you can make a
>> cast.
>> Note however, that multiplication may cause a value to round up so that
>> (6*random())::int might on very rare occasions return 6 instead of the
>> expected 0, 1, 2, 3, 4 or 5. (At least on some systems.)
>>
>>
>> ---------------------------(end of broadcast)---------------------------
>> TIP 2: you can get off all lists at once with the unregister command
>> (send "unregister YourEmailAddressHere" to majordomo(at)postgresql(dot)org)
>>
>
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2003-04-01 20:24:34 Re: mariposa
Previous Message Moritz Sinn 2003-04-01 20:06:36 mariposa