Postgres- update a value in a array on particular index I have a column named ids that is of type bigint[]. ids cane be null or of any length

It has values based on certain hierarchy.

My use case is I want to update value that is at a particular index.
For example ids[2] = 50.

How can I achieve this?

I looked at this https://www.postgresql.org/docs/current/functions-array.html#ARRAY-FUNCTIONS-TABLE
but couldn't find anything that could help.

Thanks in advance.
Indeed there is no such function, but you can easily write your own:

create function array_set(p_input anyarray, p_index int, p_new_value anyelement)
  returns anyarray
as
$$
begin
  if p_input is not null then
    p_input[p_index] := p_new_value;
  end if;
  return p_input;
end;
$$
language plpgsql
immutable;


(If you never need it for anything different than bigint[] then you can replace the anyelement and anyarray with the equivalent types)

Then you can use it like this:

update the_table
  set ids = array_set(ids, 2, 50::bigint)
where ...;