Is there a way to concatenate multiple arrays into one array in Postgres?
For example, something like this:
ARRAY_CAT(
ARRAY_FILL(5, ARRAY[4]),
ARRAY_FILL(2, ARRAY[3]),
ARRAY_FILL(11, ARRAY[3])
)
For this example, I'd like to see an output of
[5,5,5,5,2,2,2,11,11,11]
Unnest function generates a table structure of an array in PostgreSQL. Unnest array function is beneficial in PostgreSQL for expanding the array into the set of values or converting the array into the structure of the rows. PostgreSQL offers unnest() function.
PostgreSQL ARRAY_AGG() function is an aggregate function that accepts a set of values and returns an array where each value in the input set is assigned to an element of the array. Syntax: ARRAY_AGG(expression [ORDER BY [sort_expression {ASC | DESC}], [...])
PostgreSQL allows us to define a table column as an array type. The array must be of a valid data type such as integer, character, or user-defined types. To insert values into an array column, we use the ARRAY constructor.
To find PostgreSQL array elements using where clause To filter the rows, we can use the array element in the WHERE clause as the condition. In the following example, we will use the below command to identify those people who has the mobile_number (308)-589-23458 as the second mobile number: SELECT person_name.
Use the ||
concatenation operator
select
array_fill(5, array[4]) ||
array_fill(2, array[3]) ||
array_fill(11, array[3])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With