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 1m2wjE-0003m3-FA for pgsql-bugs@arkaria.postgresql.org; Mon, 12 Jul 2021 14:16:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m2wjD-0001no-8y for pgsql-bugs@arkaria.postgresql.org; Mon, 12 Jul 2021 14:16:11 +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 1m2wjD-0001nf-2K for pgsql-bugs@lists.postgresql.org; Mon, 12 Jul 2021 14:16:11 +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 1m2wj9-0008P3-9M for pgsql-bugs@lists.postgresql.org; Mon, 12 Jul 2021 14:16:10 +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 16CEG4ld2947260; Mon, 12 Jul 2021 10:16:04 -0400 From: Tom Lane To: Andrew Kiellor cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17101: Inconsistent behaviour when querying with anonymous composite types In-reply-to: References: <17101-a6faa1f74b35062d@postgresql.org> Comments: In-reply-to Andrew Kiellor message dated "Mon, 12 Jul 2021 01:44:05 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2947258.1626099364.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 12 Jul 2021 10:16:04 -0400 Message-ID: <2947259.1626099364@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Andrew Kiellor writes: > Sorry I omitted the output. It is as follows: > psql:test.sql:14: ERROR: input of anonymous composite types is not impl= emented > LINE 1: SELECT * FROM table1 WHERE column1 =3D '(0)'; > ^ I think this is operating as designed. I agree it'd be slightly more convenient if the parser would infer that the RHS must be of the same type as the LHS, but shoehorning that into the existing system design seems problematic. The record_eq operator doesn't actually require that its inputs be of identical composite types, only compatible ones. To continue your example: regression=3D# CREATE TYPE type2 AS (xyz int); CREATE TYPE regression=3D# SELECT * FROM table1 WHERE column1 =3D '(0)'::type2; column1 = --------- (0) (1 row) regression=3D# CREATE TYPE type3 AS (x float); CREATE TYPE regression=3D# SELECT * FROM table1 WHERE column1 =3D '(0)'::type3; ERROR: cannot compare dissimilar column types integer and double precisio= n at record column 1 So if the parser assumed that the inputs must be of the same composite type, it'd be exceeding its authority, and would likely cause queries that work today to start failing. The back story here is that type "record" isn't really a polymorphic type, though it behaves similarly to those types in some ways. If we were designing in a green field it'd make sense to treat "record" according to the polymorphism rules. But we're not; "record" is way older than the polymorphics so it has various unique idiosyncrasies. The one that's relevant here is that an input argument that's declared to be "record" isn't required to be the same composite type as another argument also declared as "record". regards, tom lane