Lists: | pgsql-es-ayuda |
---|
From: | Juan <smalltalker(dot)marcelo(at)gmail(dot)com> |
---|---|
To: | Ayuda <pgsql-es-ayuda(at)postgresql(dot)org> |
Subject: | problemas con trigger |
Date: | 2012-11-06 16:38:44 |
Message-ID: | CAKizN9whcehz6g1eEbgtU09npzK6WQnCoPyA0tC5RjGvEperCg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-es-ayuda |
Gente
Tengo un trigger declarado en una tabla, declarada de la sig. manera
-- Table: dato_d
-- DROP TABLE dato_d;
CREATE TABLE dato_d
(
id bigserial NOT NULL,
fecha_alta timestamp without time zone NOT NULL,
fecha_baja timestamp without time zone,
fecha_ult_mod timestamp without time zone NOT NULL,
usuario_alta character varying(50) NOT NULL,
usuario_baja character varying(50),
usuario_ult_mod character varying(50) NOT NULL,
codigo character varying(30),
inactivo integer,
nombre character varying(255),
id_dominio bigint,
CONSTRAINT d_pkey PRIMARY KEY (id),
CONSTRAINT sdgdgdfgdfgdfgdFOREIGN KEY (id_dominio)
REFERENCES d (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (
OIDS=FALSE
);
ALTER TABLE dato_d
OWNER TO tsuser;
-- Trigger: tr_datos_d on dato_d
-- DROP TRIGGER tr_datos_dom ON dato_d;
CREATE TRIGGER tr_datos_d
BEFORE INSERT OR UPDATE OR DELETE
ON dato_d
FOR EACH ROW
EXECUTE PROCEDURE tr_datos_d();
PERO: en mi trigger tengo un if por delete or update or insert
segun entendi el trigger llama con un "parametro" NEW u OLD representando
la row que se altera,
Para testear esta funcionalidad le hice un update
update dato_d set fecha_baja = fecha_baja ;
No modifico nada, pero lo que motiva este corre es que algunas veces parece
que el OLD y el NEW vienen en null
de manera que si intento acceder a el campo id me sale el error 'valor no
inicializado'
cualquier ayuda sera agradecido.
saludos
From: | Raul Andres Gutierrez Alejo <raulandrez(at)gmail(dot)com> |
---|---|
To: | pgsql-es-ayuda(at)postgresql(dot)org |
Subject: | Re: problemas con trigger |
Date: | 2012-11-06 16:47:29 |
Message-ID: | 50993F21.6020805@gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-es-ayuda |
utiliza TG_OP para saber que esta haciendo
http://www.postgresql.org/docs/9.2/static/plpgsql-trigger.html
la estructura del triger debe algo parecida a:
CREATE OR REPLACE FUNCTION tr_datos_d()
RETURNS trigger AS
$BODY$
DECLARE
BEGIN
IF TG_OP = 'INSERT' THEN
-- ...
RETURN NEW;
END IF;
IF TG_OP = 'UPDATE' THEN
--- ...
RETURN NEW;
END IF;
IF TG_OP = 'INSERT' OR TG_OP = 'UPDATE' THEN
-- ...
RETURN NEW;
END IF;
IF TG_OP = 'DELETE'THEN
--- ...
RETURN OLD;
END IF;
END;$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
El 06/11/2012 11:38 a.m., Juan escribió:
> Gente
>
> Tengo un trigger declarado en una tabla, declarada de la sig. manera
>
>
> -- Table: dato_d
>
> -- DROP TABLE dato_d;
>
> CREATE TABLE dato_d
> (
> id bigserial NOT NULL,
> fecha_alta timestamp without time zone NOT NULL,
> fecha_baja timestamp without time zone,
> fecha_ult_mod timestamp without time zone NOT NULL,
> usuario_alta character varying(50) NOT NULL,
> usuario_baja character varying(50),
> usuario_ult_mod character varying(50) NOT NULL,
> codigo character varying(30),
> inactivo integer,
> nombre character varying(255),
> id_dominio bigint,
> CONSTRAINT d_pkey PRIMARY KEY (id),
> CONSTRAINT sdgdgdfgdfgdfgdFOREIGN KEY (id_dominio)
> REFERENCES d (id) MATCH SIMPLE
> ON UPDATE NO ACTION ON DELETE NO ACTION
> )
> WITH (
> OIDS=FALSE
> );
> ALTER TABLE dato_d
> OWNER TO tsuser;
>
> -- Trigger: tr_datos_d on dato_d
>
> -- DROP TRIGGER tr_datos_dom ON dato_d;
>
> CREATE TRIGGER tr_datos_d
> BEFORE INSERT OR UPDATE OR DELETE
> ON dato_d
> FOR EACH ROW
> EXECUTE PROCEDURE tr_datos_d();
>
>
> PERO: en mi trigger tengo un if por delete or update or insert
>
> segun entendi el trigger llama con un "parametro" NEW u OLD
> representando la row que se altera,
> Para testear esta funcionalidad le hice un update
> update dato_d set fecha_baja = fecha_baja ;
> No modifico nada, pero lo que motiva este corre es que algunas veces
> parece que el OLD y el NEW vienen en null
> de manera que si intento acceder a el campo id me sale el error 'valor
> no inicializado'
>
> cualquier ayuda sera agradecido.
> saludos
From: | Juan <smalltalker(dot)marcelo(at)gmail(dot)com> |
---|---|
To: | Pedro Ricardo <hades_inf(at)elhacker(dot)net> |
Cc: | Ayuda <pgsql-es-ayuda(at)postgresql(dot)org> |
Subject: | Re: problemas con trigger |
Date: | 2012-11-06 16:53:19 |
Message-ID: | CAKizN9xCebJUNB6WZj9SpL5JVNp4Giya5ftCZNKx80yfex+8GQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-es-ayuda |
-- Function: tr_datos_d()
-- DROP FUNCTION tr_datos_d();
CREATE OR REPLACE FUNCTION tr_datos_d()
RETURNS trigger AS
$BODY$declare sql varchar = null ;
declare v_codigo varchar(100) ;
DECLARE V_COD bigint =0 ;
DECLARE V_COD2 VARCHAR(100) ;
BEGIN
RAISE NOTICE 'trigger !!!!!! DOMINIO % NAME=% WHEN=% LEVEL=% RELID=%
RELNAME=% TABLENAME=% SCHEMA=% NARGS=%', TG_OP,TG_NAME,TG_WHEN
,TG_LEVEL,TG_RELID,TG_RELNAME,TG_TABLE_NAME,TG_TABLE_SCHEMA,TG_NARGS ;
IF TG_OP='INSERT' THEN
V_COD = NEW.ID ;
V_COD2 = NEW.CODIGO;
end if;
IF TG_OP='DELETE' THEN
V_COD = OLD.ID ;
V_COD2 = OLD.CODIGO;
END IF;
IF TG_OP='UPDATE' THEN
V_COD = NEW.ID ;
V_COD2 = NEW.CODIGO;
END IF;
RAISE NOTICE 'COD2 %',OLD.CODIGO ;
RAISE NOTICE 'VIEJO %',OLD.ID ;
select getid_codigo_off_dominio( V_COD ) into v_codigo ;
RAISE NOTICE 'DOMINIO de id= % corresponde a codigo = %',V_COD ,v_codigo ;
if ( v_codigo = '' ) then
/* no encuentra ese id en la tabla de dominios */
return NEW ;
end if ;
RAISE NOTICE 'CODIGO %', v_codigo ;
case v_codigo
when 'NACIONALIDADES' THEN
IF TG_OP='INSERT' THEN
-- Conectate con dblink, crea la coneccion
perform dblink_connect ('....' ::text );
-- Usa la conexion
RAISE NOTICE 'trigger 2 ' ;
sql = 'INSERT INTO nacionalidades(id_nacionalidad ,nacionalidad) VALUES(';
sql = sql || quote_literal(to_string( NEW.id,'999999999999999999')) || '
,' ;
sql = sql || quote_literal(NEW.nombre) || ' );' ;
RAISE NOTICE 'trigger %',NEW.id ;
RAISE NOTICE 'sql %',sql ;
perform dblink_exec(sql ::text );
-- Cierra la conección
perform dblink_disconnect();
RETURN NEW;
END IF;
IF TG_OP='DELETE' THEN
sql = 'DELETE FROM nacionalidades WHERE id_nacionalidad =' ||
quote_literal(OLD.ID ,'999999999999999999') || ' ;' ;
perform dblink_exec(sql ::text );
perform dblink_disconnect();
RETURN OLD;
END IF ;
IF TG_OP='UPDATE' THEN
RAISE NOTICE 'NEW %',NEW.CODIGO ;
RAISE NOTICE 'OLD %',OLD.CODIGO ;
sql = 'update nacionalidades set nacionalidad =' || quote_literal(
OLD.CODIGO ) || ' where nacionalidades.id_nacionalidad=' ||
quote_literal( OLD.ID ::integer ) ;
perform dblink_exec(sql ::text );
perform dblink_disconnect();
RETURN NEW;
END IF;
WHEN 'SEXOS' then
/*
CREATE TABLE lista_genero
(
id_genero character varying(25) NOT NULL,
descripcion_genero character varying(255),
CONSTRAINT cslista_generoprimarykey PRIMARY KEY (id_genero)
)
*/
IF TG_OP='INSERT' THEN
-- Conectate con dblink, crea la coneccion
perform dblink_connect ('....' ::text );
-- Usa la conexion
RAISE NOTICE 'trigger 2 ' ;
sql = 'INSERT INTO lista_genero (id_genero ,descripcion_genero) VALUES(';
sql = sql || quote_literal(to_string( NEW.id,'999999999999999999')) || '
,' ;
sql = sql || quote_literal(NEW.nombre) || ' );' ;
RAISE NOTICE 'trigger %',NEW.id ;
RAISE NOTICE 'sql %',sql ;
perform dblink_exec(sql ::text );
-- Cierra la conección
perform dblink_disconnect();
RETURN NEW;
END IF ;
IF TG_OP='DELETE' THEN
sql = 'DELETE FROM lista_genero WHERE id_genero =' ||
quote_literal(OLD.ID,'999999999999999999') || ' ;' ;
perform dblink_exec(sql ::text );
perform dblink_disconnect();
RETURN OLD;
END IF;
IF TG_OP='UPDATE' THEN
sql = 'update lista_genero set descripcion_genero =' || quote_literal(
NEW.CODIGO ::INTEGER ) || ' where lista_genero.id_genero=' ||
quote_literal(NEW.ID ::INTEGER ) || ' ;' ;
perform dblink_exec(sql ::text );
perform dblink_disconnect();
RETURN NEW;
END IF;
when 'ESTADO_CIVIL' THEN
/*
CREATE TABLE lista_estadocivil
(
id_estado_civil character varying(25) NOT NULL,
descripcion_estado_civil character varying(255),
CONSTRAINT cslista_estadocivilprimarykey PRIMARY KEY (id_estado_civil)
)
*/
IF TG_OP='INSERT' THEN
-- Conectate con dblink, crea la coneccion
perform dblink_connect ('.....' ::text );
-- Usa la conexion
RAISE NOTICE 'trigger 2 ' ;
sql = 'INSERT INTO lista_estadocivil(id_estadocivil
,descripcion_estado_civil) VALUES(';
sql = sql || quote_literal( NEW.id,'999999999999999999') || ' ,' ;
sql = sql || quote_literal(NEW.nombre) || ' );' ;
RAISE NOTICE 'trigger %',NEW.id ;
RAISE NOTICE 'sql %',sql ;
perform dblink_exec(sql ::text );
-- Cierra la conección
perform dblink_disconnect();
RETURN NEW;
END IF;
IF TG_OP='DELETE' THEN
sql = 'DELETE FROM lista_estadocivil WHERE id_estadocivil =' ||
quote_literal(OLD.ID ,'999999999999999999') || ' ;' ;
perform dblink_exec(sql ::text );
perform dblink_disconnect();
RETURN OLD;
END IF;
IF TG_OP='UPDATE' THEN
RAISE NOTICE 'NEW %',NEW.CODIGO ;
RAISE NOTICE 'OLD %',OLD.CODIGO ;
sql = 'update lista_estadocivil set descripcion_estado_civil =' ||
quote_literal(V_COD ::integer ) ||' where id_estadocivil = ' ||
quote_literal(NEW.ID ::integer ) ;
perform dblink_exec(sql ::text );
perform dblink_disconnect();
RETURN NEW;
END IF;
when 'TIPOS_DOC' then
/*
CREATE TABLE tiposdocumento
(
tipo_documento character varying(20) NOT NULL,
descripcion character varying(150) DEFAULT ''::character varying,
CONSTRAINT cstiposdocumentoprimarykey PRIMARY KEY (tipo_documento)
)
*/
IF TG_OP='INSERT' THEN
-- Conectate con dblink, crea la coneccion
perform dblink_connect ('...' ::text );
-- Usa la conexion
RAISE NOTICE 'trigger 2 ' ;
sql = 'INSERT INTO tiposdocumento (tipo_documento ,descripcion) VALUES(';
sql = sql || quote_literal( NEW.id,'999999999999999999') || ' ,' ;
sql = sql || quote_literal(NEW.nombre) || ' );' ;
RAISE NOTICE 'trigger %',NEW.id ;
RAISE NOTICE 'sql %',sql ;
perform dblink_exec(sql ::text );
-- Cierra la conección
perform dblink_disconnect();
RETURN NEW;
ELSEIF TG_OP='DELETE' THEN
sql = 'DELETE FROM tiposdocumento WHERE tipo_documento =' ||
quote_literal(OLD.ID ,'999999999999999999') || ' ;' ;
perform dblink_exec(sql ::text );
perform dblink_disconnect();
RETURN OLD;
ELSEIF TG_OP='UPDATE' THEN
sql = 'update tiposdocumento set descripcion =' || quote_literal(
NEW.codigo) ||' where tipo_documento = ' ||
quote_literal(NEW.ID,'999999999999999999') ;
perform dblink_exec(sql ::text );
perform dblink_disconnect();
RETURN NEW;
END IF;
ELSE
RETURN new;
END CASE ;
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION tr_datos_d()
OWNER TO postgres;
2012/11/6 Pedro Ricardo <hades_inf(at)elhacker(dot)net>
> Hombre pon el trigger para ver como lo tienes declarado ...
>
>
> 2012/11/6 Juan <smalltalker(dot)marcelo(at)gmail(dot)com>
>
>> Gente
>>
>> Tengo un trigger declarado en una tabla, declarada de la sig. manera
>>
>>
>> -- Table: dato_d
>>
>> -- DROP TABLE dato_d;
>>
>> CREATE TABLE dato_d
>> (
>> id bigserial NOT NULL,
>> fecha_alta timestamp without time zone NOT NULL,
>> fecha_baja timestamp without time zone,
>> fecha_ult_mod timestamp without time zone NOT NULL,
>> usuario_alta character varying(50) NOT NULL,
>> usuario_baja character varying(50),
>> usuario_ult_mod character varying(50) NOT NULL,
>> codigo character varying(30),
>> inactivo integer,
>> nombre character varying(255),
>> id_dominio bigint,
>> CONSTRAINT d_pkey PRIMARY KEY (id),
>> CONSTRAINT sdgdgdfgdfgdfgdFOREIGN KEY (id_dominio)
>> REFERENCES d (id) MATCH SIMPLE
>> ON UPDATE NO ACTION ON DELETE NO ACTION
>> )
>> WITH (
>> OIDS=FALSE
>> );
>> ALTER TABLE dato_d
>> OWNER TO tsuser;
>>
>> -- Trigger: tr_datos_d on dato_d
>>
>> -- DROP TRIGGER tr_datos_dom ON dato_d;
>>
>> CREATE TRIGGER tr_datos_d
>> BEFORE INSERT OR UPDATE OR DELETE
>> ON dato_d
>> FOR EACH ROW
>> EXECUTE PROCEDURE tr_datos_d();
>>
>>
>> PERO: en mi trigger tengo un if por delete or update or insert
>>
>> segun entendi el trigger llama con un "parametro" NEW u OLD
>> representando la row que se altera,
>> Para testear esta funcionalidad le hice un update
>> update dato_d set fecha_baja = fecha_baja ;
>> No modifico nada, pero lo que motiva este corre es que algunas veces
>> parece que el OLD y el NEW vienen en null
>> de manera que si intento acceder a el campo id me sale el error 'valor no
>> inicializado'
>>
>> cualquier ayuda sera agradecido.
>> saludos
>>
>
>
>
> --
> *System.out.println('P');
> for(int i=0; i<10; i++){ System.out.print('i'); }
> System.out.print('dro');*
>
> *Staff :: Hadess_inf - www.foro.elhacker.net**
> *
>
>
From: | Juan <smalltalker(dot)marcelo(at)gmail(dot)com> |
---|---|
To: | Raul Andres Gutierrez Alejo <raulandrez(at)gmail(dot)com> |
Cc: | pgsql-es-ayuda(at)postgresql(dot)org |
Subject: | Re: problemas con trigger |
Date: | 2012-11-06 16:54:13 |
Message-ID: | CAKizN9w1Bhn8km1W65cKhGKyE-73zump46TD_=0iYQ_1Q+hHzg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-es-ayuda |
Hola
On Tue, Nov 6, 2012 at 1:47 PM, Raul Andres Gutierrez Alejo <
raulandrez(at)gmail(dot)com> wrote:
> utiliza TG_OP para saber que esta haciendo
> http://www.postgresql.org/docs/9.2/static/plpgsql-trigger.html
>
Como veras lo uso.
>
>
> la estructura del triger debe algo parecida a:
> CREATE OR REPLACE FUNCTION tr_datos_d()
> RETURNS trigger AS
> $BODY$
> DECLARE
> BEGIN
> IF TG_OP = 'INSERT' THEN
> -- ...
> RETURN NEW;
> END IF;
> IF TG_OP = 'UPDATE' THEN
> --- ...
> RETURN NEW;
> END IF;
>
> IF TG_OP = 'INSERT' OR TG_OP = 'UPDATE' THEN
> -- ...
> RETURN NEW;
> END IF;
>
> IF TG_OP = 'DELETE'THEN
> --- ...
> RETURN OLD;
> END IF;
> END;$BODY$
> LANGUAGE plpgsql VOLATILE
> COST 100;
>
> El 06/11/2012 11:38 a.m., Juan escribió:
>
> Gente
>
> Tengo un trigger declarado en una tabla, declarada de la sig. manera
>
>
> -- Table: dato_d
>
> -- DROP TABLE dato_d;
>
> CREATE TABLE dato_d
> (
> id bigserial NOT NULL,
> fecha_alta timestamp without time zone NOT NULL,
> fecha_baja timestamp without time zone,
> fecha_ult_mod timestamp without time zone NOT NULL,
> usuario_alta character varying(50) NOT NULL,
> usuario_baja character varying(50),
> usuario_ult_mod character varying(50) NOT NULL,
> codigo character varying(30),
> inactivo integer,
> nombre character varying(255),
> id_dominio bigint,
> CONSTRAINT d_pkey PRIMARY KEY (id),
> CONSTRAINT sdgdgdfgdfgdfgdFOREIGN KEY (id_dominio)
> REFERENCES d (id) MATCH SIMPLE
> ON UPDATE NO ACTION ON DELETE NO ACTION
> )
> WITH (
> OIDS=FALSE
> );
> ALTER TABLE dato_d
> OWNER TO tsuser;
>
> -- Trigger: tr_datos_d on dato_d
>
> -- DROP TRIGGER tr_datos_dom ON dato_d;
>
> CREATE TRIGGER tr_datos_d
> BEFORE INSERT OR UPDATE OR DELETE
> ON dato_d
> FOR EACH ROW
> EXECUTE PROCEDURE tr_datos_d();
>
>
> PERO: en mi trigger tengo un if por delete or update or insert
>
> segun entendi el trigger llama con un "parametro" NEW u OLD
> representando la row que se altera,
> Para testear esta funcionalidad le hice un update
> update dato_d set fecha_baja = fecha_baja ;
> No modifico nada, pero lo que motiva este corre es que algunas veces
> parece que el OLD y el NEW vienen en null
> de manera que si intento acceder a el campo id me sale el error 'valor no
> inicializado'
>
> cualquier ayuda sera agradecido.
> saludos
>
>
>
From: | Jaime Casanova <jaime(at)2ndquadrant(dot)com> |
---|---|
To: | Juan <smalltalker(dot)marcelo(at)gmail(dot)com> |
Cc: | Ayuda <pgsql-es-ayuda(at)postgresql(dot)org> |
Subject: | Re: problemas con trigger |
Date: | 2012-11-07 04:23:44 |
Message-ID: | CAJKUy5ix8NMCPVwj8pq303rBr667oMhFv=9kh_AGdN1mCj5byA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-es-ayuda |
On Tue, Nov 6, 2012 at 11:38 AM, Juan <smalltalker(dot)marcelo(at)gmail(dot)com> wrote:
>
> segun entendi el trigger llama con un "parametro" NEW u OLD representando
> la row que se altera,
> Para testear esta funcionalidad le hice un update
> update dato_d set fecha_baja = fecha_baja ;
> No modifico nada, pero lo que motiva este corre es que algunas veces parece
> que el OLD y el NEW vienen en null
> de manera que si intento acceder a el campo id me sale el error 'valor no
> inicializado'
>
obvio..
en INSERT el registro OLD no esta inicializado porque no hay valor anterior
en DELETE el registro NEW no esta inicializado porque no hay valor
modificado (o nuevo)
--
Jaime Casanova www.2ndQuadrant.com
Professional PostgreSQL: Soporte 24x7 y capacitación
Phone: +593 4 5107566 Cell: +593 987171157
From: | Jaime Casanova <jaime(at)2ndquadrant(dot)com> |
---|---|
To: | Juan <smalltalker(dot)marcelo(at)gmail(dot)com> |
Cc: | Pedro Ricardo <hades_inf(at)elhacker(dot)net>, Ayuda <pgsql-es-ayuda(at)postgresql(dot)org> |
Subject: | Re: problemas con trigger |
Date: | 2012-11-07 04:26:58 |
Message-ID: | CAJKUy5iR3ApJkpjWKxaY6oHdke+T3h2fViVJU9fRm8YfyOBhrw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-es-ayuda |
On Tue, Nov 6, 2012 at 11:53 AM, Juan <smalltalker(dot)marcelo(at)gmail(dot)com> wrote:
>
> RAISE NOTICE 'COD2 %',OLD.CODIGO ;
> RAISE NOTICE 'VIEJO %',OLD.ID ;
>
y obviamente en un INSERT este codigo te dará error porque OLD no esta
definido y ese RAISE NOTICE se hace incondicionalmente
>
> if ( v_codigo = '' ) then
> /* no encuentra ese id en la tabla de dominios */
> return NEW ;
> end if ;
>
y si es DELETE este NEW no estara definidido
y asi... sigue chequeando el codigo buscando esa clase de errores
--
Jaime Casanova www.2ndQuadrant.com
Professional PostgreSQL: Soporte 24x7 y capacitación
Phone: +593 4 5107566 Cell: +593 987171157
From: | Juan <smalltalker(dot)marcelo(at)gmail(dot)com> |
---|---|
To: | Jaime Casanova <jaime(at)2ndquadrant(dot)com> |
Cc: | Pedro Ricardo <hades_inf(at)elhacker(dot)net>, Ayuda <pgsql-es-ayuda(at)postgresql(dot)org> |
Subject: | Re: problemas con trigger |
Date: | 2012-11-07 15:47:11 |
Message-ID: | CAKizN9wPFrz-euVrW01bKL5h1Jqo0BVsHFgL4mpqvKHbfaMPxQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-es-ayuda |
Jaime
Lo extraño es que para hacer el test yo *use update*
*por lo que entiendo update manda inicializado el New.*
*lo raro es que ambos new y old estan en null.*
*cualquier idea sera agradecida *
*gracias.*
*jmdc
*
2012/11/7 Jaime Casanova <jaime(at)2ndquadrant(dot)com>
> On Tue, Nov 6, 2012 at 11:53 AM, Juan <smalltalker(dot)marcelo(at)gmail(dot)com>
> wrote:
> >
> > RAISE NOTICE 'COD2 %',OLD.CODIGO ;
> > RAISE NOTICE 'VIEJO %',OLD.ID ;
> >
>
> y obviamente en un INSERT este codigo te dará error porque OLD no esta
> definido y ese RAISE NOTICE se hace incondicionalmente
>
> >
> > if ( v_codigo = '' ) then
> > /* no encuentra ese id en la tabla de dominios */
> > return NEW ;
> > end if ;
> >
>
> y si es DELETE este NEW no estara definidido
>
>
> y asi... sigue chequeando el codigo buscando esa clase de errores
>
> --
> Jaime Casanova www.2ndQuadrant.com
> Professional PostgreSQL: Soporte 24x7 y capacitación
> Phone: +593 4 5107566 Cell: +593 987171157
>
From: | Jaime Casanova <jaime(at)2ndquadrant(dot)com> |
---|---|
To: | Juan <smalltalker(dot)marcelo(at)gmail(dot)com> |
Cc: | Pedro Ricardo <hades_inf(at)elhacker(dot)net>, Ayuda <pgsql-es-ayuda(at)postgresql(dot)org> |
Subject: | Re: problemas con trigger |
Date: | 2012-11-07 21:14:20 |
Message-ID: | CAJKUy5hTorxyyPZABtb6QFsoiqdK8i8qxYpBU3Pff=BEHENz1w@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-es-ayuda |
2012/11/7 Juan <smalltalker(dot)marcelo(at)gmail(dot)com>:
> Jaime
>
> Lo extraño es que para hacer el test yo use update
> por lo que entiendo update manda inicializado el New.
> lo raro es que ambos new y old estan en null.
> cualquier idea sera agradecida
y como determinas que NEW y OLD vienen en null?
te da algun error?
--
Jaime Casanova www.2ndQuadrant.com
Professional PostgreSQL: Soporte 24x7 y capacitación
Phone: +593 4 5107566 Cell: +593 987171157
From: | Raul Andres Gutierrez Alejo <raulandrez(at)gmail(dot)com> |
---|---|
To: | pgsql-es-ayuda(at)postgresql(dot)org |
Subject: | Re: problemas con trigger |
Date: | 2012-11-07 21:22:16 |
Message-ID: | 509AD108.7050900@gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-es-ayuda |
NEW es valido en INSERT Y UPDATE
OLD es valido en UPDATE Y DELETE
con esta función puede probar los valores para cualquier tabla.
CREATE OR REPLACE FUNCTION tr_datos_d()
RETURNS trigger AS
$BODY$
DECLARE
BEGIN
IF TG_OP = 'INSERT' THEN
RAISE NOTICE 'INSERT NEW %',NEW;
RETURN NEW;
END IF;
IF TG_OP = 'UPDATE' THEN
RAISE NOTICE 'UPDATE NEW %',NEW;
RAISE NOTICE 'UPDATE OLD %',OLD;
RETURN NEW;
END IF;
IF TG_OP = 'DELETE' THEN
RAISE NOTICE 'DELETE OLD %',OLD;
RETURN OLD;
END IF;
END;$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
El 07/11/2012 04:14 p.m., Jaime Casanova escribió:
> 2012/11/7 Juan <smalltalker(dot)marcelo(at)gmail(dot)com>:
>> Jaime
>>
>> Lo extraño es que para hacer el test yo use update
>> por lo que entiendo update manda inicializado el New.
>> lo raro es que ambos new y old estan en null.
>> cualquier idea sera agradecida
> y como determinas que NEW y OLD vienen en null?
> te da algun error?
>
> --
> Jaime Casanova www.2ndQuadrant.com
> Professional PostgreSQL: Soporte 24x7 y capacitación
> Phone: +593 4 5107566 Cell: +593 987171157
>
> -
> Enviado a la lista de correo pgsql-es-ayuda (pgsql-es-ayuda(at)postgresql(dot)org)
> Para cambiar tu suscripción:
> http://www.postgresql.org/mailpref/pgsql-es-ayuda
From: | Juan <smalltalker(dot)marcelo(at)gmail(dot)com> |
---|---|
To: | Raul Andres Gutierrez Alejo <raulandrez(at)gmail(dot)com> |
Cc: | pgsql-es-ayuda(at)postgresql(dot)org |
Subject: | Re: problemas con trigger |
Date: | 2012-11-08 00:27:25 |
Message-ID: | CAKizN9zFmPrrNhMt3AC41waOZ1ptcyt_HWSvDLfjgOjZa1JoXg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-es-ayuda |
Gracias gente por tomarse el tiempo para responder , pero ya lo solucione,
el problema estaba
entre el teclado y la silla :( :):):):)
salu2
jmdc
2012/11/7 Raul Andres Gutierrez Alejo <raulandrez(at)gmail(dot)com>
> NEW es valido en INSERT Y UPDATE
> OLD es valido en UPDATE Y DELETE
> con esta función puede probar los valores para cualquier tabla.
>
> CREATE OR REPLACE FUNCTION tr_datos_d()
> RETURNS trigger AS
> $BODY$
> DECLARE
> BEGIN
> IF TG_OP = 'INSERT' THEN
> RAISE NOTICE 'INSERT NEW %',NEW;
> RETURN NEW;
> END IF;
> IF TG_OP = 'UPDATE' THEN
> RAISE NOTICE 'UPDATE NEW %',NEW;
> RAISE NOTICE 'UPDATE OLD %',OLD;
>
> RETURN NEW;
> END IF;
> IF TG_OP = 'DELETE' THEN
> RAISE NOTICE 'DELETE OLD %',OLD;
> RETURN OLD;
> END IF;
>
> END;$BODY$
> LANGUAGE plpgsql VOLATILE
> COST 100;
>
> El 07/11/2012 04:14 p.m., Jaime Casanova escribió:
>
>> 2012/11/7 Juan <smalltalker(dot)marcelo(at)gmail(dot)com**>:
>>
>>> Jaime
>>>
>>> Lo extraño es que para hacer el test yo use update
>>> por lo que entiendo update manda inicializado el New.
>>> lo raro es que ambos new y old estan en null.
>>> cualquier idea sera agradecida
>>>
>> y como determinas que NEW y OLD vienen en null?
>> te da algun error?
>>
>> --
>> Jaime Casanova www.2ndQuadrant.com
>> Professional PostgreSQL: Soporte 24x7 y capacitación
>> Phone: +593 4 5107566 Cell: +593 987171157
>>
>> -
>> Enviado a la lista de correo pgsql-es-ayuda (
>> pgsql-es-ayuda(at)postgresql(dot)org**)
>> Para cambiar tu suscripción:
>> http://www.postgresql.org/**mailpref/pgsql-es-ayuda<http://www.postgresql.org/mailpref/pgsql-es-ayuda>
>>
>
>
> -
> Enviado a la lista de correo pgsql-es-ayuda (pgsql-es-ayuda(at)postgresql(dot)org
> **)
> Para cambiar tu suscripción:
> http://www.postgresql.org/**mailpref/pgsql-es-ayuda<http://www.postgresql.org/mailpref/pgsql-es-ayuda>
>