PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ json_categorize_type()

static void json_categorize_type ( Oid  typoid,
JsonTypeCategory tcategory,
Oid *  outfuncoid 
)
static

Definition at line 244 of file lwgeom_out_geojson.c.

247 {
248  bool typisvarlena;
249 
250  /* Look through any domain */
251  typoid = getBaseType(typoid);
252 
253  *outfuncoid = InvalidOid;
254 
255  /*
256  * We need to get the output function for everything except date and
257  * timestamp types, array and composite types, booleans, and non-builtin
258  * types where there's a cast to json.
259  */
260 
261  switch (typoid)
262  {
263  case BOOLOID:
264  *tcategory = JSONTYPE_BOOL;
265  break;
266 
267  case INT2OID:
268  case INT4OID:
269  case INT8OID:
270  case FLOAT4OID:
271  case FLOAT8OID:
272  case NUMERICOID:
273  getTypeOutputInfo(typoid, outfuncoid, &typisvarlena);
274  *tcategory = JSONTYPE_NUMERIC;
275  break;
276 
277  case DATEOID:
278  *tcategory = JSONTYPE_DATE;
279  break;
280 
281  case TIMESTAMPOID:
282  *tcategory = JSONTYPE_TIMESTAMP;
283  break;
284 
285  case TIMESTAMPTZOID:
286  *tcategory = JSONTYPE_TIMESTAMPTZ;
287  break;
288 
289  case JSONOID:
290  case JSONBOID:
291  getTypeOutputInfo(typoid, outfuncoid, &typisvarlena);
292  *tcategory = JSONTYPE_JSON;
293  break;
294 
295  default:
296  /* Check for arrays and composites */
297  if (OidIsValid(get_element_type(typoid)) || typoid == ANYARRAYOID
298  || typoid == RECORDARRAYOID)
299  *tcategory = JSONTYPE_ARRAY;
300  else if (type_is_rowtype(typoid)) /* includes RECORDOID */
301  *tcategory = JSONTYPE_COMPOSITE;
302  else
303  {
304  /* It's probably the general case ... */
305  *tcategory = JSONTYPE_OTHER;
306  /* but let's look for a cast to json, if it's not built-in */
307  if (typoid >= FirstNormalObjectId)
308  {
309  Oid castfunc;
310  CoercionPathType ctype;
311 
312  ctype = find_coercion_pathway(JSONOID, typoid,
313  COERCION_EXPLICIT,
314  &castfunc);
315  if (ctype == COERCION_PATH_FUNC && OidIsValid(castfunc))
316  {
317  *tcategory = JSONTYPE_CAST;
318  *outfuncoid = castfunc;
319  }
320  else
321  {
322  /* non builtin type with no cast */
323  getTypeOutputInfo(typoid, outfuncoid, &typisvarlena);
324  }
325  }
326  else
327  {
328  /* any other builtin type */
329  getTypeOutputInfo(typoid, outfuncoid, &typisvarlena);
330  }
331  }
332  break;
333  }
334 }
@ JSONTYPE_JSON
@ JSONTYPE_TIMESTAMP
@ JSONTYPE_NUMERIC
@ JSONTYPE_DATE
@ JSONTYPE_BOOL
@ JSONTYPE_OTHER
@ JSONTYPE_CAST
@ JSONTYPE_COMPOSITE
@ JSONTYPE_ARRAY
@ JSONTYPE_TIMESTAMPTZ

References JSONTYPE_ARRAY, JSONTYPE_BOOL, JSONTYPE_CAST, JSONTYPE_COMPOSITE, JSONTYPE_DATE, JSONTYPE_JSON, JSONTYPE_NUMERIC, JSONTYPE_OTHER, JSONTYPE_TIMESTAMP, and JSONTYPE_TIMESTAMPTZ.

Referenced by array_to_json_internal(), composite_to_geojson(), and composite_to_json().

Here is the caller graph for this function: