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 1rfsPp-002rVV-5l for pgsql-bugs@arkaria.postgresql.org; Fri, 01 Mar 2024 02:14:26 +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 1rfsPm-00ARPN-Uv for pgsql-bugs@arkaria.postgresql.org; Fri, 01 Mar 2024 02:14:23 +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 1rfsPm-00ARPE-7h for pgsql-bugs@lists.postgresql.org; Fri, 01 Mar 2024 02:14:23 +0000 Received: from out-172.mta1.migadu.com ([2001:41d0:203:375::ac]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rfsPi-002BLI-Ol for pgsql-bugs@lists.postgresql.org; Fri, 01 Mar 2024 02:14:21 +0000 Mime-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nmfay.com; s=key1; t=1709259257; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OitUy1qBlDngGsNU061WtgslRLxsU9GSLpLvjvdrIGQ=; b=NbkvZ6ddoB1lbQbN12mn+b+EYWnTI9BTtj+yt29+h6FhxD8aw5VPpVik1tbz3jV06wy7kB kcVQOM+U+IDz5REO/l4VPVHo+B7U5kvTi6ZG0TLXYVTX6gdtaoD5/8pJG8WfCVeibVGwe1 kFKQFkqOROMhPUVa2UantTxy2hwWqi+GGJiu11XuyEhqDS7Z9uBJPE23IRee7QoaSUCsYk ptRUJ50GNLG+dzPyhZLniZ6WxxNC/ZnAhmO9LpIhrj/k6KV4j1gMOqjyWtzULsxhFnuknk 9DyYjZ6RW60ADInjQAwKPkTh9P+kJYjA9DfM/y6iFls/ayxZH46+8cmb5ITVJQ== Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Thu, 29 Feb 2024 21:14:10 -0500 Message-Id: Cc: "pgsql-bugs@lists.postgresql.org" Subject: Re: `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" To: "David G. Johnston" References: In-Reply-To: X-Migadu-Flow: FLOW_OUT List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu Feb 29, 2024 at 12:53 AM EST, David G. Johnston wrote: > On Wednesday, February 28, 2024, Dian Fay wrote: > > > > > > 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: > > > > > This seems to be one of those =E2=80=9Cwon=E2=80=99t fix=E2=80=9D bugs th= at stems from the parser > being a bit too liberal in what it accepts as valid SQL. > > > https://www.postgresql.org/message-id/CAKFQuwZ3-XGfcS%2BCLTAYvPx3ARYjUxv%= 2B%3DYL8sOicV0nda%3DT5cA%40mail.gmail.com > > The fact that the gs involving expression is seen differently than the on= es > not involving gs doesn=E2=80=99t surprise me. > > David J. Thanks, that makes sense! Any thoughts on whether it's worth a cautionary note in the `order by` and/or random function docs since `order by random()` is a fairly well attested solution and I'm not the first person to run into this quirk?