Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I send some http request from postgresql function or trigger

I need to send data via http protocol (GET or POST request) from the function or trigger. Is it possible?

like image 534
im4LF Avatar asked Jul 24 '10 13:07

im4LF


People also ask

How do I use triggers in PostgreSQL?

Syntax. CREATE TRIGGER trigger_name [BEFORE|AFTER|INSTEAD OF] event_name ON table_name [ -- Trigger logic goes here.... ]; Here, event_name could be INSERT, DELETE, UPDATE, and TRUNCATE database operation on the mentioned table table_name. You can optionally specify FOR EACH ROW after table name.

Does Postgres use HTTP?

The responsible PostgreSQL process executes SQL specified in general configuration with parsed HTTP request as input to select the intended database and schema as well as authentication and request handler procedures to call there.

What is instead of trigger in PostgreSQL?

An INSTEAD OF trigger is a trigger that allows you to skip an INSERT , DELETE , or UPDATE statement to a table or a view and execute other statements defined in the trigger instead. The actual insert, delete, or update operation does not occur at all.

What is a trigger function in PostgreSQL?

A PostgreSQL trigger is a function invoked automatically whenever an event associated with a table occurs. An event could be any of the following: INSERT, UPDATE, DELETE or TRUNCATE. A trigger is a special user-defined function associated with a table.


3 Answers

You could try writing the trigger in PL/Python and use urllib2 to POST.

like image 50
Kevin Avatar answered Oct 13 '22 11:10

Kevin


There is an extension to do this, use with caution.

pgsql-http

like image 39
Sean Avatar answered Oct 13 '22 11:10

Sean


Any "untrusted" language with HTTP support can do this:

  • PL/Pythonu
  • PL/perlu
  • PL/javau
  • ...

but you shouldn't really do it. See Does PLV8 support making http calls to other servers? and why you shouldn't send email from a trigger function.

like image 4
Craig Ringer Avatar answered Oct 13 '22 13:10

Craig Ringer