* transformArrayExpr * * If the caller specifies the target type, the resulting array will * be of exactly that type. Otherwise we try to infer a common type * for the elements using select_common_type(). */
| 2008 | * for the elements using select_common_type(). |
| 2009 | */ |
| 2010 | static Node * |
| 2011 | transformArrayExpr(ParseState *pstate, A_ArrayExpr *a, |
| 2012 | Oid array_type, Oid element_type, int32 typmod) |
| 2013 | { |
| 2014 | ArrayExpr *newa = makeNode(ArrayExpr); |
| 2015 | List *newelems = NIL; |
| 2016 | List *newcoercedelems = NIL; |
| 2017 | ListCell *element; |
| 2018 | Oid coerce_type; |
| 2019 | bool coerce_hard; |
| 2020 | |
| 2021 | /* |
| 2022 | * Transform the element expressions |
| 2023 | * |
| 2024 | * Assume that the array is one-dimensional unless we find an array-type |
| 2025 | * element expression. |
| 2026 | */ |
| 2027 | newa->multidims = false; |
| 2028 | foreach(element, a->elements) |
| 2029 | { |
| 2030 | Node *e = (Node *) lfirst(element); |
| 2031 | Node *newe; |
| 2032 | |
| 2033 | /* |
| 2034 | * If an element is itself an A_ArrayExpr, recurse directly so that we |
| 2035 | * can pass down any target type we were given. |
| 2036 | */ |
| 2037 | if (IsA(e, A_ArrayExpr)) |
| 2038 | { |
| 2039 | newe = transformArrayExpr(pstate, |
| 2040 | (A_ArrayExpr *) e, |
| 2041 | array_type, |
| 2042 | element_type, |
| 2043 | typmod); |
| 2044 | /* we certainly have an array here */ |
| 2045 | Assert(array_type == InvalidOid || array_type == exprType(newe)); |
| 2046 | newa->multidims = true; |
| 2047 | } |
| 2048 | else |
| 2049 | { |
| 2050 | newe = transformExprRecurse(pstate, e); |
| 2051 | |
| 2052 | /* |
| 2053 | * Check for sub-array expressions, if we haven't already found |
| 2054 | * one. |
| 2055 | */ |
| 2056 | if (!newa->multidims && type_is_array(exprType(newe))) |
| 2057 | newa->multidims = true; |
| 2058 | } |
| 2059 | |
| 2060 | newelems = lappend(newelems, newe); |
| 2061 | } |
| 2062 | |
| 2063 | /* |
| 2064 | * Select a target type for the elements. |
| 2065 | * |
| 2066 | * If we haven't been given a target array type, we must try to deduce a |
| 2067 | * common type based on the types of the individual elements present. |
no test coverage detected