Questions about PostgreSQL's PL/Python procedural language. This extension allows one to write python-based triggers and functions inside of the PostgreSQL RDBMS.
Questions tagged [plpython]
166 questions
31
votes
5 answers
How to install 3rd party module for postgres pl/python?
I need to import a 3rd party module inside my pl/python function.
It seems pl/python uses an internal python that does not have any 3rd party modules.
I get this kind of error:
ERROR: PL/Python: PL/Python function "to_tsvector_luc" failed
DETAIL: …

kakarukeys
- 21,481
- 10
- 35
- 48
22
votes
5 answers
postgres and python
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…

Jim
- 1,056
- 1
- 13
- 19
20
votes
2 answers
Unicode normalization in Postgres
I have a large number of Scottish and Welsh accented place names (combining grave, acute, circumflex and diareses) which I need to update to their unicode normalized form, eg, the shorter form 00E1 (\xe1) for á instead of 0061 + 0301 (\x61\x301)
I…

John Powell
- 12,253
- 6
- 59
- 67
17
votes
4 answers
How to aggregate matching pairs into "connected components" in Python
Real-world problem:
I have data on directors across many firms, but sometimes "John Smith, director of XYZ" and "John Smith, director of ABC" are the same person, sometimes they're not. Also "John J. Smith, director of XYZ" and "John Smith, director…

Ian Gow
- 3,098
- 1
- 25
- 31
17
votes
2 answers
How are import statements in plpython handled?
I have a plypython function which does some json magic. For this it obviously imports the json library.
Is the import called on every call to the function? Are there any performance implication I have to be aware of?

Mauli
- 16,863
- 27
- 87
- 114
13
votes
3 answers
How to test Pl/Python PostgreSQL procedures with Travis CI?
I'm trying to set up CI for some PL/Python PostgreSQL procedures in Travis CI.
I've tried several ways:
1) With the legacy infrastructure I've tried to just assume, that PL/Python is already installed, but it had not succeed:
The command "psql -U…

Gill Bates
- 14,330
- 23
- 70
- 138
12
votes
6 answers
Install plpython on mac with python 2.7
I need to install plpython because I'm getting the error
could not access file "$libdir/plpython2": No such file or directory
when trying to do python manage.py migrate. I have seen different suggestions on how to install this package but none…

Nicky Mirfallah
- 1,004
- 4
- 16
- 38
11
votes
1 answer
How does PostgreSQL PL/Python compare with Python outside it in terms of performances?
I run the exact same Python function, one as a PostgreSQL PL/Python, and the other one outside PostgreSQL as a usual Python script.
Surprisingly, when I call the PostgreSQL PL/Python using select * from pymax7(20000);, it takes on average 65…

Franck Dernoncourt
- 77,520
- 72
- 342
- 501
10
votes
2 answers
Add plpython3 Extension to Postgres/timescaledb Alpine Docker Image
I try to add the plpython3 extension to my timescaledb/postgres (based on linux alpine) image:
FROM timescale/timescaledb:0.9.0-pg10
RUN set -ex \
&& apk add --no-cache --virtual .plpython3-deps --repository…

Yannic Hamann
- 4,655
- 32
- 50
10
votes
2 answers
In PostgreSQL, where does plpython(3)u output from `print` go?
When I create the following function in PostgreSQL:
create function log( value variadic text[] )
returns void
language plpython3u
as $$
print( ' '.join( value ) + '\n' )
$$;
do $$ begin perform log( ( 42 + 108 )::text ); end; $$;
the…

John Frazer
- 1,018
- 13
- 18
8
votes
1 answer
using python finditer, how can I replace each matched string?
I am using Python (pl/python, actually) to find, successively, a series of regex matches in a very large text object. This is working fine! Each match is a different result, and each replace will be a different result, eventually based on a query…

DrLou
- 649
- 5
- 21
8
votes
1 answer
install plpython in postgresql 8 or 9
i want to install plpython on postgresql to have python trigger
when i restore my DB (my db has some python trigger) this error apears (error message was too big so i paste first lines of it):
C:/Program Files/PostgreSQL/9.0/bin/pg_restore.exe
…

Maziar Aboualizadehbehbahani
- 1,976
- 17
- 37
8
votes
2 answers
PostgreSQL unable to create plpythonu extension
I'm trying to write a function in PostgreSQL on Windows with a Python script in the body and i'm running into an error message when trying to create the plpythonu extension. The command I'm running is:
CREATE EXTENSION plpythonu;
Which produces…

JTW
- 3,546
- 8
- 35
- 49
7
votes
1 answer
Call plpgsql Function from a PL/Python Function in PostgreSQL
Is is possible to call a plpgsql function (or any PostgreSQL function) from a PL/Python function?
So, something like this:
CREATE FUNCTION somefunc() RETURNS void AS $$
DECLARE
...
BEGIN
...
END;
$$ LANGUAGE plpgsql;
And then use it…

four-eyes
- 10,740
- 29
- 111
- 220
6
votes
1 answer
"Module not found" when importing a Python package within a plpython3u procedure
I am using a plpython3 stored function, on a postgres database on MacOS (installed with standard Enterprise DB package).
I can import standard python packages such as:
CREATE OR REPLACE FUNCTION foo(x double precision)
RETURNS double…

fralau
- 3,279
- 3
- 28
- 41