Re: some random() clarification needed

From: Marc Millas <marc(dot)millas(at)mokadb(dot)com>
To: David Rowley <dgrowleyml(at)gmail(dot)com>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: some random() clarification needed
Date: 2020-07-15 09:19:33
Message-ID: CADX_1absMjCR1jxZwXxr1-x9s6s+kigjNje2TzLB1vHo_S7MOQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Thanks!
makes it clearer :-)
its not that obvious to guess the consequences of the "volatile" behaviour.
regards,

Marc MILLAS
Senior Architect
+33607850334
www.mokadb.com

On Wed, Jul 15, 2020 at 1:53 AM David Rowley <dgrowleyml(at)gmail(dot)com> wrote:

> On Wed, 15 Jul 2020 at 04:01, Marc Millas <marc(dot)millas(at)mokadb(dot)com> wrote:
> > your answer helps me understand my first problem.
> > so, I rewrote a simple loop so as to avoid the "volatile" behaviour.
>
> Not sure what you're trying to do with the plpgsql, but you can just
> escape the multiple evaluations by putting the volatile function in a
> sub-select with no FROM clause.
>
> SELECT ... FROM ... WHERE id = (SELECT ceiling(random()*2582));
>
> Or the more traditional way to get a random row is:
>
> SELECT ... FROM ... WHERE id BETWEEN 0 AND 2585 ORDER BY random() LIMIT 1;
>
> David
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Samarendra Sahoo 2020-07-15 09:31:17 How to enable TDE on Postgresql 12.3 deployed using Kubernetes
Previous Message Eudald Valcàrcel Lacasa 2020-07-15 08:27:52 Re: Issue executing query from container