pgAdmin 4 – Running a Python Script Inside pgAdmin 4 Without QGIS Python Console

pgadmin-4postgresqlpyqgispython

I have a python script that contains within it an SQL command. When I execute this through QGIS Python console it also runs smoothly and returns the expected results without any problems.

I would like to know whether it's possible to run a Python script in pgAdmin? Is there a possibility to add like a python console into pgAdmin or something else to achieve this?

The reason I ask is simply because if possible I would like to run everything through one programme in this case pgAdmin as the bulk of my steps are in SQL and it's just one step where I am using Python.

It just would be really helpful to know if it's possible and how to do it or if it would be more effort than it's worth since the processes as they are now all work.

Best Answer

I think you are trying to use postgres and python together. One option could be that:

  1. You use pyscopg2 to execute your postgres script and return your results to python (you can use PL/pgsql to create function and then call that function using psycopg2 in python).
  2. Then do further processing in python.
  3. Finally return the results to postgres database using psycopg2.

Or you can use pgAdmin to create PL/python extension as follows

CREATE EXTENSION plpythonu;

but I have never done that myself you can refer to this link for further help.

https://www.postgresql.org/docs/9.6/static/plpython.html. Hope this answers you question.

Related Question