triggers problems whit function

Started by Ma. Cristina Peña C.over 17 years ago6 messagesgeneral
Jump to latest
#1Ma. Cristina Peña C.
mpena@sensacd.com.mx

I want to use a function in to a trigger

This is my

CREATE FUNCTION "subradio"(integer) RETURNS integer AS 'select cast(count (claveubica) as integer ) from asradios where ubicacion =0;' LANGUAGE 'sql';

And my ttrigger is

CREATE TRIGGER validaradios AFTER DELETE ON subestacion FOR EACH ROW EXECUTE PROCEDURE subradio(0);

But I got an error

ERROR: CreateTrigger: function subradio() does not exist

What can I do??

Ing. María Cristina Peña C.

Analista Programador

Sensa Control Digital S.A. de C.V.

Dir. Av. Bravo #93 Ote.

Col. Centro.
Torreón Coah.

Tel. Directo: (871) 747 01 04

Conmutador: (871) 747 01 01

Tel. Fax: (871) 747 01 90

Correo Electrónico: mpena@sensacd.com.mx <mailto:rlopezr@sensacd.com.mx>

Attachments:

image001.jpgimage/jpeg; name=image001.jpgDownload
#2Fernando Moreno
azazel.7@gmail.com
In reply to: Ma. Cristina Peña C. (#1)
Re: triggers problems whit function

2008/10/22 Ma. Cristina Peña C. <mpena@sensacd.com.mx>

I want to use a function in to a trigger

This is my

CREATE FUNCTION "subradio"(integer) RETURNS integer AS 'select cast(count
(claveubica) as integer ) from asradios where ubicacion =0;' LANGUAGE 'sql';

And my ttrigger is

CREATE TRIGGER validaradios AFTER DELETE ON subestacion FOR EACH ROW
EXECUTE PROCEDURE subradio(0);

But I got an error

ERROR: CreateTrigger: function subradio() does not exist

What can I do??

A trigger function must have a specific structure, it takes no arguments and
returns "trigger". Besides, trigger functions are supposed to do some
processing before or after insert, update or delete operations, so there's
no sense in returning a row count.

Take a look at the docs, specially chapter 35 and 38.9.

Cheers.

#3MOLINA BRAVO FELIPE DE JESUS
felipe.molina@inegi.org.mx
In reply to: Ma. Cristina Peña C. (#1)
Re: triggers problems whit function

El mié, 22-10-2008 a las 15:01 -0500, Ma. Cristina Peña C. escribió:

I want to use a function in to a trigger

This is my

CREATE FUNCTION "subradio"(integer) RETURNS integer AS 'select
cast(count (claveubica) as integer ) from asradios where ubicacion
=0;' LANGUAGE 'sql';

And my ttrigger is

CREATE TRIGGER validaradios AFTER DELETE ON subestacion FOR EACH ROW
EXECUTE PROCEDURE subradio(0);

But I got an error

ERROR: CreateTrigger: function subradio() does not exist

What can I do??

write your function in plpgsql

http://www.postgresql.org/docs/8.3/interactive/plpgsql-trigger.html

Show quoted text

cid:image002.jpg@01C8F24F.E2D90230

Ing. María Cristina Peña C.

Analista Programador

Sensa Control Digital S.A. de C.V.

Dir. Av. Bravo #93 Ote.

Col. Centro.
Torreón Coah.

Tel. Directo: (871) 747 01 04

Conmutador: (871) 747 01 01

Tel. Fax: (871) 747 01 90

Correo Electrónico: mpena@sensacd.com.mx

#4Guillaume Lelarge
guillaume@lelarge.info
In reply to: Fernando Moreno (#2)
Re: triggers problems whit function

Fernando Moreno a �crit :

2008/10/22 Ma. Cristina Pe�a C. <mpena@sensacd.com.mx
<mailto:mpena@sensacd.com.mx>>

I want to use a function in to a trigger

This is my

CREATE FUNCTION "subradio"(integer) RETURNS integer AS 'select
cast(count (claveubica) as integer ) from asradios where ubicacion
=0;' LANGUAGE 'sql';

And my ttrigger is

CREATE TRIGGER validaradios AFTER DELETE ON subestacion FOR EACH ROW
EXECUTE PROCEDURE subradio(0);

But I got an error

ERROR: CreateTrigger: function subradio() does not exist

What can I do??

A trigger function must have a specific structure, it takes no arguments

It can take arguments.

and returns "trigger".

And this is why, I think, the message tells "function subradio does not
exist". Because there's no subradio function that returns trigger.

Besides, trigger functions are supposed to do
some processing before or after insert, update or delete operations, so
there's no sense in returning a row count.

Take a look at the docs, specially chapter 35 and 38.9.

Regards.

--
Guillaume.
http://www.postgresqlfr.org
http://dalibo.com

#5Tom Lane
tgl@sss.pgh.pa.us
In reply to: Guillaume Lelarge (#4)
Re: triggers problems whit function

Guillaume Lelarge <guillaume@lelarge.info> writes:

Fernando Moreno a �crit :

A trigger function must have a specific structure, it takes no arguments

It can take arguments.

No, it can't. At least not in the declaration.

regards, tom lane

#6Guillaume Lelarge
guillaume@lelarge.info
In reply to: Tom Lane (#5)
Re: triggers problems whit function

Tom Lane a �crit :

Guillaume Lelarge <guillaume@lelarge.info> writes:

Fernando Moreno a �crit :

A trigger function must have a specific structure, it takes no arguments

It can take arguments.

No, it can't. At least not in the declaration.

Oops, you're right. Arguments shouldn't be declared, but can be used in
the body of a PL/pgsql trigger function.

Sorry about this.

--
Guillaume.
http://www.postgresqlfr.org
http://dalibo.com