Re: Random function

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Luis Roberto Weck <luisroberto(at)siscobra(dot)com(dot)br>
Cc: pgsql-performance(at)lists(dot)postgresql(dot)org
Subject: Re: Random function
Date: 2020-03-24 18:33:11
Message-ID: 23973.1585074791@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Luis Roberto Weck <luisroberto(at)siscobra(dot)com(dot)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

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message David G. Johnston 2020-03-24 18:33:26 Re: Random function
Previous Message Luis Roberto Weck 2020-03-24 18:10:16 Random function