Atenção: Essa wiki é apenas um exemplo que mostra o funcionamento de triggers no PostgreSQL.Recomendamos que use esse documento apenas como base para o desenvolvimento de sua aplicação.

Criando

Manipulação de triggers no PostgreSQL Acesse sua área de hospedagem via SSH SSH, e digite o seguinte comando para acessar sua base de dados:

 psql -h HOST -U nome_da_base nome_do_usuário

Substitua HOST pelo endereço de conexão com a base, assim como o usuário e nome do banco.

Após, será solicitado a senha de acesso.

Manipulação de triggers no PostgreSQL Sintaxe (criação das tabelas e das triggers que manipularão tais tabelas) :

CREATE TABLE teste1 ( campoA INT NOT NULL, campoB INT NOT NULL );   CREATE TABLE teste2 ( campoC INT NOT NULL, campoD INT NOT NULL );   CREATE LANGUAGE plpgsql;   CREATE OR REPLACE FUNCTION insert_minha_function() RETURNS TRIGGER AS ' BEGIN INSERT INTO teste2 (campoC, campoD) values (5,25); RETURN new; END 'LANGUAGE plpgsql;   CREATE TRIGGER insert_minha_trigger AFTER INSERT ON teste1   FOR EACH ROW EXECUTE PROCEDURE insert_minha_function();   CREATE OR REPLACE FUNCTION delete_minha_function() RETURNS TRIGGER AS ' BEGIN INSERT INTO teste2 (campoC, campoD) values (6,26); RETURN old; END 'LANGUAGE plpgsql;   CREATE TRIGGER delete_minha_trigger BEFORE DELETE ON teste1   FOR EACH ROW EXECUTE PROCEDURE delete_minha_function();

Excluindo

Manipulação de triggers no PostgreSQLSintaxe:

DROP TRIGGER nome_da_trigger ON nome_da_tabela;

Visualizando todas as triggers

Manipulação de triggers no PostgreSQLSintaxe:

SELECT * FROM pg_trigger;

Nota

Manipulação de triggers no PostgreSQL Na Locaweb as bases de dados já vêm por padrão com a linguagem plpgsql.Dessa forma, as triggers devem ser criadas nessa linguagem. As outras linguagens, não instalamos por questões de segurança no ambiente compartilhado.

Manipulação de triggers no PostgreSQL Return new;

    Uma trigger com evento BEFORE e com “return old” pode cancelar um INSERT ou um UPDATE.

    Manipulação de triggers no PostgreSQL Return old;

    • Para registros excluídos (DELETE), e para os valores antigos dos registros alterados (UPDATE).

    uma trigger com evento BEFORE e com “return new” pode cancelar um DELETE ou um UPDATE.

    Veja também


    Esse artigo ajudou você?

    47 respostas para “Manipulação de triggers no PostgreSQL”

    1. Tyler Dawson

      I really enjoyed this article. You are an excellent blogger. I’ll be back to see more! Thank you

      Responder
    2. cheap viagra for sale

      This is a topic which is close to my heart… Take care! Exactly where are your contact details though?

      Responder
    3. mamashop.com.au

      Spot on with this write-up, I absolutely believe this website needs much more attention. I’ll probably be returning to read more, thanks for the info.

      Responder
    4. What is Skincell Pro

      This is a topic that’s near to my heart… Take care! Exactly where are your contact details though?

      Responder
    5. White Rhino Feminized Cannabis Seeds

      Aw, this was a really good post. Taking a few minutes and actual effort to make a really good article… but what can I say… I procrastinate a whole lot and never seem to get nearly anything done.

      Responder
    6. Colby Archie

      I must admit that your post is really interesting. I have spent a lot of my spare time reading your content. Thank you a lot!Meri Weigand

      Responder
    7. free horror

      An outstanding share! I’ve just forwarded this onto a colleague who was conducting a little homework on this. And he actually ordered me breakfast due to the fact that I discovered it for him… lol. So let me reword this…. Thanks for the meal!! But yeah, thanks for spending the time to talk about this matter here on your site.

      Responder
    8. Tim Jones

      Great blog post! I’ll return to view your next article! Thanks!

      Responder
    9. clothing

      Everything is very open with a precise description of the issues. It was truly informative. Your website is extremely helpful. Many thanks for sharing!

      Responder
    10. Mica Scandrett

      Having read this I believed it was really informative. I appreciate you finding the time and effort to put Istilah di Judi Bola this content together. I once again find myself spending way too much time both reading and leaving comments

      Responder
    11. Aptitude Tests

      Oh my goodness! Awesome article dude! Many thanks, However I am encountering troubles with your RSS. I don’t know why I am unable to subscribe to it. Is there anyone else getting identical RSS problems? Anybody who knows the answer will you kindly respond? Thanx!!

      Responder
    12. Joline Ivans

      I am so happy to read this. This is the type of manual that needs to be given and not the random misinformation that’s at the other blogs. Appreciate your sharing this greatest doc.

      Responder
    13. lipsticks

      Aw, this was a really nice post. Taking a few minutes and actual effort to make a really good article… but what can I say… I hesitate a lot and never manage to get nearly anything done.

      Responder
    14. Ria Alleruzzo

      Several friends have understood that their marriage was annulled, some even transmit information blog interposed.

      Responder
    15. Pest Control Sean

      If you are searching for the best extreminator company, look no more. These guys are awesome!

      Responder
    16. 슬롯 머신

      Best view i have ever seen !

      Responder
    17. Pretty Gaming

      Everything is very open with a precise clarification of the issues. It was definitely informative. Your website is extremely helpful. Thank you for sharing.

      Responder
    18. Delta 8 THC gummies

      Next time I read a blog, Hopefully it doesn’t disappoint me just as much as this particular one. I mean, Yes, it was my choice to read, nonetheless I really believed you would have something helpful to talk about. All I hear is a bunch of moaning about something that you can fix if you were not too busy seeking attention.

      Responder
    19. Walker Rinderknecht

      I love the efforts you have put in this, appreciate it for all the great articles .

      Responder
    20. White glove service

      You completed various fine points there. I did a search on the issue and found the majority of persons will agree with your blog.

      Responder
    21. Verna Allocco

      Easily, the post is really the greatest on this laudable topic. I concur with your conclusions and will thirstily watch forward to your future updates. Saying thank will not just be sufficient, for the great c lucidity in your writing. I will instantly grab your rss feed to stay privy of any updates. Solid work and much success in your business enterprise!

      Responder
    22. KT Mall Zusammenklappbares elektrisches Mountainbike zu verkaufen

      Hey there! Would you mind if I share your blog with my facebook group? There’s a lot of people that I think would really appreciate your content. Please let me know. Thank you

      Responder
    23. GASLIKE BMX en venta

      Somebody essentially lend a hand to make seriously articles I’d state. That is the first time I frequented your web page and to this point? I surprised with the research you made to make this actual publish incredible. Excellent job!

      Responder
    24. Jarod Mcmonigle

      Nice post. I discover something harder on distinct blogs everyday. Most commonly it is stimulating to learn to read content from other writers and rehearse a little from their store. I’d would rather apply certain with all the content in my small weblog regardless of whether you do not mind. Natually I’ll provide a link on your internet blog. Thanks for sharing.

      Responder
    25. Jorg

      Would love to perpetually get updated outstanding
      web blog!

      Responder
    26. 안전토토

      Best view i have ever seen !

      Responder
    27. 출장안마

      May I simply just say what a comfort to discover a person that actually understands what they are talking about online. You definitely understand how to bring an issue to light and make it important. A lot more people must read this and understand this side of the story. I was surprised you’re not more popular given that you surely have the gift.

      Responder
    28. super home warranty

      I need to to thank you for this fantaastic read!!
      I definitely enjoyed every bit of it.I have got yoou
      book-marked to look at new things you post…

      Responder
    29. San Diego Plumber navigate to this site

      Hi there would you mind letting me know which webhost you’re utilizing? I’ve loaded your blog in 3 completely different web browsers and I must say this blog loads a lot quicker then most. Can you recommend a good hosting provider at a honest price? Cheers, I appreciate it!

      Responder
    30. best car donation

      Hello there! Woould you mind if I share your blog with my twitter group?
      There’s a lot of people that I think would realy appreciate
      your content.Please let me know. Thanks!

      Responder
    31. Groundbreaking Report on VitalFlow for Prostate

      Having read this I thought it was extremely enlightening. I appreciate you taking the time and energy to put this article together. I once again find myself personally spending a lot of time both reading and commenting. But so what, it was still worthwhile.

      Responder
    32. concrete slab repair los angeles

      Interesting blog! Is your theme custom made or did you download it from somewhere? A design like yours with a few simple tweeks would really make my blog shine. Please let me know where you got your design. Cheers

      Responder
    33. Walter

      Hello! Do you use Twitter? I’d like to follow you if that wwould be okay.
      I’m definitely enjoying yoyr blog andd look forward too
      new articles.

      Responder
    34. 마사지알바

      You’re so amazing. Oh my The almighty. Our god bless you.

      Responder
    35. 24 hour plumber my link

      Hey there! Do you know if they make any plugins to help with Search Engine Optimization? I’m trying to get my blog to rank for some targeted keywords but I’m not seeing very good gains. If you know of any please share. Thanks!

      Responder
    36. content

      I simply want to say I am just new to blogging and really savored your web site. Most likely I’m want to bookmark your blog . You really come with amazing articles and reviews. Thanks for sharing your web site.

      Responder
    37. porno

      Thank you for another informative site. Where else may just I get that kind of info written in such a perfect way? I have a mission that I’m simply now working on, and I’ve been on the look out for such information.

      Responder
    38. upscale renovations

      Hey very cool blog!! Man .. Excellent .. Amazing .. I will bookmark your web site and take the feeds also…I’m happy to find a lot of useful info here in the post, we need work out more techniques in this regard, thanks for sharing. . . . . .

      Responder
    39. Hemp Pain Cream Maximum Strength

      This is very fascinating, You’re an overly professional blogger. I’ve joined your rss feed and sit up for in the hunt for extra of your magnificent post. Also, I’ve shared your site in my social networks!

      Responder
    40. m&s digital marketing

      Wonderful work! This is the type of info that should be shared around the net. Shame on Google for not positioning this post higher! Come on over and visit my website . Thanks =)

      Responder
    41. visit here

      I have realized that online degree is getting preferred because getting your college degree online has become a popular alternative for many people. A huge number of people have definitely not had a chance to attend an established college or university although seek the elevated earning possibilities and career advancement that a Bachelor’s Degree offers. Still others might have a degree in one course but wish to pursue some thing they already have an interest in.

      Responder
    42. roadside assistance

      Excellent weblog right here! Additionally your website rather a lot up very fast! What web host are you the usage of? Can I get your affiliate hyperlink to your host? I desire my site loaded up as fast as yours lol

      Responder
    43. find here

      I just want to tell you that I am beginner to blogging and site-building and seriously savored this web page. More than likely I’m going to bookmark your blog . You really have excellent posts. Many thanks for revealing your website page.

      Responder
    44. Gerry Colop

      I just want to mention I am very new to blogs and certainly liked you’re web site. More than likely I’m likely to bookmark your blog post . You really have superb article content. Many thanks for sharing your blog.

      Responder

    Comente sobre este conteúdo! Escreva o que pensa, complemente, vamos discutir. O conhecimento é livre!