Line data Source code
1 : /*------------------------------------------------------------------------- 2 : * 3 : * pg_dependencies.c 4 : * pg_dependencies data type support. 5 : * 6 : * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group 7 : * Portions Copyright (c) 1994, Regents of the University of California 8 : * 9 : * IDENTIFICATION 10 : * src/backend/utils/adt/pg_dependencies.c 11 : * 12 : *------------------------------------------------------------------------- 13 : */ 14 : 15 : #include "postgres.h" 16 : 17 : #include "lib/stringinfo.h" 18 : #include "statistics/extended_stats_internal.h" 19 : #include "utils/fmgrprotos.h" 20 : 21 : /* 22 : * pg_dependencies_in - input routine for type pg_dependencies. 23 : * 24 : * pg_dependencies is real enough to be a table column, but it has no operations 25 : * of its own, and disallows input too 26 : */ 27 : Datum 28 0 : pg_dependencies_in(PG_FUNCTION_ARGS) 29 : { 30 : /* 31 : * pg_node_list stores the data in binary form and parsing text input is 32 : * not needed, so disallow this. 33 : */ 34 0 : ereport(ERROR, 35 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), 36 : errmsg("cannot accept a value of type %s", "pg_dependencies"))); 37 : 38 : PG_RETURN_VOID(); /* keep compiler quiet */ 39 : } 40 : 41 : /* 42 : * pg_dependencies_out - output routine for type pg_dependencies. 43 : */ 44 : Datum 45 16 : pg_dependencies_out(PG_FUNCTION_ARGS) 46 : { 47 16 : bytea *data = PG_GETARG_BYTEA_PP(0); 48 16 : MVDependencies *dependencies = statext_dependencies_deserialize(data); 49 : int i, 50 : j; 51 : StringInfoData str; 52 : 53 16 : initStringInfo(&str); 54 16 : appendStringInfoChar(&str, '{'); 55 : 56 96 : for (i = 0; i < dependencies->ndeps; i++) 57 : { 58 80 : MVDependency *dependency = dependencies->deps[i]; 59 : 60 80 : if (i > 0) 61 64 : appendStringInfoString(&str, ", "); 62 : 63 80 : appendStringInfoChar(&str, '"'); 64 272 : for (j = 0; j < dependency->nattributes; j++) 65 : { 66 192 : if (j == dependency->nattributes - 1) 67 80 : appendStringInfoString(&str, " => "); 68 112 : else if (j > 0) 69 32 : appendStringInfoString(&str, ", "); 70 : 71 192 : appendStringInfo(&str, "%d", dependency->attributes[j]); 72 : } 73 80 : appendStringInfo(&str, "\": %f", dependency->degree); 74 : } 75 : 76 16 : appendStringInfoChar(&str, '}'); 77 : 78 16 : PG_RETURN_CSTRING(str.data); 79 : } 80 : 81 : /* 82 : * pg_dependencies_recv - binary input routine for type pg_dependencies. 83 : */ 84 : Datum 85 0 : pg_dependencies_recv(PG_FUNCTION_ARGS) 86 : { 87 0 : ereport(ERROR, 88 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), 89 : errmsg("cannot accept a value of type %s", "pg_dependencies"))); 90 : 91 : PG_RETURN_VOID(); /* keep compiler quiet */ 92 : } 93 : 94 : /* 95 : * pg_dependencies_send - binary output routine for type pg_dependencies. 96 : * 97 : * Functional dependencies are serialized in a bytea value (although the type 98 : * is named differently), so let's just send that. 99 : */ 100 : Datum 101 0 : pg_dependencies_send(PG_FUNCTION_ARGS) 102 : { 103 0 : return byteasend(fcinfo); 104 : }