typedef Datum (*PGFunction) (FunctionCallInfo fcinfo);
/* *Thisstructholdsthesystem-cataloginformationthatmustbelookedup *beforeafunctioncanbecalledthroughfmgr.Ifthesamefunctionis *tobecalledmultipletimes,thelookupneedbedoneonlyonceandthe *infostructsavedforre-use. * *Notethatfn_exprreallyisparse-time-determinedinformationaboutthe *arguments,ratherthanaboutthefunctionitself.Butit'sconvenientto *storeithereratherthaninFunctionCallInfoBaseData,whereitmightmore *logicallybelong. * *fn_extraisavailableforusebythecalledfunction;allotherfields *shouldbetreatedasread-onlyafterthestructiscreated.
*/ typedefstruct FmgrInfo
{
PGFunction fn_addr; /* pointer to function or handler to be called */
Oid fn_oid; /* OID of function (NOT of handler, if any) */ short fn_nargs; /* number of input args (0..FUNC_MAX_ARGS) */ bool fn_strict; /* function is "strict" (NULL in => NULL out) */ bool fn_retset; /* function returns a set */ unsignedchar fn_stats; /* collect stats if track_functions > this */ void *fn_extra; /* extra space for use by handler */
MemoryContext fn_mcxt; /* memory context to store fn_extra in */
fmNodePtr fn_expr; /* expression parse tree for call, or NULL */
} FmgrInfo;
/* *Thisstructisthedataactuallypassedtoanfmgr-calledfunction. * *Thecalledfunctionisexpectedtosetisnull,andpossiblyresultinfoor *fieldsinwhateverresultinfopointsto.Itshouldnotchangeanyother *fields.(Inparticular,scribblingontheargumentarraysisabadidea, *sincesomecallersassumetheycanre-callwiththesamearguments.) * *Notethatenoughspaceforargumentsneedstobeprovided,eitherbyusing *SizeForFunctionCallInfo()indynamicallocations,orbyusing *LOCAL_FCINFO()foron-stackallocations. * *Thisstructisnamed*BaseData,ratherthan*Data,tobreakprev12code *thatallocatedFunctionCallInfoDataitself,asit'doftensilentlybreak *oldcodeduetonospaceforargumentsbeingprovided.
*/ typedefstruct FunctionCallInfoBaseData
{
FmgrInfo *flinfo; /* ptr to lookup info used for this call */
fmNodePtr context; /* pass info about context of call */
fmNodePtr resultinfo; /* pass or return extra info about result */
Oid fncollation; /* collation for function to use */ #define FIELDNO_FUNCTIONCALLINFODATA_ISNULL 4 bool isnull; /* function must set true if result is NULL */ short nargs; /* # arguments actually passed */ #define FIELDNO_FUNCTIONCALLINFODATA_ARGS 6
NullableDatum args[FLEXIBLE_ARRAY_MEMBER];
} FunctionCallInfoBaseData;
/* *Thismacroensuresthat`name`pointstoastack-allocated *FunctionCallInfoBaseDatastructwithsufficientspacefor`nargs`arguments.
*/ #define LOCAL_FCINFO(name, nargs) \ /* use union with FunctionCallInfoBaseData to guarantee alignment */ \ union \
{ \
FunctionCallInfoBaseData fcinfo; \ /* ensure enough space for nargs args is available */ \ char fcinfo_data[SizeForFunctionCallInfo(nargs)]; \
} name##data; \
FunctionCallInfo name = &name##data.fcinfo
/* *Supportforcleaningupdetoastedcopiesofinputs.Thismustonly *beusedforpass-by-refdatatypes,andnormallywouldonlybeused *fortoastabletypes.Ifthegivenpointerisdifferentfromthe *originalargument,assumeit'sapalloc'ddetoastedcopy,andpfreeit. *NOTE:mostfunctionsontoastabletypesdonothavetoworryaboutthis, *butwecurrentlyrequirethatsupportfunctionsforindexesnotleak *memory.
*/ #define PG_FREE_IF_COPY(ptr,n) \ do { \ if ((Pointer) (ptr) != PG_GETARG_POINTER(n)) \
pfree(ptr); \
} while (0)
/* Macros for fetching arguments of standard types */
#define PG_GETARG_DATUM(n) (fcinfo->args[n].value) #define PG_GETARG_INT32(n) DatumGetInt32(PG_GETARG_DATUM(n)) #define PG_GETARG_UINT32(n) DatumGetUInt32(PG_GETARG_DATUM(n)) #define PG_GETARG_INT16(n) DatumGetInt16(PG_GETARG_DATUM(n)) #define PG_GETARG_UINT16(n) DatumGetUInt16(PG_GETARG_DATUM(n)) #define PG_GETARG_CHAR(n) DatumGetChar(PG_GETARG_DATUM(n)) #define PG_GETARG_BOOL(n) DatumGetBool(PG_GETARG_DATUM(n)) #define PG_GETARG_OID(n) DatumGetObjectId(PG_GETARG_DATUM(n)) #define PG_GETARG_POINTER(n) DatumGetPointer(PG_GETARG_DATUM(n)) #define PG_GETARG_CSTRING(n) DatumGetCString(PG_GETARG_DATUM(n)) #define PG_GETARG_NAME(n) DatumGetName(PG_GETARG_DATUM(n)) #define PG_GETARG_TRANSACTIONID(n) DatumGetTransactionId(PG_GETARG_DATUM(n)) /* these macros hide the pass-by-reference-ness of the datatype: */ #define PG_GETARG_FLOAT4(n) DatumGetFloat4(PG_GETARG_DATUM(n)) #define PG_GETARG_FLOAT8(n) DatumGetFloat8(PG_GETARG_DATUM(n)) #define PG_GETARG_INT64(n) DatumGetInt64(PG_GETARG_DATUM(n)) /* use this if you want the raw, possibly-toasted input datum: */ #define PG_GETARG_RAW_VARLENA_P(n) ((struct varlena *) PG_GETARG_POINTER(n)) /* use this if you want the input datum de-toasted: */ #define PG_GETARG_VARLENA_P(n) PG_DETOAST_DATUM(PG_GETARG_DATUM(n)) /* and this if you can handle 1-byte-header datums: */ #define PG_GETARG_VARLENA_PP(n) PG_DETOAST_DATUM_PACKED(PG_GETARG_DATUM(n)) /* DatumGetFoo macros for varlena types will typically look like this: */ #define DatumGetByteaPP(X) ((bytea *) PG_DETOAST_DATUM_PACKED(X)) #define DatumGetTextPP(X) ((text *) PG_DETOAST_DATUM_PACKED(X)) #define DatumGetBpCharPP(X) ((BpChar *) PG_DETOAST_DATUM_PACKED(X)) #define DatumGetVarCharPP(X) ((VarChar *) PG_DETOAST_DATUM_PACKED(X)) #define DatumGetHeapTupleHeader(X) ((HeapTupleHeader) PG_DETOAST_DATUM(X)) /* And we also offer variants that return an OK-to-write copy */ #define DatumGetByteaPCopy(X) ((bytea *) PG_DETOAST_DATUM_COPY(X)) #define DatumGetTextPCopy(X) ((text *) PG_DETOAST_DATUM_COPY(X)) #define DatumGetBpCharPCopy(X) ((BpChar *) PG_DETOAST_DATUM_COPY(X)) #define DatumGetVarCharPCopy(X) ((VarChar *) PG_DETOAST_DATUM_COPY(X)) #define DatumGetHeapTupleHeaderCopy(X) ((HeapTupleHeader) PG_DETOAST_DATUM_COPY(X)) /* Variants which return n bytes starting at pos. m */ #define DatumGetByteaPSlice(X,m,n) ((bytea *) PG_DETOAST_DATUM_SLICE(X,m,n)) #define DatumGetTextPSlice(X,m,n) ((text *) PG_DETOAST_DATUM_SLICE(X,m,n)) #define DatumGetBpCharPSlice(X,m,n) ((BpChar *) PG_DETOAST_DATUM_SLICE(X,m,n)) #define DatumGetVarCharPSlice(X,m,n) ((VarChar *) PG_DETOAST_DATUM_SLICE(X,m,n)) /* GETARG macros for varlena types will typically look like this: */ #define PG_GETARG_BYTEA_PP(n) DatumGetByteaPP(PG_GETARG_DATUM(n)) #define PG_GETARG_TEXT_PP(n) DatumGetTextPP(PG_GETARG_DATUM(n)) #define PG_GETARG_BPCHAR_PP(n) DatumGetBpCharPP(PG_GETARG_DATUM(n)) #define PG_GETARG_VARCHAR_PP(n) DatumGetVarCharPP(PG_GETARG_DATUM(n)) #define PG_GETARG_HEAPTUPLEHEADER(n) DatumGetHeapTupleHeader(PG_GETARG_DATUM(n)) /* And we also offer variants that return an OK-to-write copy */ #define PG_GETARG_BYTEA_P_COPY(n) DatumGetByteaPCopy(PG_GETARG_DATUM(n)) #define PG_GETARG_TEXT_P_COPY(n) DatumGetTextPCopy(PG_GETARG_DATUM(n)) #define PG_GETARG_BPCHAR_P_COPY(n) DatumGetBpCharPCopy(PG_GETARG_DATUM(n)) #define PG_GETARG_VARCHAR_P_COPY(n) DatumGetVarCharPCopy(PG_GETARG_DATUM(n)) #define PG_GETARG_HEAPTUPLEHEADER_COPY(n) DatumGetHeapTupleHeaderCopy(PG_GETARG_DATUM(n)) /* And a b-byte slice from position a -also OK to write */ #define PG_GETARG_BYTEA_P_SLICE(n,a,b) DatumGetByteaPSlice(PG_GETARG_DATUM(n),a,b) #define PG_GETARG_TEXT_P_SLICE(n,a,b) DatumGetTextPSlice(PG_GETARG_DATUM(n),a,b) #define PG_GETARG_BPCHAR_P_SLICE(n,a,b) DatumGetBpCharPSlice(PG_GETARG_DATUM(n),a,b) #define PG_GETARG_VARCHAR_P_SLICE(n,a,b) DatumGetVarCharPSlice(PG_GETARG_DATUM(n),a,b) /* *ObsolescentvariantsthatguaranteeINTalignmentforthereturnvalue. *Fewoperationsontheseparticulartypesneedalignment,mainlyoperations *thatcasttheVARDATApointertoatypelikeint16[].Mostcodeshoulduse *the...PP(X)counterpart.Nonetheless,theseappearfrequentlyincode *predatingthePostgreSQL8.3introductionofthe...PP(X)variants.
*/ #define DatumGetByteaP(X) ((bytea *) PG_DETOAST_DATUM(X)) #define DatumGetTextP(X) ((text *) PG_DETOAST_DATUM(X)) #define DatumGetBpCharP(X) ((BpChar *) PG_DETOAST_DATUM(X)) #define DatumGetVarCharP(X) ((VarChar *) PG_DETOAST_DATUM(X)) #define PG_GETARG_BYTEA_P(n) DatumGetByteaP(PG_GETARG_DATUM(n)) #define PG_GETARG_TEXT_P(n) DatumGetTextP(PG_GETARG_DATUM(n)) #define PG_GETARG_BPCHAR_P(n) DatumGetBpCharP(PG_GETARG_DATUM(n)) #define PG_GETARG_VARCHAR_P(n) DatumGetVarCharP(PG_GETARG_DATUM(n))
/* To access options from opclass support functions use this: */ #define PG_HAS_OPCLASS_OPTIONS() has_fn_opclass_options(fcinfo->flinfo) #define PG_GET_OPCLASS_OPTIONS() get_fn_opclass_options(fcinfo->flinfo)
/* To return a NULL do this: */ #define PG_RETURN_NULL() \ do { fcinfo->isnull = true; return (Datum) 0; } while (0)
/* A few internal functions return void (which is not the same as NULL!) */ #define PG_RETURN_VOID() return (Datum) 0
/* Macros for returning results of standard types */
typedefstruct
{ int api_version; /* specifies call convention version number */ /* More fields may be added later, for version numbers > 1. */
} Pg_finfo_record;
/* Expected signature of an info function */ typedefconst Pg_finfo_record *(*PGFInfoFunction) (void);
/* Definition of the values we check to verify ABI compatibility */ typedefstruct
{ int version; /* PostgreSQL major version */ int funcmaxargs; /* FUNC_MAX_ARGS */ int indexmaxkeys; /* INDEX_MAX_KEYS */ int namedatalen; /* NAMEDATALEN */ int float8byval; /* FLOAT8PASSBYVAL */ char abi_extra[32]; /* see pg_config_manual.h */
} Pg_abi_values;
/* Definition of the magic block structure */ typedefstruct
{ int len; /* sizeof(this struct) */
Pg_abi_values abi_fields; /* see above */ /* Remaining fields are zero unless filled via PG_MODULE_MAGIC_EXT */ constchar *name; /* optional module name */ constchar *version; /* optional module version */
} Pg_magic_struct;
/* Macro to fill the ABI fields */ #define PG_MODULE_ABI_DATA \
{ \
PG_VERSION_NUM / 100, \
FUNC_MAX_ARGS, \
INDEX_MAX_KEYS, \
NAMEDATALEN, \
FLOAT8PASSBYVAL, \
FMGR_ABI_EXTRA, \
}
/* These are for invocation of a specifically named function with a *directly-computedparameterlist.Notethatneitherargumentsnorresult *areallowedtobeNULL.Also,thefunctioncannotbeonethatneedsto *lookatFmgrInfo,sincetherewon'tbeany.
*/ extern Datum DirectFunctionCall1Coll(PGFunction func, Oid collation,
Datum arg1); extern Datum DirectFunctionCall2Coll(PGFunction func, Oid collation,
Datum arg1, Datum arg2); extern Datum DirectFunctionCall3Coll(PGFunction func, Oid collation,
Datum arg1, Datum arg2,
Datum arg3); extern Datum DirectFunctionCall4Coll(PGFunction func, Oid collation,
Datum arg1, Datum arg2,
Datum arg3, Datum arg4); extern Datum DirectFunctionCall5Coll(PGFunction func, Oid collation,
Datum arg1, Datum arg2,
Datum arg3, Datum arg4, Datum arg5); extern Datum DirectFunctionCall6Coll(PGFunction func, Oid collation,
Datum arg1, Datum arg2,
Datum arg3, Datum arg4, Datum arg5,
Datum arg6); extern Datum DirectFunctionCall7Coll(PGFunction func, Oid collation,
Datum arg1, Datum arg2,
Datum arg3, Datum arg4, Datum arg5,
Datum arg6, Datum arg7); extern Datum DirectFunctionCall8Coll(PGFunction func, Oid collation,
Datum arg1, Datum arg2,
Datum arg3, Datum arg4, Datum arg5,
Datum arg6, Datum arg7, Datum arg8); extern Datum DirectFunctionCall9Coll(PGFunction func, Oid collation,
Datum arg1, Datum arg2,
Datum arg3, Datum arg4, Datum arg5,
Datum arg6, Datum arg7, Datum arg8,
Datum arg9);
/* *ThesefunctionsworkliketheDirectFunctionCallfunctionsexceptthat *theyusetheflinfoparametertoinitialisethefcinfoforthecall. *It'srecommendedthatthecalleeonlyusethefn_extraandfn_mcxt *fields,asotherfieldswilltypicallydescribethecallingfunction *notthecallee.Conversely,thecallingfunctionshouldnothave *usedfn_extra,unlessitsuseisknowntobecompatiblewiththecallee's.
*/ extern Datum CallerFInfoFunctionCall1(PGFunction func, FmgrInfo *flinfo,
Oid collation, Datum arg1); extern Datum CallerFInfoFunctionCall2(PGFunction func, FmgrInfo *flinfo,
Oid collation, Datum arg1, Datum arg2);
/* These are for invocation of a previously-looked-up function with a *directly-computedparameterlist.Notethatneitherargumentsnorresult *areallowedtobeNULL.
*/ extern Datum FunctionCall0Coll(FmgrInfo *flinfo, Oid collation); extern Datum FunctionCall1Coll(FmgrInfo *flinfo, Oid collation,
Datum arg1); extern Datum FunctionCall2Coll(FmgrInfo *flinfo, Oid collation,
Datum arg1, Datum arg2); extern Datum FunctionCall3Coll(FmgrInfo *flinfo, Oid collation,
Datum arg1, Datum arg2,
Datum arg3); extern Datum FunctionCall4Coll(FmgrInfo *flinfo, Oid collation,
Datum arg1, Datum arg2,
Datum arg3, Datum arg4); extern Datum FunctionCall5Coll(FmgrInfo *flinfo, Oid collation,
Datum arg1, Datum arg2,
Datum arg3, Datum arg4, Datum arg5); extern Datum FunctionCall6Coll(FmgrInfo *flinfo, Oid collation,
Datum arg1, Datum arg2,
Datum arg3, Datum arg4, Datum arg5,
Datum arg6); extern Datum FunctionCall7Coll(FmgrInfo *flinfo, Oid collation,
Datum arg1, Datum arg2,
Datum arg3, Datum arg4, Datum arg5,
Datum arg6, Datum arg7); extern Datum FunctionCall8Coll(FmgrInfo *flinfo, Oid collation,
Datum arg1, Datum arg2,
Datum arg3, Datum arg4, Datum arg5,
Datum arg6, Datum arg7, Datum arg8); extern Datum FunctionCall9Coll(FmgrInfo *flinfo, Oid collation,
Datum arg1, Datum arg2,
Datum arg3, Datum arg4, Datum arg5,
Datum arg6, Datum arg7, Datum arg8,
Datum arg9);
/* These are for invocation of a function identified by OID with a *directly-computedparameterlist.Notethatneitherargumentsnorresult *areallowedtobeNULL.Theseareessentiallyfmgr_info()followedby *FunctionCallN().Ifthesamefunctionistobeinvokedrepeatedly,dothe *fmgr_info()onceandthenuseFunctionCallN().
*/ extern Datum OidFunctionCall0Coll(Oid functionId, Oid collation); extern Datum OidFunctionCall1Coll(Oid functionId, Oid collation,
Datum arg1); extern Datum OidFunctionCall2Coll(Oid functionId, Oid collation,
Datum arg1, Datum arg2); extern Datum OidFunctionCall3Coll(Oid functionId, Oid collation,
Datum arg1, Datum arg2,
Datum arg3); extern Datum OidFunctionCall4Coll(Oid functionId, Oid collation,
Datum arg1, Datum arg2,
Datum arg3, Datum arg4); extern Datum OidFunctionCall5Coll(Oid functionId, Oid collation,
Datum arg1, Datum arg2,
Datum arg3, Datum arg4, Datum arg5); extern Datum OidFunctionCall6Coll(Oid functionId, Oid collation,
Datum arg1, Datum arg2,
Datum arg3, Datum arg4, Datum arg5,
Datum arg6); extern Datum OidFunctionCall7Coll(Oid functionId, Oid collation,
Datum arg1, Datum arg2,
Datum arg3, Datum arg4, Datum arg5,
Datum arg6, Datum arg7); extern Datum OidFunctionCall8Coll(Oid functionId, Oid collation,
Datum arg1, Datum arg2,
Datum arg3, Datum arg4, Datum arg5,
Datum arg6, Datum arg7, Datum arg8); extern Datum OidFunctionCall9Coll(Oid functionId, Oid collation,
Datum arg1, Datum arg2,
Datum arg3, Datum arg4, Datum arg5,
Datum arg6, Datum arg7, Datum arg8,
Datum arg9);
/* AggCheckCallContext can return one of the following codes, or 0: */ #define AGG_CONTEXT_AGGREGATE 1/* regular aggregate */ #define AGG_CONTEXT_WINDOW 2/* window function */
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.