mirror of
https://github.com/postgres/postgres.git
synced 2025-06-30 21:42:05 +03:00
Support arrays as input to array_agg() and ARRAY(SELECT ...).
These cases formerly failed with errors about "could not find array type for data type". Now they yield arrays of the same element type and one higher dimension. The implementation involves creating functions with API similar to the existing accumArrayResult() family. I (tgl) also extended the base family by adding an initArrayResult() function, which allows callers to avoid special-casing the zero-inputs case if they just want an empty array as result. (Not all do, so the previous calling convention remains valid.) This allowed simplifying some existing code in xml.c and plperl.c. Ali Akbar, reviewed by Pavel Stehule, significantly modified by me
This commit is contained in:
21
src/backend/utils/cache/lsyscache.c
vendored
21
src/backend/utils/cache/lsyscache.c
vendored
@ -2354,6 +2354,27 @@ get_array_type(Oid typid)
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* get_promoted_array_type
|
||||
*
|
||||
* The "promoted" type is what you'd get from an ARRAY(SELECT ...)
|
||||
* construct, that is, either the corresponding "true" array type
|
||||
* if the input is a scalar type that has such an array type,
|
||||
* or the same type if the input is already a "true" array type.
|
||||
* Returns InvalidOid if neither rule is satisfied.
|
||||
*/
|
||||
Oid
|
||||
get_promoted_array_type(Oid typid)
|
||||
{
|
||||
Oid array_type = get_array_type(typid);
|
||||
|
||||
if (OidIsValid(array_type))
|
||||
return array_type;
|
||||
if (OidIsValid(get_element_type(typid)))
|
||||
return typid;
|
||||
return InvalidOid;
|
||||
}
|
||||
|
||||
/*
|
||||
* get_base_element_type
|
||||
* Given the type OID, get the typelem, looking "through" any domain
|
||||
|
Reference in New Issue
Block a user