array cast
PG 7.4+→ target type arrayCasts an array to another array type by applying the element-wise cast.
Signatures
text[]::integer[] → integer[]ARRAY[...]::type[] → type[]Parameters
| Parameter | Type | Description |
|---|---|---|
| expression | array | Source array |
Examples
SELECT ARRAY['1','2','3']::integer[];{1,2,3}SELECT '{2025-01-01,2025-06-15}'::date[];{2025-01-01,2025-06-15}SELECT ARRAY['3.14','2.71']::numeric[];{3.14,2.71}Upcast integer array to bigint
SELECT ARRAY[1,2,3]::bigint[];{1,2,3}If any single element of a text array is not a valid integer (e.g., empty string or non-numeric text), the entire `::integer[]` cast fails with no partial result.
✓ Instead: Validate or clean the array elements first using `array_remove` or `unnest` + CASE filtering before casting, to avoid whole-batch failures from a single dirty value.
When using `string_to_array` to split CSV input, cast the result to a typed array in one step: `string_to_array('1,2,3', ',')::integer[]`.
SELECT string_to_array(csv_ids, ',')::bigint[] AS id_array FROM imports;Properly typed bigint arrays from CSV