Search code examples
pythonpostgresqlrabbitmqmqttplpython

Can you import Python libraries with PL/Python in PostgreSQL?


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?


Solution

  • 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.