In postgres 9.2 I am trying to create a python program that can be a trigger. I want to run an external program (an exe on the local disk) so I am using python to run it. When I try to create a simple program like this:
CREATE FUNCTION one () RETURNS int AS $$ # PL/Python function body $$ LANGUAGE plpythonu;
I get the error:
ERROR: language "plpythonu" does not exist HINT: Use CREATE LANGUAGE to load the language into the database.
When I run:
CREATE LANGUAGE plpythonu
I get the error:
ERROR: could not access file "$libdir/plpython2": No such file or directory
I am using Windows 7 and python 2.5 .
I have looked in many places but cannot find a solution.
Any ideas?
PostgreSQL, often written as "Postgres" and pronounced "Poss-gres", is an open source relational database implementation frequently used by Python applications as a backend for data storage and retrieval.
Psycopg is a PostgreSQL adapter for the Python programming language. This tool allows us to connect the capabilities of the Python language and libraries to obtain, manipulate, input, and update data stored in a PostgreSQL database. At the time of this writing the current version is psycopg2.
I have just solved this problem, literally a few days back. The solution is quite involved. Here it goes.
In Postgresql use the 'CREATE LANGUAGE plpython3u' command to install Python 3 language support. More often than not, it will give the following error "unable to load ".....\plpython3.dll" error 126. (Note if it installs correctly, no error will be displayed.)
In case you get the above error, goto your python installation directory (default is C:\python32) and look for "python3.dll" in the DLL's folder. Copy this file to your Postgresql 'lib' folder in the installation directory of Postgres (default is c:\program files\postgres\9.x\lib\"). Rename this copied file to python32.dll.
Now run the 'CREATE LANGUAGE plpython3u' command again. It should work this time.
To verify, check out the pg_available_extensions view in the system tables of postgresql. The row containing plpython3u should have a version number in the 'installed version' column.
Note : This only works for plpython3u language. I do not know any similar process for plpython2u.
To resolve this for plpython3, it was necessary to:
CREATE LANGUAGE plpython3u
Update: I've written a much better explanation here: https://stackoverflow.com/a/24218449/398670
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With