Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1jGoMY-0004Zt-LH for pgsql-performance@arkaria.postgresql.org; Tue, 24 Mar 2020 18:33:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jGoMX-0006VR-Ey for pgsql-performance@arkaria.postgresql.org; Tue, 24 Mar 2020 18:33:17 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1jGoMX-0006VH-2S for pgsql-performance@lists.postgresql.org; Tue, 24 Mar 2020 18:33:17 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jGoMT-0006ew-81 for pgsql-performance@lists.postgresql.org; Tue, 24 Mar 2020 18:33:15 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id 02OIXBLc023974; Tue, 24 Mar 2020 14:33:12 -0400 From: Tom Lane To: Luis Roberto Weck cc: pgsql-performance@lists.postgresql.org Subject: Re: Random function In-reply-to: <95311e45-95e3-970b-e54f-3a4595d55dbb@siscobra.com.br> References: <95311e45-95e3-970b-e54f-3a4595d55dbb@siscobra.com.br> Comments: In-reply-to Luis Roberto Weck message dated "Tue, 24 Mar 2020 15:10:16 -0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <23972.1585074791.1@sss.pgh.pa.us> Date: Tue, 24 Mar 2020 14:33:11 -0400 Message-ID: <23973.1585074791@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Luis Roberto Weck 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