PostgreSQL/開発

 ただいま作成中・・・ 

概要

定義

変数,エイリアス

マクロ

列挙型

FmgrInfo

番号データ型フィールド説明
1PGFunctionfn_addr実行される関数のポインタ
2Oidfn_oid関数のOID
3shortfn_nargs関数の引数の数
4boolfn_strict関数がstrictモードが否か。
true:strictモード,false:strictモードでない
5boolfn_retsetsetを返す関数か否か。
true:setを返す,false:setを返さない
6unsigned charfn_stats関数が統計情報を収集するか。この値より大きな値の場合に収集する。
 参考  enum TrackFunctionsLevel - on doxygen.postgresql.org
7void*fn_extra関数で利用可能な領域
8MemoryContextfn_mcxtfn_extraを格納するためのメモリコンテキスト
9fmNodePtrfn_exprパースツリーのノード表現

FunctionCallInfoData

番号データ型フィールド説明
1FmgrInfo*flinfo関数情報を保持する構造体のポインタ
2fmNodePtrcontext関数呼び出しのコンテキスト。
例:TriggerData,AggState,WindowAggState
3fmNodePtrresultinfo実行結果に関する情報。
例:ReturnSetInfo
4Oidfncollationcollation
5boolisnull結果がNULLを返すか否か。
true:返す,false:返さない
6shortnargs関数の引数の数
7Datumarg[FUNC_MAX_ARGS]引数
8boolargnull[FUNC_MAX_ARGS]arg[i]がNULLであるか否か
true:NULL,false:NULLでない

関数呼び出しに関する情報を保持する構造体。

 参考  FunctionCallInfoData - on doxygen.postgresql.org

 サンプル 

// 指定されたOIDの関数情報を取得する。
FmgrInfo *fmgr = palloc(sizeof(FmgrInfo));
fmgr_info((Oid)1396, fmgr); // abs(int64)の情報を構造体に格納する

関数

関数名

void test_invoke()
{
    Datum result;
    FunctionCallInfoData fcinfo;

    FmgrInfo *fmgr = palloc(sizeof(FmgrInfo));
    fmgr_info((Oid)1396, fmgr); // abs(int64);

    // Basic way
    int64 arg0 = -100;

    InitFunctionCallInfoData(fcinfo, fmgr, 1, 0, NULL, NULL);
    fcinfo.isnull = false;
    fcinfo.argnull[0] = false;
    fcinfo.arg[0] = Int64GetDatum(arg0);

    result = FunctionCallInvoke(&fcinfo);
    elog(INFO, "abs(-100) = %ld", DatumGetInt64(result));
}

/* Output is the following:
------------------------------
INFO:  abs(-100) = 100
*/

サンプルプログラム

#ifdef PG_MODULE_MAGIC
PG_MODULE_MAGIC;
#endif

PG_FUNCTION_INFO_V1(test_fdw_handler);
/* これは以下のように展開される
extern Datum test_fdw_handler(FunctionCallInfo fcinfo);
extern const Pg_finfo_record * pg_finfo_test_fdw_handler(void);
const Pg_finfo_record * pg_finfo_test_fdw_handler(void)
{
	static const Pg_finfo_record my_finfo = { 1 };
	return &my_finfo;
}
extern int no_such_variable;
/*

参考・関連

 関連

コメント



トップ   一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
目次
ダブルクリックで閉じるTOP | 閉じる
GO TO TOP