0

I'm looking for a way to do a request response pattern inside a trigger. This would be used to perform additional (more complex) data validation.

More concretely, something like this:

CREATE OR REPLACE TRIGGER create_user
BEFORE INSERT
   ON users
   FOR EACH ROW
BEGIN
  --- trigger 3rd party validation code
  NOTIFY creating new.user

  --- listen for 3rd party code to notify with the result
  return LISTEN created

END;

Would this be possible to do in postgres? Thanks!

Matt
  • 22,224
  • 25
  • 80
  • 116
  • You need to provide specific information about what you are trying to do. What's a "request response pattern" in this context? What /exactly/ do you want the trigger to do? – BadZen Jan 06 '17 at 16:02
  • i want it to trigger more complex validation in another language (like Golang, PHP, Node.js) and then respond with true or false, then have the trigger reject or resolve. – Matt Jan 06 '17 at 16:34
  • At 6,000+ rep you should know better than to ask a question in this way. An answer to your question would be as simple as "Yes", but I guess you are looking for something more specific. If so, make your question more specific. – Patrick Jan 06 '17 at 17:21
  • I find being concise tends to work better on Stack Overflow. The heading says it all – even a "yes" would be helpful to me actually, then I know to dig further, but I haven't seen any way to LISTEN and NOTIFY inside a Postgres trigger. I've updated the title to hopefully clarify it some more. – Matt Jan 06 '17 at 17:25
  • A trigger can absolutely `notify` other listeners. However a trigger that listens, doesn't really make sense because it could only process messages when it was fired, which kind of defeats the purpose of the listening in my eyes. –  Jan 07 '17 at 19:54

0 Answers0