Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lwm2q-0004sO-Ev for pgsql-general@arkaria.postgresql.org; Fri, 25 Jun 2021 13:38:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lwm2p-0004b1-Ep for pgsql-general@arkaria.postgresql.org; Fri, 25 Jun 2021 13:38:55 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lwm2p-0004at-6B for pgsql-general@lists.postgresql.org; Fri, 25 Jun 2021 13:38:55 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lwm2m-0004Dz-U2 for pgsql-general@lists.postgresql.org; Fri, 25 Jun 2021 13:38:54 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 15PDcpb72737120; Fri, 25 Jun 2021 09:38:51 -0400 From: Tom Lane To: David Morgenstern cc: pgsql-general@lists.postgresql.org Subject: Re: Difference between text_pattern_ops and varchar_pattern_ops In-reply-to: <2EA363D8-E6F2-4EBF-9A74-BECBBF81B76E@synedra.com> References: <2EA363D8-E6F2-4EBF-9A74-BECBBF81B76E@synedra.com> Comments: In-reply-to David Morgenstern message dated "Fri, 25 Jun 2021 12:29:41 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <2737118.1624628331.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Fri, 25 Jun 2021 09:38:51 -0400 Message-ID: <2737119.1624628331@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk David Morgenstern writes: > Can somebody explain why text_pattern_ops can be used on varchar > columns, considering it can’t be used for bpchar columns? The underlying rule there is that an opclass can be applied to an index column if the column's actual type is binary-coercible to what the opclass expects. varchar is binary-coercible to text, since they're basically the same type. bpchar is not, because we must insert a coercion function that strips any trailing blanks. (Essentially, the restriction exists because the index machinery won't cope with such intermediate functions.) regards, tom lane