【发布时间】:2015-02-17 04:46:51
【问题描述】:
我正在为 postgresql 9.3.5 编写 c-language 用户定义函数。我没有使用 pl/pgsql 或 pl/python,因为它的一部分需要用 C 编写以提高速度。
函数获取一个现有的 OID 作为参数。如何从 c 语言函数中访问和修改 OID 数据?我找不到任何文档!
到目前为止,我在函数中所拥有的只是读取参数的部分:
#include "postgres.h"
#include "fmgr.h"
PG_MODULE_MAGIC;
Datum tsdb_write_lob(PG_FUNCTION_ARGS) ;
PG_FUNCTION_INFO_V1(tsdb_write_lob);
Datum tsdb_write_lob(PG_FUNCTION_ARGS) {
int16 arg_dataformat = PG_GETARG_INT16(0);
int16 arg_granularity_days = PG_GETARG_INT16(1);
Oid arg_dataoid = PG_GETARG_OID(2);
ereport( INFO, (errcode( ERRCODE_SUCCESSFUL_COMPLETION ),
errmsg("Arguments were: %d, %d, %ld\n",arg_dataformat,arg_granularity_days,arg_dataoid)));
/*TODO:
* open oid (lo_open ?)
* read data
* decompress data
* parse data
* add new data
* compress data
* save to same oid
*/
PG_RETURN_VOID();
}
更新: 这似乎是一个例子:
https://github.com/postgres/postgres/blob/master/src/backend/libpq/be-fsstubs.c
【问题讨论】:
-
你能展示你目前拥有的东西吗?我真的觉得这很有趣,并且最近在 c 中为 PostgreSQL 做了一些扩展,所以我可以帮助你。
-
奇怪的是,用于开发 postgresql 函数的文档很少。这是运气和谷歌技能的结合。
-
是的,postgresql 的文档中几乎没有好的示例。我正要问你,你说的open oid是什么意思?
-
@iharob 相当于 lo_open()。我在 15 年前才找到这个模糊的答案:postgresql.org/message-id/7886.992327525@sss.pgh.pa.us
-
我会尝试在源代码中找到合适的函数。
标签: c postgresql