Re: Dissecting Tuples in C - Mailing list pgsql-interfaces

From Clay Luther
Subject Re: Dissecting Tuples in C
Date
Msg-id 1056665701.22881.41.camel@gkar
Whole thread Raw
In response to Re: Dissecting Tuples in C  ("Nigel J. Andrews" <nandrews@investsystems.co.uk>)
Responses Re: Dissecting Tuples in C
List pgsql-interfaces
Hrmmmm....let me be more clear.<br /><br /> How do I get the TupleDesc for a HeapTuple, for example?  The Trigger
structurehas HeapTuples, but I need the TupleDesc as well to be able to use functions like SPI_getvalue().<br /><br />
Clay<br/><br /><br /><br /><br /> On Thu, 2003-06-26 at 15:58, Nigel J. Andrews wrote: <blockquote type="CITE"><font
color="#737373"size="2"><i>On 26 Jun 2003, Clay Luther wrote:</i></font><br /><font color="#737373" size="3"></font><br
/><fontcolor="#737373" size="2">> I am trying to get up to speed writing C triggers and I have a question<br /> >
aboutthe relation between HeapTuples and other tuple-related types,<br /> > like TupleTableSlots, and the routines
andmacros used to manipulate<br /> > them. I am reading and re-reading the online docs, but still have some<br />
>broad questions.<br /> > <br /> > For example, suppose I just wanted a trigger to iterate through the<br />
>HeapTuple pointed at by the tirgger data tg_trigtuple, printing out the<br /> > column names, types, and values
(letssay, only ints and strings for<br /> > simplicity). How would I do this?<br /> > <br /> > A pointer to a
gooddocument would be just as good as a detailed answer.</font><br /><font color="#737373" size="3"></font><br /><font
color="#737373"size="2">Take a browse around the things in contrib. However, I'd say the easiest way to<br /> do the
specificthing you ask about is to look up the SPI utility functions in<br /> the docs and then write something like the
psuedocode:</font><br /><font color="#737373" size="3"></font><br /><font color="#737373" size="2">i = 1;<br /> while
(i< tupdesc->natts)<br /> {</font><br /><font color="#737373" size="3">        </font><font color="#737373"
size="2">char*colname = SPI_fname(tg_trigtuple, i);</font><br /><font color="#737373" size="3">        </font><font
color="#737373"size="2">char *coltype = SPI_gettype(tg_trigtuple, i);</font><br /><font color="#737373"
size="3">       </font><font color="#737373" size="2">char *colvalue = SPI_getvalue(tg_trigtuple, i);</font><br /><font
color="#737373"size="3"><br />         </font><font color="#737373" size="2">i++;<br /> }</font><br /><font
color="#737373"size="3"></font><br /><font color="#737373" size="2">That's very much psuedo code. It's bad that I can't
rememberthe exact names<br /> and parameters considering I was doing such things only a week ago but, that's<br /> what
beingbusy does to my memory.</font><br /><font color="#737373" size="3"></font><br /><font color="#737373" size="2">But
really,you can't go wrong looking in chapter 9 (server side<br /> programming) at the spi functions. Well you can just
watchout that the column<br /> numbering starts at 1 for spi.</font><br /><font color="#737373" size="3"><br
/></font><br/><font color="#737373" size="2">-- <br /> Nigel J. Andrews</font><br /><font color="#737373"
size="3"></font><br/></blockquote> 

pgsql-interfaces by date:

Previous
From: "Nigel J. Andrews"
Date:
Subject: Re: Dissecting Tuples in C
Next
From: Joe Conway
Date:
Subject: Re: Dissecting Tuples in C