Random multiple times

From: Oliver Kohll - Mailing Lists <oliver(dot)lists(at)gtwm(dot)co(dot)uk>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Random multiple times
Date: 2011-09-21 08:51:47
Message-ID: 81771A6B-84F3-4014-B5D3-206B523FE5FB@gtwm.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Szymon Guz 2011-09-21 09:18:48 Re: Random multiple times
Previous Message Devrim GÜNDÜZ 2011-09-21 08:25:52 Re: pg-9.1 for fedora 15 available?