Suppose that I have a table with the following two columns:
create table contacts (
first_name varchar[],
last_name varchar[]
);
And I have the following two rows:
INSERT INTO contacts (first_name, last_name)
VALUES (ARRAY['Samin'] , Array['Var']),
(ARRAY['Sara', 'pooya'] , Array['Rad', 'Mohammadi']);
select * from contacts;
I want to do a query that results in the following output:
#row1: {Samin-Var}
#row2: {Sara-Rad, pooya-Mohammadi}
2
Answers
This is can done using a self-defined function in PostgreSQL.
Here we assume that the lengths of
firsts
andlasts
are the same.Usage example:
You can use a lateral join that turns the arrays into rows and aggregates them back into a the names you want:
Online example