I am running a query which is creating a view for me with following details
id name brand_id
1 E1 {3,4}
2 E2 {5,7,8}
3 E4 {1}
I want to split the records for brand_id into equal number of rows. Hence the above view should look like:
id name brand_id
1 E1 {3}
1 E1 {4}
2 E2 {5}
2 E2 {7}
2 E2 {8}
3 E4 {1}
Over here the brand_id is calculated from a subquery by matching the creation date of record with the date of brand
SQL Query:
CREATE OR REPLACE VIEW %I AS
SELECT row_number() over(),
id,
name,
(select array(select id
from brand b
where status = true and (i.creation_date = b.creation_date)
order by b asc) ) as brand_id
FROM events i
group by id order by id