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 1gSkl0-00005J-E3 for pgsql-sql@arkaria.postgresql.org; Fri, 30 Nov 2018 15:31:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gSkkz-0001du-3V for pgsql-sql@arkaria.postgresql.org; Fri, 30 Nov 2018 15:31:05 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gSkky-0001ab-S3 for pgsql-sql@lists.postgresql.org; Fri, 30 Nov 2018 15:31:04 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gSkkw-0001A2-Pj for pgsql-sql@lists.postgresql.org; Fri, 30 Nov 2018 15:31:04 +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 wAUFV0hl017748; Fri, 30 Nov 2018 10:31:00 -0500 From: Tom Lane To: "Voillequin, Jean-Marc" cc: "pgsql-sql@lists.postgresql.org" Subject: Re: Avoid "could not determine interpretation of row comparison operator =" In-reply-to: <1EC8157EB499BF459A516ADCF135ADCE39FFD3A4@LON-WGMSX712.ad.moodys.net> References: <1EC8157EB499BF459A516ADCF135ADCE39FFD3A4@LON-WGMSX712.ad.moodys.net> Comments: In-reply-to "Voillequin, Jean-Marc" message dated "Fri, 30 Nov 2018 13:35:27 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <17746.1543591860.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 30 Nov 2018 10:31:00 -0500 Message-ID: <17747.1543591860@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk "Voillequin, Jean-Marc" writes: > I understand that row (1,2) (int,int) cannot be compared to row ('1','2'= ) (text,text) without coding a new comparison operator =3D for row type. > I have read the documentation on "create/alter operator class/family" bu= t could not figure out how to do this. > Is it just possible to implement such feature within PG thanks to operat= or class/family ? TBH, I think you would greatly regret that if you did it. It'd create numerous problems: * Some queries would start failing due to inability to resolve an ambiguous operator choice. * The ordering of numbers and text isn't the same, eg 123 is greater than 23 if you consider them to be numbers but not if you consider them to be text. If you fuzz the line determining which ordering applies, that's going to result in a lot of confusion for you, even if the system thinks it's clear. * Even simple equality isn't the same in the two domains, consider "1" vs "+1". More room for surprises. * The semantics you've chosen here (cast the text input to numeric) mean that the comparison operator will fail outright for a large fraction of its possible text inputs. That's seldom a desirable behavior for a btree comparison operator. I think you'd be way better off to fix whichever part of your application is confused enough to think that a query like that is sensible. > Of course, the case I have to solve is more complex. But a small example= or recommendation will be greatly appreciated. Perhaps what you're really trying to do is more sensible than this example, but if so you should give us a less oversimplified example. regards, tom lane