Sql 从Postgres C API中的复合类型数组访问列

Sql 从Postgres C API中的复合类型数组访问列,sql,c,postgresql,postgresql-9.6,Sql,C,Postgresql,Postgresql 9.6,我访问复合值数组,如下所示: PG_GETARG_ARRAYTYPE_P(0) /* Then I deconstruct it into C array */ deconstruct_array() /* Later I iterate thru values and attempt to access columns of my composite type */ GetAttributeByName(input_data1[i], "keyColumnName", &isnull[

我访问复合值数组,如下所示:

PG_GETARG_ARRAYTYPE_P(0)
/* Then I deconstruct it into C array */
deconstruct_array()
/* Later I iterate thru values and attempt to access columns of my composite type */
GetAttributeByName(input_data1[i], "keyColumnName", &isnull[0])
以下是它在SQL中的外观:

SELECT * FROM my_c_function(array[(44, 1)::comp_type, (43, 0)::comp_type], array[(42, 1)::comp_type, (43, 1)::comp_type]);
预期结果:

array[(44, 1)::comp_type, (42, 1)::comp_type, (43, 1)::comp_type] /*order doesn't matter*/
但这不起作用,因为
GetAttributeByName()
仅适用于
HeapTupleHeader
,遗憾的是,我有一个
数据数组。
通常通过访问函数属性获得
HeapTupleHeader
,如:
PG\u GETARG\u HeapTupleHeader(0)
,但这并不适用于数组(或者我错了?)

那么,是否有一些函数/makro可以从复合类型的
Datum
获取列,或者将复合类型
Datum
转换为
HeapTuple
?我已经深入到了heap\u getattr()
,但找不到任何有用的东西。我不记得是否已经有某种函数可以以类似的方式访问复合数组,并告诉我如何操作

就上下文而言: 我有两个复合类型的数组,我想写C函数来快速连接它们。然而,我不能简单地将右参数添加到左边,因为它们可以共享“key”列,在这种情况下,我希望结果只包含右边的值


这是plpgSQL中的简单任务(unnest、full join、array_agg),但速度非常慢。我在hstore和json中测试了相同的任务,两者都比unnest+array_agg快得多,但如果没有大量的数据库结构更改,我就无法使用这些数据类型,因此,我一直在寻找不同的解决方案。

我想您所需要的只是
DatumGetHeapTupleHeader
中定义的
fmgr.h

侧注:您也可以尝试一个。它们比
plpgsql
的要快得多。@pozs是的,我忘了提-我确实试过了,没有改变