Tigger after delete with plpgsql

Started by fellipehover 13 years ago10 messagesgeneral
Jump to latest
#1fellipeh
fellipeh@gmail.com

Hello, I`m try to use this code for my After Delete trigger:

delete
from MOVIMENTO
where (IDEMPRESA = OLD.idempresa) and
(upper(TABELA) = 'NFENTRADA_ITEM') and
(CODIGO = OLD.idempresa_item);

But, when execute. show me error.. that`s says

"old is not initialize" (sorry,but I dont know how exactly error msy
because in my SO, give in portuguese)..

my question is: how can I use OLd and NEW in posgre?

Best Regards,

T.·.F.·.A.·. S+F

*Fellipe Henrique P. Soares*

*"Life is a game without Tutorial"*

*http://fellipeh.eti.br*

#2Alan Hodgson
ahodgson@simkin.ca
In reply to: fellipeh (#1)
Re: Tigger after delete with plpgsql

On Friday, August 31, 2012 02:10:47 PM Fellipe Henrique wrote:

Hello, I`m try to use this code for my After Delete trigger:

delete
from MOVIMENTO
where (IDEMPRESA = OLD.idempresa) and
(upper(TABELA) = 'NFENTRADA_ITEM') and
(CODIGO = OLD.idempresa_item);

But, when execute. show me error.. that`s says

"old is not initialize" (sorry,but I dont know how exactly error msy
because in my SO, give in portuguese)..

my question is: how can I use OLd and NEW in posgre?

Just like that. Which implies something else is wrong. Please post the whole
trigger function and a \d of the table where this trigger is used, and the SQL
that you are executing that results in the error.

#3Tulio
tulio@informidia.com.br
In reply to: fellipeh (#1)
Re: Tigger after delete with plpgsql

<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#333333">
Hi,<br>
<br>
You're using a trigger AFTER, in your case could be BEFORE?<br>
Cause when you use AFTER the var OLD not exists...<br>
I don't know if I understand exactly what you'll do to ativate this
trigger..<br>
but I think maybe is it..<br>
<br>
try..<br>
<br>
<br>
Em 31/08/2012 14:10, Fellipe Henrique escreveu:
<blockquote
cite="mid:CAF1jwZH+cXLCwHwZCF53eBtXADm=u4B_+6kQqJA9GfmctJ=Zaw@mail.gmail.com"
type="cite">Hello, I`m try to use this code for my After Delete
trigger:
<div><br>
</div>
<div>
<div>&nbsp; delete</div>
<div>&nbsp; from MOVIMENTO</div>
<div>&nbsp; where (IDEMPRESA = OLD.idempresa) and</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; (upper(TABELA) = 'NFENTRADA_ITEM') and</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; (CODIGO = OLD.idempresa_item);</div>
<div><br>
</div>
<div>But, when execute. show me error.. that`s says</div>
<div><br>
</div>
<div>"old is not initialize" (sorry,but I dont know how exactly
error msy because in my SO, give in portuguese)..</div>
<div><br>
</div>
<div>my question is: &nbsp;how can I use OLd and NEW in posgre?</div>
<div><br>
</div>
<div>Best Regards,</div>
<div><br>
</div>
<div><br>
</div>
<span style="color:black">T.&middot;.F</span><span style="color:black">.&middot;.A</span><span
style="color:black">.&middot;.</span>&nbsp;&nbsp;&nbsp;&nbsp; S+F<br>
<p style="height:17px;width:273px"><b><span style="color:black">Fellipe
Henrique P. Soares</span></b><span
style="font-size:7.5pt;color:rgb(102,102,102)" lang="EN-US"><br>
</span></p>
<p style="height:17px;width:273px"><b><span style="color:black">"Life
is a game without Tutorial"</span></b></p>
<p style="height:17px;width:273px"><font face="garamond, serif"><b><a
moz-do-not-send="true" href="http://fellipeh.eti.br&quot;
target="_blank">http://fellipeh.eti.br&lt;/a&gt;&lt;/b&gt;&lt;/font&gt;&lt;/p&gt;
</div>
</blockquote>
<br>
</body>
</html>

#4fellipeh
fellipeh@gmail.com
In reply to: Tulio (#3)
Re: Tigger after delete with plpgsql

Hi,

I`m using Before Delete..

CREATE TRIGGER nfentrada_item_tr1
BEFORE DELETE
ON public.nfentrada_item FOR EACH ROW
EXECUTE PROCEDURE public.nfentrada_item_ad0();

here is my nfentrada_item_ad0();

delete
from MOVIMENTO
where (IDEMPRESA = OLD.idempresa) and
(upper(TABELA) = 'NFENTRADA_ITEM') and
(CODIGO = OLD.idnfentrada_item);
return old;

I just want to delete all row in my MOVIMENTO table with these
conditionals..

Thanks,

T.·.F.·.A.·. S+F

*Fellipe Henrique P. Soares*

*"Life is a game without Tutorial"*

*http://fellipeh.eti.br*

2012/8/31 Tulio <tulio@informidia.com.br>

Show quoted text

Hi,

You're using a trigger AFTER, in your case could be BEFORE?
Cause when you use AFTER the var OLD not exists...
I don't know if I understand exactly what you'll do to ativate this
trigger..
but I think maybe is it..

try..

Em 31/08/2012 14:10, Fellipe Henrique escreveu:

Hello, I`m try to use this code for my After Delete trigger:

delete
from MOVIMENTO
where (IDEMPRESA = OLD.idempresa) and
(upper(TABELA) = 'NFENTRADA_ITEM') and
(CODIGO = OLD.idempresa_item);

But, when execute. show me error.. that`s says

"old is not initialize" (sorry,but I dont know how exactly error msy
because in my SO, give in portuguese)..

my question is: how can I use OLd and NEW in posgre?

Best Regards,

T.·.F.·.A.·. S+F

*Fellipe Henrique P. Soares*

*"Life is a game without Tutorial"*

*http://fellipeh.eti.br*

#5Alan Hodgson
ahodgson@simkin.ca
In reply to: fellipeh (#4)
Re: Tigger after delete with plpgsql

On Friday, August 31, 2012 03:14:15 PM Fellipe Henrique wrote:

CREATE TRIGGER nfentrada_item_tr1
BEFORE DELETE
ON public.nfentrada_item FOR EACH ROW
EXECUTE PROCEDURE public.nfentrada_item_ad0();

here is my nfentrada_item_ad0();

delete
from MOVIMENTO
where (IDEMPRESA = OLD.idempresa) and
(upper(TABELA) = 'NFENTRADA_ITEM') and
(CODIGO = OLD.idnfentrada_item);
return old;

I just want to delete all row in my MOVIMENTO table with these
conditionals..

And the error appears when you do a DELETE FROM public.nfentrada_item? Can you
post the entire function declaration with the CREATE comand?

#6fellipeh
fellipeh@gmail.com
In reply to: Alan Hodgson (#5)
Re: Tigger after delete with plpgsql

Yes, the error appears when I delete "nfentrada_item" row

Here is code:

--
View this message in context: http://postgresql.1045698.n5.nabble.com/Tigger-after-delete-with-plpgsql-tp5722154p5722173.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

#7Alan Hodgson
ahodgson@simkin.ca
In reply to: fellipeh (#6)
Re: Tigger after delete with plpgsql

On Friday, August 31, 2012 12:12:32 PM fellipeh wrote:

Yes, the error appears when I delete "nfentrada_item" row
View this message in context:
http://postgresql.1045698.n5.nabble.com/Tigger-after-delete-with-plpgsql-tp
5722154p5722173.html Sent from the PostgreSQL - general mailing list archive
at Nabble.com.

Well ... I don't know. That runs fine here. Can you post the actual error
message you get? Or a \d on both of those tables.

#8fellipeh
fellipeh@gmail.com
In reply to: Alan Hodgson (#7)
Re: Tigger after delete with plpgsql

Here is error msg:
http://postgresql.1045698.n5.nabble.com/file/n5722180/erro_PG.png

sorry, but in portuguese..

--
View this message in context: http://postgresql.1045698.n5.nabble.com/Tigger-after-delete-with-plpgsql-tp5722154p5722180.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

#9Alan Hodgson
ahodgson@simkin.ca
In reply to: fellipeh (#8)
Re: Tigger after delete with plpgsql

On Friday, August 31, 2012 12:41:42 PM fellipeh wrote:

Here is error msg:
http://postgresql.1045698.n5.nabble.com/file/n5722180/erro_PG.png

sorry, but in portuguese..

--
View this message in context:
http://postgresql.1045698.n5.nabble.com/Tigger-after-delete-with-plpgsql-tp
5722154p5722180.html Sent from the PostgreSQL - general mailing list archive
at Nabble.com.

What is the function movimento_ad0()?

#10fellipeh
fellipeh@gmail.com
In reply to: Alan Hodgson (#9)
Re: Tigger after delete with plpgsql

Found the error... my movimento_ad0() was set to statement .. I change to
Row, and works fine now...

Thanks for all

--
View this message in context: http://postgresql.1045698.n5.nabble.com/Tigger-after-delete-with-plpgsql-tp5722154p5722190.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.