Jump to content

Triggers - PostgreSQL


A_T_C
 Share

Recommended Posts

Boa tarde!

Estamos a tentar desenvolver um trigger que não permite que um registo c 2 atributos iguais estejam em 2 tabelas diferentes.

create function me_txt_update()
returns trigger
as
$$
declare var integer default 0;
begin
	select count(*) into var
	from respme
	where respme.numperg = new.numperg;
	if var > 0 then
		raise exception 'Erro';
	end if;
	return new;
end
$$
language plpgsql;

create trigger me_txt before insert on respme
for each row execute procedure me_txt_update();

Mas não está a ter o comportamento pretendido...

O q se tem q fazer para funcionar ? :wallbash:

Link to comment
Share on other sites

Não sei se é grande ajuda mas deixo aqui uma pequena doc sobre triggers em postgresql bastante explicativa

http://pt.wikibooks.org/wiki/PostgreSQL_Pr%C3%A1tico/Fun%C3%A7%C3%B5es_Definidas_pelo_Usu%C3%A1rio_e_Triggers/Triggers

Espero que ajude, infelizmente embora já tenha trabalhado com PL/SQL não tenho muita pratica e experiência na área

I haven’t lost my mind; it’s backed up on DVD somewhere!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.