Re: C function to return tuple
От | Marios Vodas |
---|---|
Тема | Re: C function to return tuple |
Дата | |
Msg-id | AANLkTin8ungEFJM7=Rj9hUkNcV8hrk8Ah3PV7tL4yEMg@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: C function to return tuple (Tom Lane <tgl@sss.pgh.pa.us>) |
Ответы |
Re: C function to return tuple
|
Список | pgsql-hackers |
I see what you mean and I changed the code BUT still my main problem is that I want to know how to fill values array. I remind you that d_type contains attributes of another composite type p_type.
I need a solution to that because I need to use it in other parts of the code.
Datum d_swap(PG_FUNCTION_ARGS) {
HeapTupleHeader t = PG_GETARG_HEAPTUPLEHEADER(0);
HeapTupleHeader i;
HeapTupleHeader e;
bool isnull;
TupleDesc tupdesc;
Datum values[3];
HeapTuple tuple;
i = DatumGetHeapTupleHeader(GetAttributeByName(t, "i", &isnull));
e = DatumGetHeapTupleHeader(GetAttributeByName(t, "e", &isnull));
if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) {
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("function returning record called in context that cannot accept type record")));
}
BlessTupleDesc(tupdesc);
//I need to get this working
values[0] = e;
values[1] = i;
values[2] = GetAttributeByName(t, "id", &isnull);
tuple = heap_form_tuple(tupdesc, values, &isnull);
PG_RETURN_DATUM(HeapTupleGetDatum(tuple));
}
On Sun, Sep 26, 2010 at 7:16 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Marios Vodas <mvodas@gmail.com> writes:Seems like the main problem with that function is that you're passing
> My problem is that I don't know how to construct the d_type tuple in the c
> function.
an uninitialized "nulls" array to heap_form_tuple.
I kinda wonder why you are using a fixed-length values array together
with a variable-length, dynamically allocated nulls array, but that'
just odd style not wrong in itself.
regards, tom lane
В списке pgsql-hackers по дате отправления: