Skip site navigation (1) Skip section navigation (2)

Re: C function to return tuple

From: Marios Vodas <mvodas(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: C function to return tuple
Date: 2010-09-26 16:38:33
Message-ID: AANLkTin8ungEFJM7=Rj9hUkNcV8hrk8Ah3PV7tL4yEMg@mail.gmail.com (view raw or flat)
Thread:
Lists: 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(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> Marios Vodas <mvodas(at)gmail(dot)com> writes:
> > My problem is that I don't know how to construct the d_type tuple in the
> c
> > function.
>
> Seems like the main problem with that function is that you're passing
> 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
>

In response to

Responses

pgsql-hackers by date

Next:From: Tom LaneDate: 2010-09-26 16:42:22
Subject: Re: [COMMITTERS] pgsql: Still more tweaking of git_changelog.
Previous:From: Robert HaasDate: 2010-09-26 16:25:09
Subject: Re: [COMMITTERS] pgsql: Still more tweaking of git_changelog.

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group