Re: Random function - Mailing list pgsql-performance

From Tom Lane
Subject Re: Random function
Date
Msg-id 23973.1585074791@sss.pgh.pa.us
Whole thread Raw
In response to Random function  (Luis Roberto Weck <luisroberto@siscobra.com.br>)
List pgsql-performance
Luis Roberto Weck <luisroberto@siscobra.com.br> writes:
> I am trying to generate some random data using the random() function.

> However, I am getting the same result over mulitiple rows. This is a 
> sample of the SQL I am using:

> select (select string_agg(random()::text,';')
>         from pg_catalog.generate_series(1,3,1) )
>   from generate_series(1,10,1)

The sub-select is independent of the outer select so it's only computed
once, and then you get ten copies of that result.  Restructuring the
query, or inserting an artificial dependency on the outer select's data,
would help.

            regards, tom lane



pgsql-performance by date:

Previous
From: Luis Roberto Weck
Date:
Subject: Random function
Next
From: "David G. Johnston"
Date:
Subject: Re: Random function