I need to copy all data from one column customerId
to another new column (customerIds
– which is in different format) in the same table. There is a column called customerId
whose type is bigint
and I need to copy data from this column to customerIds
whose data type is bigint[]
.
Is there any way to do this in postgres sql? I know how to copy data from one column to other column which is in same format but not sure how to do this when new column is array.
Same table and column is in same format.
UPDATE table_name
SET customerId = customerIds
2
Answers
As you have only one id per customer you can update simply the forst element of the array
fiddle
maybe this helps:
with cte as (Select 4::BIGINT as num )
SELECT array_agg(cte.num) from cte;
for your problem:
UPDATE table_name
SET customerId = arrag_agg(customerIds)
answer is just an idea. not tested