pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedDissecting Tuples in C
4+ messages / 3 participants
[nested] [flat]
* Dissecting Tuples in C
@ 2003-06-26 20:45 Clay Luther <claycle@cisco.com>
0 siblings, 1 reply; 4+ messages in thread
From: Clay Luther @ 2003-06-26 20:45 UTC (permalink / raw)
To: pgsql-interfaces
I am trying to get up to speed writing C triggers and I have a question
about the relation between HeapTuples and other tuple-related types,
like TupleTableSlots, and the routines and macros used to manipulate
them. I am reading and re-reading the online docs, but still have some
broad questions.
For example, suppose I just wanted a trigger to iterate through the
HeapTuple pointed at by the tirgger data tg_trigtuple, printing out the
column names, types, and values (lets say, only ints and strings for
simplicity). How would I do this?
A pointer to a good document would be just as good as a detailed answer.
Thanks!
--
Clay
claycle@cisco.com
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Dissecting Tuples in C
@ 2003-06-26 20:58 Nigel J. Andrews <nandrews@investsystems.co.uk>
parent: Clay Luther <claycle@cisco.com>
0 siblings, 1 reply; 4+ messages in thread
From: Nigel J. Andrews @ 2003-06-26 20:58 UTC (permalink / raw)
To: Clay Luther <claycle@cisco.com>; +Cc: pgsql-interfaces
On 26 Jun 2003, Clay Luther wrote:
> I am trying to get up to speed writing C triggers and I have a question
> about the relation between HeapTuples and other tuple-related types,
> like TupleTableSlots, and the routines and macros used to manipulate
> them. I am reading and re-reading the online docs, but still have some
> broad questions.
>
> For example, suppose I just wanted a trigger to iterate through the
> HeapTuple pointed at by the tirgger data tg_trigtuple, printing out the
> column names, types, and values (lets say, only ints and strings for
> simplicity). How would I do this?
>
> A pointer to a good document would be just as good as a detailed answer.
Take a browse around the things in contrib. However, I'd say the easiest way to
do the specific thing you ask about is to look up the SPI utility functions in
the docs and then write something like the psuedo code:
i = 1;
while (i < tupdesc->natts)
{
char *colname = SPI_fname(tg_trigtuple, i);
char *coltype = SPI_gettype(tg_trigtuple, i);
char *colvalue = SPI_getvalue(tg_trigtuple, i);
i++;
}
That's very much psuedo code. It's bad that I can't remember the exact names
and parameters considering I was doing such things only a week ago but, that's
what being busy does to my memory.
But really, you can't go wrong looking in chapter 9 (server side
programming) at the spi functions. Well you can just watch out that the column
numbering starts at 1 for spi.
--
Nigel J. Andrews
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Dissecting Tuples in C
@ 2003-06-26 22:15 Clay Luther <claycle@cisco.com>
parent: Nigel J. Andrews <nandrews@investsystems.co.uk>
0 siblings, 1 reply; 4+ messages in thread
From: Clay Luther @ 2003-06-26 22:15 UTC (permalink / raw)
To: Nigel J. Andrews <nandrews@investsystems.co.uk>; +Cc: pgsql-interfaces
Hrmmmm....let me be more clear.
How do I get the TupleDesc for a HeapTuple, for example? The Trigger
structure has HeapTuples, but I need the TupleDesc as well to be able to
use functions like SPI_getvalue().
Clay
On Thu, 2003-06-26 at 15:58, Nigel J. Andrews wrote:
> On 26 Jun 2003, Clay Luther wrote:
>
> > I am trying to get up to speed writing C triggers and I have a
> question
> > about the relation between HeapTuples and other tuple-related types,
> > like TupleTableSlots, and the routines and macros used to manipulate
> > them. I am reading and re-reading the online docs, but still have
> some
> > broad questions.
> >
> > For example, suppose I just wanted a trigger to iterate through the
> > HeapTuple pointed at by the tirgger data tg_trigtuple, printing out
> the
> > column names, types, and values (lets say, only ints and strings for
> > simplicity). How would I do this?
> >
> > A pointer to a good document would be just as good as a detailed
> answer.
>
> Take a browse around the things in contrib. However, I'd say the
> easiest way to
> do the specific thing you ask about is to look up the SPI utility
> functions in
> the docs and then write something like the psuedo code:
>
> i = 1;
> while (i < tupdesc->natts)
> {
> char *colname = SPI_fname(tg_trigtuple, i);
> char *coltype = SPI_gettype(tg_trigtuple, i);
> char *colvalue = SPI_getvalue(tg_trigtuple, i);
>
> i++;
> }
>
> That's very much psuedo code. It's bad that I can't remember the exact
> names
> and parameters considering I was doing such things only a week ago
> but, that's
> what being busy does to my memory.
>
> But really, you can't go wrong looking in chapter 9 (server side
> programming) at the spi functions. Well you can just watch out that
> the column
> numbering starts at 1 for spi.
>
>
> --
> Nigel J. Andrews
>
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Dissecting Tuples in C
@ 2003-06-26 22:23 Joe Conway <mail@joeconway.com>
parent: Clay Luther <claycle@cisco.com>
0 siblings, 0 replies; 4+ messages in thread
From: Joe Conway @ 2003-06-26 22:23 UTC (permalink / raw)
To: Clay Luther <claycle@cisco.com>; +Cc: Nigel J. Andrews <nandrews@investsystems.co.uk>; pgsql-interfaces
Clay Luther wrote:
> Hrmmmm....let me be more clear.
>
> How do I get the TupleDesc for a HeapTuple, for example? The Trigger
> structure has HeapTuples, but I need the TupleDesc as well to be able to
> use functions like SPI_getvalue().
>
Take a look at ttdummy() in src/test/regress/regress.c.
Here's a snippet of the specific lines you need:
<snip>
TriggerData *trigdata = (TriggerData *) fcinfo->context;
rel = trigdata->tg_relation;
tupdesc = rel->rd_att;
</snip>
HTH,
Joe
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2003-06-26 22:23 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-06-26 20:45 Dissecting Tuples in C Clay Luther <claycle@cisco.com>
2003-06-26 20:58 ` Nigel J. Andrews <nandrews@investsystems.co.uk>
2003-06-26 22:15 ` Clay Luther <claycle@cisco.com>
2003-06-26 22:23 ` Joe Conway <mail@joeconway.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox