views:

283

answers:

2

Is it possible to send data on a socket over a TCP?IP connection from a PostgreSQL stored procedure or trigger?

If you know of any useful examples pleas tell me.

If you know of something similar for other data base systems it would also be helpful.

Thanks in advance.

+1  A: 

Yes, it's possible but you have to use one of the "untrusted" languages - PL/perlU, PL/pythonU, etc.

And then all examples you need you'll find in the documentation of the respective language.

Milen A. Radev
+2  A: 

Answer from Milen solves the technical side of the question. But there is also a problem of interactions.

Let's assume you have trigger that does things over TCPIP. This means that the query that launched the trigger can take a long time (think network issues, service issues, firewalls).

Usually much better solution is to store information in some kind of queue, and addition of service, which checks the queue (perhaps using NOTIFY/LISTEN feature of PostgreSQL), and does what's necessary over TCP/IP - with proper handling of long connections, retries and so on.

If you'd be inclined to use such mechanism, you might want to check pgq from SkyTools.

depesz