15 lines
368 B
Text
15 lines
368 B
Text
create or replace function equilibrium_indices(lst) as table (
|
|
with recursive cte as (
|
|
select 0 as ix, 0 as before, 0 as pivotor, list_sum(lst) as after
|
|
union all
|
|
select ix+1,
|
|
before+pivotor,
|
|
lst[ix+1],
|
|
after - lst[ix+1]
|
|
from cte
|
|
where ix<length(lst)
|
|
)
|
|
select ix
|
|
from cte
|
|
where before = after and ix>0
|
|
);
|