forming tuple as an attribute inside another tuple in c function - Mailing list pgsql-hackers

From Marios Vodas
Subject forming tuple as an attribute inside another tuple in c function
Date
Msg-id AANLkTinJv16K-XE=dPETr3DvGU+zU9P1GaPsH76Vs5rO@mail.gmail.com
Whole thread Raw
Responses Re: forming tuple as an attribute inside another tuple in c function
List pgsql-hackers
Is it posible? Either by using heap_form_tuple or BuildTupleFromCStrings.

CREATE TYPE p_type AS
(
x double precision,
y double precision
);
CREATE TYPE d_type AS
(
i p_type,
e p_type,
id integer
);

CREATE OR REPLACE FUNCTION demo()
RETURNS d_type
AS '/home/user/PostgreSQL/9.0/lib/mylib','demo'
LANGUAGE C STRICT;

Datum demo(PG_FUNCTION_ARGS) {
    float8 xi = 1;
    float8 yi = 2;

    float8 xe = 3;
    float8 ye = 4;

    int32 id = 1;

    bool isnull;

    TupleDesc tupdesc;
    Datum values[3];
    HeapTuple tuple;

    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);

    values[0] = ?;                                             //how?
    values[1] = ?;                                             //how?
    values[2] = Int32GetDatum(id);

    tuple = heap_form_tuple(tupdesc, values, &isnull);

    PG_RETURN_DATUM(HeapTupleGetDatum(tuple));
}

pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: do we want to gitignore regression-test-failure files?
Next
From: Tom Lane
Date:
Subject: Re: do we want to gitignore regression-test-failure files?