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 1qlYEh-003ISc-Mp for pgsql-general@arkaria.postgresql.org; Wed, 27 Sep 2023 17:22:07 +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 1qlYEf-001Syi-Ny for pgsql-general@arkaria.postgresql.org; Wed, 27 Sep 2023 17:22:06 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qlVrw-000Y4A-Dy for pgsql-general@lists.postgresql.org; Wed, 27 Sep 2023 14:50:28 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qlVru-006wi7-3n for pgsql-general@lists.postgresql.org; Wed, 27 Sep 2023 14:50:27 +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 38REoOC7606025; Wed, 27 Sep 2023 10:50:24 -0400 From: Tom Lane To: Philip Carlsen cc: pgsql-general@lists.postgresql.org Subject: Re: valid casts to anyarray In-reply-to: References: Comments: In-reply-to Philip Carlsen message dated "Tue, 26 Sep 2023 21:39:31 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <606023.1695826224.1@sss.pgh.pa.us> Date: Wed, 27 Sep 2023 10:50:24 -0400 Message-ID: <606024.1695826224@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Philip Carlsen writes: > I've been down a rabbit hole today trying to understand what exactly makes > a type a valid candidate for an ANYARRAY function argument (e.g., something > you can 'unnest()'). Per the comments for check_generic_type_consistency: * 2) All arguments declared ANYARRAY must have the same datatype, * which must be a varlena array type. If you follow that code down you eventually find that it expects get_element_type() to succeed, and that says * NB: this only succeeds for "true" arrays having array_subscript_handler * as typsubscript. For other types, InvalidOid is returned independently * of whether they have typelem or typsubscript set. which is mechanized as an IsTrueArrayType() check. > My reading has led me across such functions as 'get_promoted_array_type', > 'IsTrueArrayType', 'can_coerce_type', and 'check_generic_type_consistency', > and this has led me to believe that any type which has a valid (i.e., > non-zero?) pg_type.typelem defined should be applicable. It has to not only have an element type, but have a standard array header, else we don't know how to do a lot of operations on it. Type "point" and related animals are sort of a poor man's array, which is supported for basic subscripting operations, but it's not generic enough to be reasonable to consider as an ANYARRAY. regards, tom lane