Re: C Tigger Function Tuples - Mailing list pgsql-general

From Joe Conway
Subject Re: C Tigger Function Tuples
Date
Msg-id 3D529AAF.10101@joeconway.com
Whole thread Raw
In response to C Tigger Function Tuples  ("Kubat, Philip" <philip.kubat@cbetech.com>)
List pgsql-general
Kubat, Philip wrote:
> I am creating a C function which send inserted records to a file called
> via a after insert trigger. I have attached my code. I have the basic
> functionality working, but I need to understand working with heap
> tuples.  I am using heap_getattr to retrieve the attrs from the
> HeapTuple.  I am planning to loop through the attr and the send then to
> a file.
>
> My question is how do you know what "type" an attr is?  To convert from
> Datum to C type i.e. DataGetInt32, dataGetCString, etc.  (See my dummy
> function GetDatumType.)

Without looking too closely at your code, it sounds like you want to use
the "out" function for each attribute's data type to produce a C-string
representation of it?

Look in execTuples.c and funcapi.c (in CVS, not in 7.2.1) at
TupleDescGetAttInMetadata(), BuildTupleFromCStrings(), and
get_type_metadata() for an example of just the opposite process --
building a tuple from C strings. You should be able to do something
similar with the "out" functions instead of the "in" functions.

I'm sure there are other examples that can be found in the source.
Another likely place to look is the code in copy.c.

HTH,

Joe


pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: SQL Comments
Next
From: Gregory Seidman
Date:
Subject: Re: increasing FUNC_MAX_ARGS insufficient?