From: Tom Lane <tgl@sss.pgh.pa.us>
To: Philip Carlsen <plcplc@gmail.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: valid casts to anyarray
Date: Wed, 27 Sep 2023 10:50:24 -0400
Message-ID: <606024.1695826224@sss.pgh.pa.us> (raw)
In-Reply-To: <CALkT+D4qBsGL8OruvtZSKL9fXa21HCD-KSDVajujtDs3RV-RDQ@mail.gmail.com>
References: <CALkT+D4qBsGL8OruvtZSKL9fXa21HCD-KSDVajujtDs3RV-RDQ@mail.gmail.com>
Philip Carlsen <plcplc@gmail.com> 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, plcplc@gmail.com
Subject: Re: valid casts to anyarray
In-Reply-To: <606024.1695826224@sss.pgh.pa.us>
References: <CALkT+D4qBsGL8OruvtZSKL9fXa21HCD-KSDVajujtDs3RV-RDQ@mail.gmail.com> <606024.1695826224@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox