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.89) (envelope-from ) id 1hNzwD-0001pB-6d for pgsql-general@arkaria.postgresql.org; Tue, 07 May 2019 13:15:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hNzwB-0003jn-IT for pgsql-general@arkaria.postgresql.org; Tue, 07 May 2019 13:15:15 +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 1hNzwB-0003jg-4r for pgsql-general@lists.postgresql.org; Tue, 07 May 2019 13:15:15 +0000 Received: from q7r7.com ([8.9.8.112] helo=50pop.com) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hNzw8-00037A-VJ for pgsql-general@lists.postgresql.org; Tue, 07 May 2019 13:15:13 +0000 Received: from localhost (50pop.com [local]) by 50pop.com (OpenSMTPD) with ESMTPA id 32e9917f; Tue, 7 May 2019 09:15:12 -0400 (EDT) Date: Tue, 7 May 2019 09:15:12 -0400 From: Myles Miller To: Daniel Perrett , pgsql-general@lists.postgresql.org Subject: Re: random generated string matching index in inexplicable ways [EXT] Message-ID: <20190507131512.GB62383@50pop.com> References: <20190507115345.GA56585@50pop.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.4 (2019-03-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Tue, May 07, 2019 at 12:17:12PM +0000, Daniel Perrett wrote: > The WHERE expression (and therefore the random function) is being evaluated once per row, not once per query. > If you run this query a few times, you will see the problem: > SELECT y, chr(round(random())::int + 65) FROM (SELECT 'A' UNION SELECT 'B') x(y); Ah! Thank you! I understand now.