PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ pgis_asgeobuf_transfn()

Datum pgis_asgeobuf_transfn ( PG_FUNCTION_ARGS  )

Definition at line 46 of file lwgeom_out_geobuf.c.

47 {
48 #if ! (defined HAVE_LIBPROTOBUF && defined HAVE_GEOBUF)
49  elog(ERROR, "ST_AsGeobuf: Missing libprotobuf-c >= version 1.1");
50  PG_RETURN_NULL();
51 #else
52  MemoryContext aggcontext, oldcontext;
53  struct geobuf_agg_context *ctx;
54 
55  /* We need to initialize the internal cache to access it later via postgis_oid() */
56  postgis_initialize_cache(fcinfo);
57 
58  if (!AggCheckCallContext(fcinfo, &aggcontext))
59  elog(ERROR, "pgis_asgeobuf_transfn: called in non-aggregate context");
60  oldcontext = MemoryContextSwitchTo(aggcontext);
61 
62  if (PG_ARGISNULL(0)) {
63  ctx = palloc(sizeof(*ctx));
64 
65  ctx->geom_name = NULL;
66  if (PG_NARGS() > 2 && !PG_ARGISNULL(2))
67  ctx->geom_name = text_to_cstring(PG_GETARG_TEXT_P(2));
69  } else {
70  ctx = (struct geobuf_agg_context *) PG_GETARG_POINTER(0);
71  }
72 
73  if (!type_is_rowtype(get_fn_expr_argtype(fcinfo->flinfo, 1)))
74  elog(ERROR, "pgis_asgeobuf_transfn: parameter row cannot be other than a rowtype");
75 
76  /* Null input tuple => null result */
77  if (PG_ARGISNULL(1)) {
78  PG_RETURN_NULL();
79  }
80 
81  ctx->row = PG_GETARG_HEAPTUPLEHEADER(1);
82 
83  geobuf_agg_transfn(ctx);
84  MemoryContextSwitchTo(oldcontext);
85  PG_RETURN_POINTER(ctx);
86 #endif
87 }
void geobuf_agg_init_context(struct geobuf_agg_context *ctx)
Initialize aggregation context.
Definition: geobuf.c:541
void geobuf_agg_transfn(struct geobuf_agg_context *ctx)
Aggregation step.
Definition: geobuf.c:578
char * text_to_cstring(const text *textptr)
HeapTupleHeader row
Definition: geobuf.h:52
char * geom_name
Definition: geobuf.h:50

References geobuf_agg_init_context(), geobuf_agg_transfn(), geobuf_agg_context::geom_name, geobuf_agg_context::row, and text_to_cstring().

Here is the call graph for this function: