Re: Random multiple times

From: Szymon Guz <mabewlun(at)gmail(dot)com>
To: Oliver Kohll - Mailing Lists <oliver(dot)lists(at)gtwm(dot)co(dot)uk>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Random multiple times
Date: 2011-09-21 09:18:48
Message-ID: CAFjNrYukQQNX8_wZv5EneZam+jmqOCJt8oKpUKKOh-49aPo94A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 21 September 2011 10:51, Oliver Kohll - Mailing Lists <
oliver(dot)lists(at)gtwm(dot)co(dot)uk> wrote:

> Hi,
>
> I understand random() is a volatile function and runs multiple times for
> multiple rows returned by a SELECT, however is there a way of getting it to
> run multiple times *within* another function call and in the same row. i.e.
> something like
>
> select regexp_replace('+1 555 555 555', E'\\d', trunc(random() * 9 +
> 1)::text,'g');
> regexp_replace
> ----------------
> +1 111 111 111
> (1 row)
>
> As you can see, it returns the same digit each time. I've tried wrapping a
> select around the trunc too.
>
> Regards
> Oliver Kohll
> www.gtwm.co.uk / www.agilebase.co.uk
>
>
>
>
Short answer is: yes. More information you can find here
http://simononsoftware.com/problem-with-random-in-postgresql-subselect/

regards
Szymon

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Daniel Baktiar 2011-09-21 09:40:14 Re: Random multiple times
Previous Message Oliver Kohll - Mailing Lists 2011-09-21 08:51:47 Random multiple times