PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ pgis_geometry_accum_transfn()

Datum pgis_geometry_accum_transfn ( PG_FUNCTION_ARGS  )

Definition at line 120 of file lwgeom_accum.c.

References pgis_abs::a, pgis_abs::data, and pgis_accum_finalfn().

Referenced by pgis_abs_out().

121 {
122  Oid arg1_typeid = get_fn_expr_argtype(fcinfo->flinfo, 1);
123  MemoryContext aggcontext;
124  ArrayBuildState *state;
125  pgis_abs *p;
126  Datum elem;
127 
128  if (arg1_typeid == InvalidOid)
129  ereport(ERROR,
130  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
131  errmsg("could not determine input data type")));
132 
133  if ( ! AggCheckCallContext(fcinfo, &aggcontext) )
134  {
135  /* cannot be called directly because of dummy-type argument */
136  elog(ERROR, "%s called in non-aggregate context", __func__);
137  aggcontext = NULL; /* keep compiler quiet */
138  }
139 
140  if ( PG_ARGISNULL(0) )
141  {
142  p = (pgis_abs*) palloc(sizeof(pgis_abs));
143  p->a = NULL;
144  p->data = (Datum) NULL;
145 
146  if (PG_NARGS() == 3)
147  {
148  Datum argument = PG_GETARG_DATUM(2);
149  Oid dataOid = get_fn_expr_argtype(fcinfo->flinfo, 2);
150  MemoryContext old = MemoryContextSwitchTo(aggcontext);
151 
152  p->data = datumCopy(argument, get_typbyval(dataOid), get_typlen(dataOid));
153 
154  MemoryContextSwitchTo(old);
155  }
156  }
157  else
158  {
159  p = (pgis_abs*) PG_GETARG_POINTER(0);
160  }
161  state = p->a;
162  elem = PG_ARGISNULL(1) ? (Datum) 0 : PG_GETARG_DATUM(1);
163  state = accumArrayResult(state,
164  elem,
165  PG_ARGISNULL(1),
166  arg1_typeid,
167  aggcontext);
168  p->a = state;
169 
170  PG_RETURN_POINTER(p);
171 }
ArrayBuildState * a
Definition: lwgeom_accum.c:85
Datum data
Definition: lwgeom_accum.c:86
To pass the internal ArrayBuildState pointer between the transfn and finalfn we need to wrap it into ...
Definition: lwgeom_accum.c:83
Here is the call graph for this function:
Here is the caller graph for this function: