title: custom aggregate function in postgres return NULL value
body: <p>in order to create a more complex custom aggregate function, i followed first this <a href="https://hashrocket.com/blog/posts/custom-aggregates-in-postgresql" rel="nofollow noreferrer">amazing tutorial</a>.</p>
  <p>Here the data i use :</p>
  <pre><code>create table entries(
    id serial primary key,
    amount float8 not null
  );
  
  select setseed(0);
  
  insert into entries(amount)
  select (2000 * random()) - 1000
  from generate_series(1, 1000000);
  </code></pre>
  <p>So I have this table :</p>
  <pre><code> id      |        amount         |   running_total
  ---------+-----------------------+--------------------
         1 |     -462.016298435628 |  -462.016298435628
         2 |      162.440904416144 |  -299.575394019485
         3 |     -820.292402990162 |  -1119.86779700965
         4 |     -866.230697371066 |  -1986.09849438071
         5 |      -495.30001822859 |   -2481.3985126093
         6 |      772.393747232854 |  -1709.00476537645
         7 |     -323.866365477443 |  -2032.87113085389
         8 |     -856.917716562748 |  -2889.78884741664
         9 |      285.323366522789 |  -2604.46548089385
        10 |     -867.916810326278 |  -3472.38229122013
  -- snip --
  </code></pre>
  <p>And I would like the max of the <code>running_total</code> column<br />
  (I know I can do do it without a new aggregate function, but it's for the demonstration)</p>
  <p>So i've made this aggregate function</p>
  <pre><code>create or replace function grt_sfunc(agg_state point, el float8)
  returns point
  immutable
  language plpgsql
  as $$
  declare
    greatest_sum float8;
    current_sum float8;
  begin
      current_sum := agg_state[0] + el;
      greatest_sum := 40;
      /*if agg_state[1] &lt; current_sum then
          greatest_sum := current_sum;
      else
          greatest_sum := agg_state[1];
      end if;*/
      return point(current_sum, greatest_sum);
      /*return point(3.14159, 0);*/
  end;
  $$;
  
  create or replace function grt_finalfunc(agg_state point)
  returns float8
  immutable
  strict
  language plpgsql
  as $$
  begin
    return agg_state[0];
  end;
  $$;
  
  create or replace aggregate greatest_running_total (float8)
  (
      sfunc = grt_sfunc,
      stype = point,
      finalfunc = grt_finalfunc
  );
  </code></pre>
  <p>Normally it sould work, but in the end, it gives me a null result :</p>
  <pre><code>select greatest_running_total(amount order by id asc)
  from entries;
  
  
  id    |  running_total
  ---------+---------------
      1 |  [NULL]
  </code></pre>
  <p>I tried to change the type of the data, to check the 2 first aggregate functions separately, they are working well. Does someone could help me find a solution please ? :)</p>
  <p>Thank you very much !</p>