I was wondering if I could just add minvfunc, and have the rest of the m*
functions be assumed to be the same as their non-moving counterparts.
Apparently the answer is 'no'.  But in the process, I found a bad error
message.  When omitting mfinalfunc when there is a finalfunc, I get the
error:

"ERROR:  moving-aggregate implementation returns type jj_state, but plain
implementation returns type jj_state."  A rather peculiar
complaint, analogous to the infamous "something failed: Success".

Looking at the code, it seems we are testing rettype != finaltype, but
reporting aggmTransType and aggTransType.  Why aren't we reporting what we
are testing?

With the attached patch, it gives the more sensible "ERROR:
 moving-aggregate implementation returns type jj_state, but plain
implementation returns type numeric."

Cheers,

Jeff
drop type jj_state cascade;

CREATE TYPE jj_state AS ( x numeric, y numeric);


CREATE OR REPLACE FUNCTION jj_transition(
  state jj_state,
  val numeric
) RETURNS jj_state AS $$
BEGIN
  RETURN NULL::jj_state;
END;
$$ LANGUAGE plpgsql;

CREATE OR REPLACE FUNCTION jj_final(
  state jj_state
) RETURNS numeric AS $$
BEGIN
  RETURN 5.5;
END;
$$ LANGUAGE plpgsql;

CREATE OR REPLACE FUNCTION jj_inverse(state jj_state, val numeric)
RETURNS jj_state AS $$
BEGIN
  RETURN NULL::jj_state;
END;
$$ LANGUAGE plpgsql;

CREATE AGGREGATE jj(numeric) (
  sfunc      = jj_transition,
  stype      = jj_state,
  finalfunc  = jj_final,
  initcond   = '(0,0)',
  msfunc     = jj_transition,
  minvfunc   = jj_inverse,
  mstype     = jj_state
  -- mfinalfunc = average_final
);

Attachment: moving_agg_error.patch
Description: Binary data

Reply via email to