我正在使用postgressql。从文件中读取数据并使用pg_bulkload-C过滤器加载它。根据文档,C过滤器比SQL过滤器快得多。
我是C.的新手。通过此文档。不清楚,如何开始。
https://www.postgresql.org/docs/current/static/xfunc-c.html
有人可以指导我创建C代码,以便可以在postgres函数中调用吗?
以下是示例数据。文件没有标题。
Sample Data:
ABC|20170101|DEF ||GHIJ|KLM
Target Table Definition:
COLA numeric(5,0)
COLB date
COLC text
COLD text
COLE text
First column should be mapped to COLA
Second column should be mapped to COLB
Third column should be mapped to COLD
Fourth column should be mapped to COLC
Fifth column should be mapped to Some default value(column is not present in source)
Transformation:
a)First column should be mapped to COLA. It is numeric in target table. If any alpha-characters were present, default this column with '0'. Otherwise, source value should be moved to table.
b)Second column should be mapped to COLB. TO_DATE function from text format. File will have date format as YYYYMMDD. It should be converted to date.
c)Third column should be mapped to COLD.Need to Trim both leading and trailing spaces.
d)Fourth column should be mapped to COLC. If it NULL, some value should be defaulted.
e)Only few columns from source file should be loaded. In this case, only first four columns should be loaded.
f)Different ordering in source files & target columns.In this case,
Third column should be mapped to COLD
Fourth column should be mapped to COLC
g)COLE should be loaded with default value. This column is not present in source file.
将所有数据加载为varchar和nullable后,可以使用查询处理这些转换。但是我们需要在加载之前处理这个问题,就像我们在Oracle中一样。
您认为,使用C编程可以实现这些功能吗?编写这些功能的一些标准语法将非常有用。
由于