I have to create a process call on a db field(s) being a certain status. I have heard you can execute a cURL call with a db trigger but Google is not being kind enough to return anything I can use.
So I guess my question is three parts:
- Can this be done?
- Reference?
- Alternative Solution?
Workflow:
db field is updated with status, need to kick off script/request/process that run the next step in my work flow (This is a PHP script) that will pull the recorded in the db an开发者_开发问答d process another step, then update the db with the results.
You shouldn't use triggers for that, as a trigger blocks transactions so it will make your database very slow. Also you'd need to install unsafe language to Postgres — pl/sh, pl/perl, pl/python or other.
There are 2 better solutions for this problem:
have a process which connects to database and LISTENs for NOTIFY events generated by your trigger — this will work instantly;
periodically check for new data using, for example, a cron script - this would work with a delay.
If you can call a shell script, http://plsh.projects.postgresql.org/ you can call a curl.
But I get a creepy feeling about the approach...
- If the remote server goes offline, data inconsistency??
Alternative:
I wouldn't put business logic in triggers, only customized constraints or denormalisation.
Do what you need to do with either middle-tier, or stored procedures.
Regards, //t
I think what you're looking for is a trigger in postgres that will run the necessery script. Triggers are explained in the documentation, the syntax for adding a new trigger is explained here. The trigger type you're looking for appears to be an AFTER UPDATE trigger. As far as I know, the script you run will have to check if the field is of the required status, as postgres will always run the trigger.
精彩评论