Re: Coalesce 2 Arrays
От | Rob Sargent |
---|---|
Тема | Re: Coalesce 2 Arrays |
Дата | |
Msg-id | 53ea4b16-4a57-e8c9-a27c-5de130375e7c@gmail.com обсуждение исходный текст |
Ответ на | Re: Coalesce 2 Arrays (Alex Magnum <magnum11200@gmail.com>) |
Ответы |
Re: Coalesce 2 Arrays
|
Список | pgsql-general |
On 6/24/19 4:46 PM, Alex Magnum wrote:
create or replace function tt( a1 int[], a2 int[])Yes, they are.On Tue, Jun 25, 2019 at 4:33 AM Rob Sargent <robjsargent@gmail.com> wrote:Are the inputs always of fixed dimensions eg. 1 by 7?On Jun 24, 2019, at 2:31 PM, Alex Magnum <magnum11200@gmail.com> wrote:Hi,
I have two arrays which I need to combine based on the individual values;i could do a coalesce for each field but was wondering if there is an easier wayarray_a{a, null,c, d,null,f,null} primaryarray_b{null,2 ,null,4,5 ,6,null} secondaryresult {a, 2, c, d,5, f,null)Any advice would be appreciated
returns int[] as $$
declare
aret int[];
asize int;
begin
select array_length(a1,1) into asize;
for i in 1..asize loop
aret[i] = coalesce(a1[i], a2[i]);
end loop;
return aret;
end;
$$ language plpgsql;
select * from tt(array[3,null], array[null,4]);
tt
-------
{3,4}
(1 row)
В списке pgsql-general по дате отправления: