Constantin
Constantin

Reputation: 465

PostgreSQL socket connection

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.

Upvotes: 1

Views: 2126

Answers (2)

user80168
user80168

Reputation:

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.

Upvotes: 4

Milen A. Radev
Milen A. Radev

Reputation: 62653

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.

Upvotes: 1

Related Questions