Questions tagged [plpython]

Questions about PostgreSQL's PL/Python procedural language. This extension allows one to write python-based triggers and functions inside of the PostgreSQL RDBMS.

166 questions
2
votes
1 answer

PL/Python with Anaconda

I've got Anaconda installed on a Ubuntu and would like to use some of it's modules in PL/Python. However, every time I call scipy, it errors with ImportError: No module named scipy.stats. How do I get the Anaconda to work with PL/Python? UPDATED:…
Rocky Yost
  • 150
  • 1
  • 1
  • 10
2
votes
0 answers

Writing unit-tests for PostgreSQL functions in PL/Python - is it possible/reasonable?

I've found interesting PL/PGSQL framework for unit-testing of PL/PGSQL procedures, called pgTAP. But PostgreSQL supports another language for stored procedures - Python, which already has unit-testing framework in standard library and assert…
Gill Bates
  • 14,330
  • 23
  • 70
  • 138
2
votes
2 answers

How to pass int[] as argument between plpython functions

I'm working with PostgreSQL and plpython functions. I have a function func1: CREATE OR REPLACE FUNCTION func1(a integer, b timestamp with time zone, c integer[]) RETURNS SETOF x AS $BODY$ parts=plpy.execute("SELECT * FROM…
John
  • 1,724
  • 6
  • 25
  • 48
2
votes
1 answer

PL/Python ERROR: NameError: global name 'name of user-defined function' is not defined

I am running Postgres 9.3 and I am trying to create a PL/Python function calling a user-defined sql function but I get the below error message after calling the function using SELECT * FROM f2(TEXT1, TEXT2): ERROR: NameError: global name 'f1' is not…
jO.
  • 3,384
  • 7
  • 28
  • 38
2
votes
2 answers

PL/Python Error "could not convert SPI error to Python exception"

I am working on a set of PL/Python stored procedures. I am using PostgreSQL 9.3 ( installed from apt.postgresql.org ) and a Python 2.7 interpreter; running on Ubuntu 13.04. The error occurs in the middle of a large operation ( creating a…
Ngure Nyaga
  • 2,989
  • 1
  • 20
  • 30
2
votes
1 answer

Passing a real[] as argument from a between plpython functions

I am new to python and I am trying to do some server programming in pl/python (in order to achive speedier processing) and after many attemps I decided to resource on this list to look for help. I want to call a pl/python function from another by…
2
votes
1 answer

How many plpython execution environments are opened in a query?

Are user defined functions in postgres (and greenplum) run in isolation? How many execution environments are open when I have a query with a plpythonu user-defined functions? Is there any shared python interpreter state when running a query? Say I…
christangrant
  • 9,276
  • 4
  • 26
  • 27
2
votes
2 answers

Using PL/Pythonu with virtualenv

I am writing function in postgres in python using the PL/Pythonu extension in postgres. I would like postgres to use my virutal environment (I am using virtualenv) instead of the global install. How do I go about doing this?
Barry Steyn
  • 1,563
  • 3
  • 19
  • 25
1
vote
1 answer

What is the correct way to load a dll library in Postgres PL/Python?

The following gives an error drop function testing(); CREATE FUNCTION testing() RETURNS text AS $$ import ctypes try: ctypes.windll.LoadLibrary("D:\\jcc.dll") except: import traceback plpy.error(traceback.format_exc()) return '' $$…
kakarukeys
  • 21,481
  • 10
  • 35
  • 48
1
vote
0 answers

Are `AFTER UPDATE` triggers `FOR EACH ROW` atomic?

I'd like to insert a row inside a "history" table whenever the original row gets modified (updated). I'd like to use original row's ID as a FOREIGN KEY for the history table. But this ID might change. Have a look at the example below: CREATE TABLE…
winwin
  • 958
  • 7
  • 25
1
vote
1 answer

How is PL/Python code executed by Postgresql

When a PL/Python procedure is executed, the python code is executed by a Python interpreter. My question is, is the Python interpreter running as a separate process, or is it a shared library that gets linked to the calling databases process? I'm…
Adam Van Oijen
  • 435
  • 3
  • 8
  • 17
1
vote
1 answer

pl/python TypeError: sequence item 21: expected string, int found

Friends: in PostgreSQL plpython, am trying to do an iterative search/replace in a text block 'data'. Using re-sub to define a match pattern, then call a function 'replace' to do the work. Objective is to have the 'replace' function called…
DrLou
  • 649
  • 5
  • 21
1
vote
2 answers

PL/Python: trying to understand global dictionary

I am using pl/python3u in postgres. In that environment I have imported pandas and networkx. I have created a simple function that builds a graph from information in the tables and it works perfectly. I now want to create other functions that…
MikeB2019x
  • 823
  • 8
  • 23
1
vote
0 answers

Installing PL/Python2 on Ubuntu for PostgreSQL 12

PL/Python, and specifically PL/Python 2, is a requirement for the MADlib extension - which appears to support Postgres 9.2+. I am using Postgres 12 on Ubuntu 20.04. Unfortunately, while I have symlinked Python2.7 to be the target for generic python,…
LanceRD
  • 51
  • 2
1
vote
0 answers

Where is the missing postgres-plpython-12 for Ubuntu 20.04, required for psycopg2?

There is no available package for postgres-plpython-12 https://packages.ubuntu.com/search?keywords=postgresql-plpython The psycopg2 library does not work with plpython3 (or does it)? psycopg2.errors.UndefinedFile: could not access file…
Darren Weber
  • 1,537
  • 19
  • 20