pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Zouroudis <mzouroudis@idealcorp.com>
To: pgsql-admin@postgresql.org
Subject: serious issues with TG_OP
Date: Fri, 23 Aug 2002 00:41:04 -0400
Message-ID: <3D65BCE0.2070400@idealcorp.com> (raw)

I'm once again having a problem with postgres and would greatly 
appreicate any help.  there are two tables that i'm working with, TEST 
and ONE, created here;

CREATE TABLE test (
test_id         serial        primary key,
fake              text,
below            text,
above             text,
behind            text
);

CREATE TABLE one(
last_id          serial        primary key,
first               text,
begin              text,
hope               text
);

and here's my function;
-----------------------------------------------------------------------------------------
CREATE FUNCTION pearl() RETURNS OPAQUE AS '

DECLARE

  t test%ROWTYPE;
  o one%ROWTYPE;
  x    text;
  y    text;
  z    text;
  a    text;
  xx   text;
  yy   text;
  zz   text;
  aa   text;

BEGIN


  x  := new.fake;
  y  := new.below;
  z  := new.above;
  a  := new.behind;
  xx := x;
  yy := y;
  zz := z;

--insert into test table
--create function that inserts into table ONE automatically when an 
insert into TEST happens
        if TG_OP = ''INSERT'' then
           raise notice ''INSERT xx is equal to  % '', x;
           INSERT INTO one (first, begin, hope) VALUES ( xx, yy, zz);
        end if;

--update data in TEST
--create function that will automatically update data in ONE after 
update in TEST
        if TG_OP = ''UPDATE'' then
           raise notice ''UPDATE xx is equal to  % '', x;
           UPDATE one SET first = x, begin =''yy'', hope = zz WHERE 
begin  = ''eed'';
        end if;

--Delete data from TEST table.
--create function that will automatically delete data in ONE after 
delete in TEST

        if TG_OP = ''DELETE'' then
           raise notice ''DELETE xx is equal to  % '', x;
           DELETE FROM one  WHERE  first = x;
        end if;

RETURN NULL;

END;


'language 'plpgsql';


CREATE TRIGGER love AFTER INSERT or UPDATE or DELETE ON test
FOR EACH ROW EXECUTE PROCEDURE pearl();


----------------------------------------------------------------------------

when i run it  with an insert then update and then a delete statement in a script, i get the following message

----------------------------------------------------------------------------
psql:script:9: NOTICE:  INSERT xx is equal to  ddd
INSERT 215042 1
psql:script:13: NOTICE:  UPDATE xx is equal to  hello
UPDATE 1
psql:script:17: NOTICE:  Error occurred while executing PL/pgSQL function pearl
psql:script:17: NOTICE:  line 21 at assignment
psql:script:17: ERROR:  record new is unassigned yet
-------------------------------------------------------------------------------

the function is printing out a value for x (hello), but not deleting it.  i am lost on how to correctly assign a value for the delete.  Please somebody help me before i do  "kill -9" the postmaster and then blow up my computer.

thanks in advance,

mike

-- 
Mike Zouroudis
Intern
__________________________________________________
I.D.E.A.L. Technology Corporation - Orlando Office
http://www.idealcorp.com - 407.999.9870 x14





view thread (2+ messages)  latest in thread

Message-ID: <3D65BCE0.2070400@idealcorp.com>
Permalink:  ../3D65BCE0.2070400@idealcorp.com/
Also on:    postgresql.org/message-id/3D65BCE0.2070400@idealcorp.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: mzouroudis@idealcorp.com
  Subject: Re: serious issues with TG_OP
  In-Reply-To: <3D65BCE0.2070400@idealcorp.com>
  References: <3D65BCE0.2070400@idealcorp.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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