Anyone can help give a C-language function example that use a custom type as one of the parameters?
Today, I tried to follow the documentation, but I was not able to get the correct values of my custom type.
here is the example: http://www.postgresql.org/docs/9.3/static/xfunc-c.html#XFUNC-C-BASETYPE
#include "postgres.h"
#include "executor/executor.h" /* for GetAttributeByName() */
#ifdef PG_MODULE_MAGIC
PG_MODULE_MAGIC;
#endif
PG_FUNCTION_INFO_V1(c_overpaid);
Datum
c_overpaid(PG_FUNCTION_ARGS)
{
HeapTupleHeader t = PG_GETARG_HEAPTUPLEHEADER(0);
bool isnull;
Datum salary;
salary = GetAttributeByName(t, "salary", &isnull);
if (isnull)
PG_RETURN_BOOL(false);
PG_RETURN_FLOAT4(DatumGetFLOAT4(salary) );
}
the answer is always "0".
you can use "CREATE TYPE V AS(salary float);" as the custom type. thx.