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 1qlVrW-0038Hu-4l for pgsql-general@arkaria.postgresql.org; Wed, 27 Sep 2023 14:50:02 +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 1qlVrU-000VTz-6i for pgsql-general@arkaria.postgresql.org; Wed, 27 Sep 2023 14:50:00 +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 1qlVrT-000VTh-NP for pgsql-general@lists.postgresql.org; Wed, 27 Sep 2023 14:50:00 +0000 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qlVrO-006whq-GP for pgsql-general@lists.postgresql.org; Wed, 27 Sep 2023 14:49:59 +0000 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-40528376459so115084095e9.3 for ; Wed, 27 Sep 2023 07:49:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20230601.gappssmtp.com; s=20230601; t=1695826193; x=1696430993; darn=lists.postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:from:to:cc:subject:date :message-id:reply-to; bh=WL7RNg9oMF9y5sOI/lR73TSMOaEGcblhIivP9tfH+NI=; b=Bt6Zuu3CGN4hHVgyas+X4pAN8odQaAIsEAEupOafUEz25Qtv+u2Q+Xr4Oo/M9hqiMr /A3sEigImE/adoxZ3eVtx+USJtKNQL0NMmYYqwuUIlUWEL9LBv+qo+kB+w69Baskvela cGgbh9oZxgQSFX6MoqSZSV46GCvWIwCsUht6EKZBF7Ep67cH2f/5lJ7oxHTRFPlY7OmE HMLeMyGzgRoO7KvUAZ4yL4lHmYPGATZQ7albiH4UT2FkNG6EXuvI+VXXpZa2qWIXv0DK JMFS0V/txkKC7iTIXNFKMH7ePBAh4GuX2X2tti/OVneLg7R2MkAiAFCHRUOIyYMlrAfq /SsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695826193; x=1696430993; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=WL7RNg9oMF9y5sOI/lR73TSMOaEGcblhIivP9tfH+NI=; b=RQwk2EJoWCoCgbeldGfOckcn36UP+UkZsDfDZ1jDYJMz+GMdoKnlMlflkS3SblVhtb 1ZvsilX8JmhhxSVKkZyVzTZ3IjIvxMDVcnhhTBwx206o65GqT9LXklirG48VVRyPrNQI 4MU4X3AIljtfQshpgSGNnnUr8xMB04BWdiwBaHFdeWXvYzktdQBaY5MpwLS9ZUXUAsh1 1E4jNxRv2HpgdDxRC/ondtxGS+qaJH7nc3QrKdZXzK802p857XfzWjOpQlcKcNizzjZY QuC5sfm0vDa6LUCZjXpU9dYPPF3WrF6WofWJ+MxZclqIMeQRDRNKjxEWafP2N/e5aNnH vDbw== X-Gm-Message-State: AOJu0YyaDIBAFtqrmUvhuzksZYcioPWl/F2/igZNMY/bFz/8WpOctNYO KoRt1WgzqzZANdiF3U793SnMgw== X-Google-Smtp-Source: AGHT+IGgfqo+R1etIc276fjpHLJuTKVf69PlB0f4/Uv53DMj17PMd9SJDGRa5UG7NY98mVyTJUzAog== X-Received: by 2002:a05:600c:210d:b0:405:49aa:d578 with SMTP id u13-20020a05600c210d00b0040549aad578mr2165094wml.37.1695826192656; Wed, 27 Sep 2023 07:49:52 -0700 (PDT) Received: from localhost.localdomain (178-190-177-111.adsl.highway.telekom.at. [178.190.177.111]) by smtp.gmail.com with ESMTPSA id q12-20020a05600c040c00b0040586360a36sm9588577wmb.17.2023.09.27.07.49.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 07:49:52 -0700 (PDT) Message-ID: <88bf272f86df0c91a7beb7b229a4a784ff97b9f1.camel@cybertec.at> Subject: Re: valid casts to anyarray From: Laurenz Albe To: Philip Carlsen , pgsql-general@lists.postgresql.org Date: Wed, 27 Sep 2023 16:49:51 +0200 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.48.4 (3.48.4-1.fc38) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, 2023-09-26 at 21:39 +0200, Philip Carlsen wrote: > I've been down a rabbit hole today trying to understand what exactly make= s a type > a valid candidate for an ANYARRAY function argument (e.g., something you = can 'unnest()'). >=20 > My reading has led me across such functions as 'get_promoted_array_type',= =C2=A0 '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. >=20 > However, I cannot seem to be able to call 'unnest' on a 'point':=20 >=20 > postgres=3D# select unnest(point(1,2)); > ERROR: =C2=A0function unnest(point) does not exist >=20 > ... even though according to 'pg_catalog.pg_type' the type 'point' does i= ndeed look > very array-like (it should be equivalent to an float8 array). The only di= fference I > can spot is that it has 'typsubscript=3Draw_array_subscript_handler', as = opposed to > typsubscript=3Darray_subscript_handler' which is what 'IsTrueArrayType' c= hecks for. >=20 > Can anyone here perhaps enlighten me as to how I can tell if a type is a = valid ANYARRAY > (and bonus points to point out the check I must have missed in the (parse= r?) source code)? I'd say that the type has to be an array type... For example, here is the definition of "cardinality()", which takes "anyarr= ay" as argument: Datum array_cardinality(PG_FUNCTION_ARGS) { AnyArrayType *v =3D PG_GETARG_ANY_ARRAY_P(0); PG_RETURN_INT32(ArrayGetNItems(AARR_NDIM(v), AARR_DIMS(v))); } Yours, Laurenz Albe