Random function

From: Luis Roberto Weck <luisroberto(at)siscobra(dot)com(dot)br>
To: pgsql-performance(at)lists(dot)postgresql(dot)org
Subject: Random function
Date: 2020-03-24 18:10:16
Message-ID: 95311e45-95e3-970b-e54f-3a4595d55dbb@siscobra.com.br
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Hi,

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)

And I am getting something like:

|string_agg |
+--------------------------------------------------------------+
|0.243969671428203583;0.692578794434666634;0.291524752043187618|
|0.243969671428203583;0.692578794434666634;0.291524752043187618|
|0.243969671428203583;0.692578794434666634;0.291524752043187618|
|0.243969671428203583;0.692578794434666634;0.291524752043187618|
|0.243969671428203583;0.692578794434666634;0.291524752043187618|
|0.243969671428203583;0.692578794434666634;0.291524752043187618|
|0.243969671428203583;0.692578794434666634;0.291524752043187618|
|0.243969671428203583;0.692578794434666634;0.291524752043187618|
|0.243969671428203583;0.692578794434666634;0.291524752043187618|
|0.243969671428203583;0.692578794434666634;0.291524752043187618|

If this is the expected output, is there a way to always generate random
numbers?

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Tom Lane 2020-03-24 18:33:11 Re: Random function
Previous Message Thomas Kellerer 2020-03-23 16:33:34 Re: JOIN on partitions is very slow