Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I execute a cURL call from postgres trigger

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:

  1. Can this be done?
  2. Reference?
  3. 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 and process another step, then update the db with the results.

like image 699
Phill Pafford Avatar asked Oct 29 '25 14:10

Phill Pafford


1 Answers

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.

like image 105
Tometzky Avatar answered Oct 31 '25 05:10

Tometzky



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!