Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rfYIS-000r5I-2K for pgsql-bugs@arkaria.postgresql.org; Thu, 29 Feb 2024 04:45:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rfYIQ-0000ic-Dv for pgsql-bugs@arkaria.postgresql.org; Thu, 29 Feb 2024 04:45:26 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rfYIP-0000iU-P4 for pgsql-bugs@lists.postgresql.org; Thu, 29 Feb 2024 04:45:26 +0000 Received: from out-183.mta1.migadu.com ([2001:41d0:203:375::b7]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rfYIN-001xv5-CF for pgsql-bugs@lists.postgresql.org; Thu, 29 Feb 2024 04:45:25 +0000 Mime-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nmfay.com; s=key1; t=1709181920; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=d2ovD0c0+k5bYKeyvrFsEFNWQkkboZECiE0OP1pnzA4=; b=MtVqZ6opK37lQvtvZzW4cUQJDwiDU8iZh64fqt/E0JS7RCX9bj8sWoqF3vRCSyRgOTO7sp WH1rZAJzBtv9vrAmXLSRkrn0nqx45is4WK2MeHJonaXCW444UhMnEdqUi+SzuinApV3llJ HKdVFwchTVGPaOvFZB6YzE5XYhx8RQRi+IwPHO98k29lt5/lEAn5wnr6isNKow8fy9cYGq U05nPwSwEfkaNVtMyknYAxDgE94dYpdeAaYkoX2TbWS39OeVfJuf55118qmmTQW3NN1z/W OszHyhUxZu40JTT2SrK0eaO3O1WDj5ZI/uSQ1Yh7RPgLqT1fXtAAF7kR40I8TQ== Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Wed, 28 Feb 2024 23:45:17 -0500 Message-Id: To: Subject: `order by random()` makes select-list `random()` invocations deterministic X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: "Dian Fay" X-Migadu-Flow: FLOW_OUT List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk In Postgres 16.1, running the following query: ``` select gs, gs + random() * 100 - 50 as gs2, random() * 100 - 50 as r1, random() * 100 - 50 as r2, random() * 100 - 50 as r3 from generate_series(0, 10) as gs order by random(); ``` Every `random()` invocation in the select list uses a single consistent value within each returned row. Remove the `order by random()` and values become randomized as expected, but it gets a bit stranger: - order by any of the `rN` values and `gs2` uses a different random value, but all the `rN` values are identical; - order by `gs2` and all random values are distinct again.