PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ pgis_geometry_accum_transfn()

Datum pgis_geometry_accum_transfn ( PG_FUNCTION_ARGS  )

Definition at line 122 of file lwgeom_accum.c.

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

References pgis_abs::a, and pgis_abs::data.