I'm following Postgres documentation https://www.postgresql.org/docs/8.2/xfunc-c.html for writing C function and creating the extension (for hierarchial clustering) and I'm confused.
HeapTupleHeader t = PG_GETARG_HEAPTUPLEHEADER(0);
GET_ARGUMENT_BY_NUM
, can I get a value for each column and put it into an array? (For some reason i want to get data from table and for example, clusterize it).c_overpaid(emp, limit)
(in documentation) called one time for emp table, or is it called as much as the rows in the table?You should read the documentation for the current version.
Yes.
As the example shows, with GetAttributeByName
, but there is also a GetAttributeByNum
function. I assume you are talking about a C array and not a PostgreSQL array. You can stuff all the values into an array, sure, if they have the same data type.
Then you would have to use the special type record
. For a code sample, look at the functions record_to_json
and composite_to_json
in src/backend/utils/adt/json.c
.
It is called for each row found, since it appears in the SELECT
list.
That's a bit vague, but sure. I don't see why you'd want to extract that from a table though. Why not write your own table access method, since it looks like you want to define a new way of storing tables.
But be warned, that would be decidedly non-trivial, and you'd better first get your feet wet with more mundane stuff.