From claycle@cisco.com Thu Jun 26 20:49:06 2003 X-Original-To: pgsql-interfaces-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 4935431013F for ; Thu, 26 Jun 2003 20:49:06 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 22493-03 for ; Thu, 26 Jun 2003 17:48:55 -0300 (ADT) Received: from rtp-core-1.cisco.com (rtp-core-1.cisco.com [64.102.124.12]) by svr1.postgresql.org (Postfix) with ESMTP id 8534231015B for ; Thu, 26 Jun 2003 17:48:55 -0300 (ADT) Received: from unity.cisco.com (evvbu-exchange-100tx.cisco.com [64.101.140.74]) by rtp-core-1.cisco.com (8.12.9/8.12.6) with SMTP id h5QKmrai026060 for ; Thu, 26 Jun 2003 16:48:54 -0400 (EDT) Subject: Dissecting Tuples in C From: Clay Luther To: pgsql-interfaces@postgresql.org Content-Type: multipart/alternative; boundary="=-/cW1EbiYicK/Vd3n2tA0" Organization: Cisco System, Inc. Message-Id: <1056660353.22881.28.camel@gkar> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.2 (1.2.2-5) Date: 26 Jun 2003 15:45:53 -0500 X-Archive-Number: 200306/83 X-Sequence-Number: 4294 --=-/cW1EbiYicK/Vd3n2tA0 Content-Type: text/plain Content-Transfer-Encoding: 7bit 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 --=-/cW1EbiYicK/Vd3n2tA0 Content-Type: text/html; charset=utf-8 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
--=-/cW1EbiYicK/Vd3n2tA0-- From nandrews@investsystems.co.uk Thu Jun 26 20:58:44 2003 X-Original-To: pgsql-interfaces-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id D5C1B310096 for ; Thu, 26 Jun 2003 20:58:44 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 22614-05 for ; Thu, 26 Jun 2003 17:58:34 -0300 (ADT) Received: from smtp.investsystems.co.uk (unknown [62.49.196.163]) by svr1.postgresql.org (Postfix) with SMTP id 6AE583100CC for ; Thu, 26 Jun 2003 17:58:33 -0300 (ADT) Received: (qmail 25453 invoked from network); 26 Jun 2003 20:58:32 -0000 Received: from ponder.fairway2k.co.uk (nandrews@172.31.1.3) by hex.fairway2k.co.uk with SMTP; 26 Jun 2003 20:58:32 -0000 Date: Thu, 26 Jun 2003 21:58:32 +0100 (BST) From: "Nigel J. Andrews" X-Sender: nandrews@ponder.fairway2k.co.uk To: Clay Luther Cc: pgsql-interfaces@postgresql.org Subject: Re: Dissecting Tuples in C In-Reply-To: <1056660353.22881.28.camel@gkar> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Archive-Number: 200306/84 X-Sequence-Number: 4295 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 From claycle@cisco.com Thu Jun 26 22:19:17 2003 X-Original-To: pgsql-interfaces-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id AC9C430FE72 for ; Thu, 26 Jun 2003 22:19:17 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 30943-02 for ; Thu, 26 Jun 2003 19:19:06 -0300 (ADT) Received: from rtp-core-1.cisco.com (rtp-core-1.cisco.com [64.102.124.12]) by svr1.postgresql.org (Postfix) with ESMTP id 620C430FAE6 for ; Thu, 26 Jun 2003 19:19:06 -0300 (ADT) Received: from unity.cisco.com (evvbu-exchange-100tx.cisco.com [64.101.140.74]) by rtp-core-1.cisco.com (8.12.9/8.12.6) with SMTP id h5QMI2ai004101; Thu, 26 Jun 2003 18:18:03 -0400 (EDT) Subject: Re: Dissecting Tuples in C From: Clay Luther To: "Nigel J. Andrews" Cc: pgsql-interfaces@postgresql.org In-Reply-To: References: Content-Type: multipart/alternative; boundary="=-sapnR1TTwMhBla8qK8ZR" Organization: Cisco System, Inc. Message-Id: <1056665701.22881.41.camel@gkar> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.2 (1.2.2-5) Date: 26 Jun 2003 17:15:01 -0500 X-Archive-Number: 200306/85 X-Sequence-Number: 4296 --=-sapnR1TTwMhBla8qK8ZR Content-Type: text/plain Content-Transfer-Encoding: 7bit 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 > --=-sapnR1TTwMhBla8qK8ZR Content-Type: text/html; charset=utf-8 Re: [INTERFACES] Dissecting Tuples in C 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


--=-sapnR1TTwMhBla8qK8ZR-- From mail@joeconway.com Thu Jun 26 22:28:16 2003 X-Original-To: pgsql-interfaces-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 9D07330FAE6 for ; Thu, 26 Jun 2003 22:28:16 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 38814-02 for ; Thu, 26 Jun 2003 19:28:05 -0300 (ADT) Received: from joeconway.com (66-146-172-86.skyriver.net [66.146.172.86]) by svr1.postgresql.org (Postfix) with ESMTP id 334EC30F17E for ; Thu, 26 Jun 2003 19:28:05 -0300 (ADT) Received: from [206.19.64.3] (account jconway HELO joeconway.com) by joeconway.com (CommuniGate Pro SMTP 4.0.6) with ESMTP-TLS id 1813393; Thu, 26 Jun 2003 14:59:21 -0700 Message-ID: <3EFB727E.50803@joeconway.com> Date: Thu, 26 Jun 2003 15:23:58 -0700 From: Joe Conway User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.3) Gecko/20030312 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Clay Luther Cc: "Nigel J. Andrews" , pgsql-interfaces@postgresql.org Subject: Re: Dissecting Tuples in C References: <1056665701.22881.41.camel@gkar> In-Reply-To: <1056665701.22881.41.camel@gkar> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Archive-Number: 200306/86 X-Sequence-Number: 4297 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: TriggerData *trigdata = (TriggerData *) fcinfo->context; rel = trigdata->tg_relation; tupdesc = rel->rd_att; HTH, Joe