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
2 answers

how to parameter-ize a query's WHERE clause within pl/python?

Friends: Have been trying to parameter-ize into a query in pl/python - and am surely missing something simple here; I've tried % and $ prepends to the variable name, with no luck. (also haven't been able to pass a result variable into the python…
DrLou
  • 649
  • 5
  • 21
2
votes
4 answers

Install PL/Python on Windows for PostgreSQL 12

I've been working on FHIR for a project and we are using PostgreSQL as a database. While reading docs, I've come to know about PL/Python and decided to give it a shot but I am unable to install the python extension. When I run the command CREATE…
Khizar Iqbal
  • 435
  • 2
  • 11
  • 18
2
votes
2 answers

how to change Python version used by plpython on Mac OSX?

I have installed PostgreSQL 9.0.4 on Mac OSX 10.6 using the installer from EnterpriseDB and noticed that stored procedures implemented in plpython use python 2.5. A look into the plpython library seems to confirm that (otool sort of does on the mac…
ssc
  • 9,528
  • 10
  • 64
  • 94
2
votes
2 answers

Is there a way to remove the “plpy.Error:” prefix from an exception raised with `plpy.error`?

In a PL/pgSQL function, RAISE EXCEPTION 'mymessage' USING ...; will have “mymessage” as the error message, but in a PL/Python function, plpy.error('mymessage', ...) will have “plpy.Error: mymessage” as the error message. Is there a straightforward…
Zachary Yaro
  • 196
  • 12
2
votes
1 answer

PL/Python3 with VARIADIC arrays as arguments

I'm using plpython3u to process a result that contains an arbitrary number of columns each of which hold an array (of varying lengths > 0). In python, I'd be expecting to process this data as a multidimensional array but I'm having trouble getting…
2
votes
1 answer

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…
Dave
  • 39
  • 5
2
votes
1 answer

Python3 PyPDF2 - how to treat file handlers as BytesIO objects?

Have a nice, tested bit of python PyPDF2 code a .py designed to operate on 'real' OS files. Having debugged it all, I am now trying to incorporate it into a plPython function, replacing files with io.BytesIO() - or whatever mechanism would be the…
DrLou
  • 649
  • 5
  • 21
2
votes
2 answers

postgresql set default value in trigger

i have a "before update trigger" on a table. How to set default value on a column ? : CREATE OR REPLACE FUNCTION trigger() RETURNS TRIGGER AS $$ TD["new"]["test"] = DEFAULT # Doesn't work $$ LANGUAGE plpython2u VOLATILE;
2
votes
2 answers

global variables in pl/python

The following code works fine in my python IDE: counter = 1000 def increment(): global counter counter += 1 increment() print(counter) But when I copy and paste the code in a pl/python function (as below), it doesn't work. counter =…
user275801
  • 1,235
  • 1
  • 10
  • 13
2
votes
1 answer

Pl\Python: issues when importing module

I have successfully setup plpyton3u extension in Postgresql 10 (64 bit) on my windows 10 (64 bit) machine. However, when i try to make a http request by calling requests module I am getting attribute error AttributeError: 'module' object has no…
2
votes
2 answers

Handling backslashes in plpython

CREATE OR REPLACE FUNCTION CLEAN_STRING(in_str varchar) returns varchar AS $$ def strip_slashes(in_str): while in_str.endswith("\\") or in_str.endswith("/"): in_str = in_str[:-1] in_str = in_str.replace("\\", "/") return…
Deepak K M
  • 521
  • 1
  • 5
  • 13
2
votes
1 answer

PostgreSQL - Python - Trigger - Access to current_user

I am writing an audit trigger in plPython. I cannot figure out how to get access to the current_user variable. Is it available via plpy somehow? I would also like to know if it is possible to pass variables into a trigger function? If so how is this…
Crashmeister
  • 375
  • 1
  • 14
2
votes
1 answer

Is there a way to install PL/Python after the database has been compiled without "--with-python" parameter?

Ubuntu 14.04.3, PostgreSQL 9.6 Maybe I can get the plpythonu source code from the PostgreSQL 9.6 source code or somewhere else, put it into the /contrib directory, make it and CREATE EXTENSION after that!? Or something like that. Don't want to think…
Pavel Ganin
  • 21
  • 1
  • 2
2
votes
1 answer

Call postgres PL/Python stored function from another PL/Python block

Is it possible to call PL/Python function from other PL/Python block as a normal Python function. For example, I have a function f1: create or replace function f1() returns text as $$ return "hello" $$ language 'plpython3u'; I want call this…
lodopidolo
  • 175
  • 2
  • 10
2
votes
2 answers

Pass custom error code (ERRCODE) with a plpy.error or a custom SPIError

Is it possible to pass a custom error code with plpy.error/fatal or inherit SPIError to pass a custom ERRCODE, HINT, etc?
hooblei
  • 3,210
  • 2
  • 20
  • 17