X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 98B425E46F9 for ; Wed, 25 Aug 2004 11:53:45 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 98759-07 for ; Wed, 25 Aug 2004 14:53:39 +0000 (GMT) Received: from smtp104.mail.sc5.yahoo.com (smtp104.mail.sc5.yahoo.com [66.163.169.223]) by svr1.postgresql.org (Postfix) with SMTP id 1ED265E46EB for ; Wed, 25 Aug 2004 11:53:36 -0300 (ADT) Received: from unknown (HELO jupiter.black-lion.info) (janwieck@68.80.245.191 with login) by smtp104.mail.sc5.yahoo.com with SMTP; 25 Aug 2004 14:53:41 -0000 Received: from [172.21.8.18] (ismtp.afilias.com [216.217.55.254]) (authenticated bits=0) by jupiter.black-lion.info (8.12.10/8.12.9) with ESMTP id i7PErdT7002047; Wed, 25 Aug 2004 10:53:39 -0400 (EDT) (envelope-from JanWieck@Yahoo.com) Message-ID: <412CA7ED.4020704@Yahoo.com> Date: Wed, 25 Aug 2004 10:53:33 -0400 From: Jan Wieck User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.1) Gecko/20040707 X-Accept-Language: en-us, en MIME-Version: 1.0 To: "Pedro B." Cc: pgsql-sql@postgresql.org Subject: Re: PQexec and SPI_exec References: <412CA074.2000606@netcabo.pt> In-Reply-To: <412CA074.2000606@netcabo.pt> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.6 tagged_above=0.0 required=5.0 tests=RCVD_IN_NJABL_DUL, RCVD_IN_SORBS_DUL X-Spam-Level: * X-Archive-Number: 200408/263 X-Sequence-Number: 18760 On 8/25/2004 10:21 AM, Pedro B. wrote: > Hello everyone. > > I'm experiencing some doubts regarding a procedure i have (.c compiled > as .so) running as an 'after insert for each row' trigger. > > This trigger is supposed to do a simple query, something like > SELECT * FROM table order by id where processed=0 limit 1 > > It's not the perfect way to get the vars of the insert itself, but the > result is a set of 45 columns, and the operations of the trigger are > somehow complex, so .c is really a necessity on this one, and as long as > this select actually returns the proper values, i can deal with it later. > > But my problem is not one of a structure nature: my problem is the fact > that using SPI_exec, and the SPI_getvalue(SPI_tuptable->vals[0], > SPI_tuptable->tupdesc, columnX), and > DatumGetInt32(DirectFunctionCall1(int4in, > CStringGetDatum(SPI_getvalue(SPI_tuptable->vals[0], > SPI_tuptable->tupdesc, columnX)))), etc, it all works fine. > the SPI-running-from-the-triggered-.so can detect the correct values - > from the insert that triggered it If the trigger is supposed to use values from the tuple that triggered its call, then it should not select them from the table but use the provided tg_trigtuple in the TriggerData structure. See http://www.postgresql.org/docs/current/static/trigger-interface.html for details. > > I would prefer to use the more friendly PQexec and the simpler > PQgetvalue(res,0,X), but this last approach does not return the values > of the insert that triggered it. It returns the values from the "the > last insert before this one". What is the proper way to make this method > work? There is no proper way to make this work at all. What you are doing in this case is to have the database server process that is handling your query open another client connection to the server, starting another database server process. This cannot work. Jan -- #======================================================================# # It's easier to get forgiveness for being wrong than for being right. # # Let's break this rule - forgive me. # #================================================== JanWieck@Yahoo.com #