PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ json_categorize_type()

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

Definition at line 320 of file lwgeom_out_geojson.c.

323{
324 bool typisvarlena;
325
326 /* Look through any domain */
327 typoid = getBaseType(typoid);
328
329 *outfuncoid = InvalidOid;
330
331 /*
332 * We need to get the output function for everything except date and
333 * timestamp types, array and composite types, booleans, and non-builtin
334 * types where there's a cast to json.
335 */
336
337 switch (typoid)
338 {
339 case BOOLOID:
340 *tcategory = JSONTYPE_BOOL;
341 break;
342
343 case INT2OID:
344 case INT4OID:
345 case INT8OID:
346 case FLOAT4OID:
347 case FLOAT8OID:
348 case NUMERICOID:
349 getTypeOutputInfo(typoid, outfuncoid, &typisvarlena);
350 *tcategory = JSONTYPE_NUMERIC;
351 break;
352
353 case DATEOID:
354 *tcategory = JSONTYPE_DATE;
355 break;
356
357 case TIMESTAMPOID:
358 *tcategory = JSONTYPE_TIMESTAMP;
359 break;
360
361 case TIMESTAMPTZOID:
362 *tcategory = JSONTYPE_TIMESTAMPTZ;
363 break;
364
365 case JSONOID:
366 case JSONBOID:
367 getTypeOutputInfo(typoid, outfuncoid, &typisvarlena);
368 *tcategory = JSONTYPE_JSON;
369 break;
370
371 default:
372 /* Check for arrays and composites */
373 if (OidIsValid(get_element_type(typoid)) || typoid == ANYARRAYOID
374 || typoid == RECORDARRAYOID)
375 *tcategory = JSONTYPE_ARRAY;
376 else if (type_is_rowtype(typoid)) /* includes RECORDOID */
377 *tcategory = JSONTYPE_COMPOSITE;
378 else
379 {
380 /* It's probably the general case ... */
381 *tcategory = JSONTYPE_OTHER;
382 /* but let's look for a cast to json, if it's not built-in */
383 if (typoid >= FirstNormalObjectId)
384 {
385 Oid castfunc;
386 CoercionPathType ctype;
387
388 ctype = find_coercion_pathway(JSONOID, typoid,
389 COERCION_EXPLICIT,
390 &castfunc);
391 if (ctype == COERCION_PATH_FUNC && OidIsValid(castfunc))
392 {
393 *tcategory = JSONTYPE_CAST;
394 *outfuncoid = castfunc;
395 }
396 else
397 {
398 /* non builtin type with no cast */
399 getTypeOutputInfo(typoid, outfuncoid, &typisvarlena);
400 }
401 }
402 else
403 {
404 /* any other builtin type */
405 getTypeOutputInfo(typoid, outfuncoid, &typisvarlena);
406 }
407 }
408 break;
409 }
410}
@ 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: