X-Original-To: pgsql-interfaces-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 19FDED7AB7 for ; Mon, 12 Sep 2005 13:01:47 -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 74634-03 for ; Mon, 12 Sep 2005 16:01:43 +0000 (GMT) Received: from nproxy.gmail.com (nproxy.gmail.com [64.233.182.206]) by svr1.postgresql.org (Postfix) with ESMTP id 6803CD8A9F for ; Mon, 12 Sep 2005 13:01:40 -0300 (ADT) Received: by nproxy.gmail.com with SMTP id c2so409351nfe for ; Mon, 12 Sep 2005 09:01:39 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=hed9EOp1RXFSBP/exhXWG9doQEwKkcePh+///f/fgTXNqBi95xxXFWKBIEWOklleDrhjlOnD+elFzEE5fIxufuzl1otykrDnRACb8pHxuUoqTW8YjnOUiPX8swnhVM7CF5m1i0T+OWJmPXBgFLqrsCr6v+3IH8Je/RQ0WVoghCc= Received: by 10.48.236.2 with SMTP id j2mr58788nfh; Mon, 12 Sep 2005 09:01:39 -0700 (PDT) Received: by 10.48.250.5 with HTTP; Mon, 12 Sep 2005 09:01:39 -0700 (PDT) Message-ID: <1532344d05091209012fc914df@mail.gmail.com> Date: Mon, 12 Sep 2005 18:01:39 +0200 From: fabrizio picca Reply-To: fabrizio.picca@gmail.com To: Michael Fuhr Subject: Re: help needed on SPI_modifytuple. Cc: pgsql-interfaces@postgresql.org In-Reply-To: <20050912153646.GA55025@winnie.fuhr.org> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <1532344d050912071740e7c5d9@mail.gmail.com> <20050912153646.GA55025@winnie.fuhr.org> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.024 required=5 tests=[AWL=-0.000, RCVD_BY_IP=0.024] X-Spam-Level: X-Archive-Number: 200509/15 X-Sequence-Number: 5738 thanks a lot Michael, you've just hit the problem! Now everything works fine! Thanks again Fabrizio On 9/12/05, Michael Fuhr wrote: > On Mon, Sep 12, 2005 at 04:17:33PM +0200, fabrizio picca wrote: > > I'm trying to sipmply modify a tuple before it will be inserted in the = db. > > The problem is that when it try to insert the modified tuple with > > SPI_modifytuple all i get is a SPI_ERROR_ARGUMENT negative (-6) . > > Could someone help me? i'm reallygoing crazy. > > > > What i did is just a fire-before C trigger that acts like this: >=20 > Is the trigger fired on INSERT, UPDATE, or both? >=20 > > oldtuple =3D trigdata->tg_trigtuple; > > newtuple =3D trigdata->tg_newtuple; > [...] > > rettuple=3DSPI_modifytuple(rel,newtuple,1,&attnum,&new_value,&i= snull); >=20 > I didn't look closely at the rest of the code, but if the trigger > is fired on INSERT then you should pass oldtuple; newtuple will be > NULL, causing SPI_modifytuple() to fail with SPI_ERROR_ARGUMENT. > Here's an extract from "Writing Trigger Functions in C" in the > "Triggers" chapter of the documentation: >=20 > tg_trigtuple >=20 > A pointer to the row for which the trigger was fired. This is > the row being inserted, updated, or deleted. If this trigger was > fired for an INSERT or DELETE then this is what you should return > from the function if you don't want to replace the row with a > different one (in the case of INSERT) or skip the operation. >=20 > tg_newtuple >=20 > A pointer to the new version of the row, if the trigger was fired > for an UPDATE, and NULL if it is for an INSERT or a DELETE. This > is what you have to return from the function if the event is an > UPDATE and you don't want to replace this row by a different one > or skip the operation. >=20 > -- > Michael Fuhr >=20 --=20 L'Estetica del lavoro =E8 lo spettacolo della merce umana (Area) -- http://www.fabpicca.net