2

I was wondering if it was possible to use Python libraries inside PL/Python.

What I want to do is remove one node in our setup. Right now we have a sensor publishing data to RabbitMQ using Mosquitto and MQTT.

On the other side, we have PostgreSQL and we want to build a database. I know that we need something between RabbitMQ and PostgreSQL and we were thinking of Paho.

But we were wondering if it was possible to run a script on PostgreSQL using plpython and using the library Paho there. So that would make onr less thing to execute "stand alone".

Or maybe there are other alternatives?

Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263
Dave
  • 39
  • 5

1 Answers1

1

Sure, you can import any module into PL/Python. The documentation states:

PL/Python is only available as an “untrusted” language, meaning it does not offer any way of restricting what users can do in it and is therefore named plpythonu.

Just make sure you don't use multi-threading inside PostgreSQL.

Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263
  • Thank you! I was able to get my code running directly from PostgreSQL! – Dave Apr 10 '19 at 19:13
  • @laurenz-albe, what is the issue with using multi-threading inside PGSQL? – fabio.avigo May 10 '19 at 15:38
  • 2
    The system is not written for it. You need to write software specifically thread-safe for multi-threading to work. For example PostgreSQL works a lot with signals. When a multi-threaded process receives a signal, it is not clear which thread will handle it. – Laurenz Albe May 10 '19 at 15:41