pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Luis Roberto Weck <luisroberto@siscobra.com.br>
Cc: pgsql-performance@lists.postgresql.org
Subject: Re: Random function
Date: Tue, 24 Mar 2020 14:33:11 -0400
Message-ID: <23973.1585074791@sss.pgh.pa.us> (raw)
In-Reply-To: <95311e45-95e3-970b-e54f-3a4595d55dbb@siscobra.com.br>
References: <95311e45-95e3-970b-e54f-3a4595d55dbb@siscobra.com.br>

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





view thread (3+ messages)  latest in thread

Message-ID: <23973.1585074791@sss.pgh.pa.us>
Permalink:  ../23973.1585074791@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/23973.1585074791@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: tgl@sss.pgh.pa.us, luisroberto@siscobra.com.br, pgsql-performance@lists.postgresql.org
  Subject: Re: Random function
  In-Reply-To: <23973.1585074791@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox