* IntListGetPgIntArray creates a Postgres array based on given list of integers. */
| 177 | * IntListGetPgIntArray creates a Postgres array based on given list of integers. |
| 178 | */ |
| 179 | ArrayType * |
| 180 | IntListGetPgIntArray(const List *intList) |
| 181 | { |
| 182 | int nelems = list_length(intList); |
| 183 | if (nelems == 0) |
| 184 | { |
| 185 | return construct_empty_array(INT4OID); |
| 186 | } |
| 187 | |
| 188 | Datum *intDatumArray = palloc(sizeof(Datum) * nelems); |
| 189 | for (int i = 0; i < nelems; i++) |
| 190 | { |
| 191 | intDatumArray[i] = Int32GetDatum(list_nth_int(intList, i)); |
| 192 | } |
| 193 | |
| 194 | bool elmbyval = true; |
| 195 | return construct_array(intDatumArray, nelems, INT4OID, sizeof(int), |
| 196 | elmbyval, TYPALIGN_INT); |
| 197 | } |
| 198 | |
| 199 | |
| 200 | /* |
no outgoing calls
no test coverage detected