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

How can I indicate that a postgresql plpython function argument can be any type?

I'm using (or trying to) the following function: CREATE FUNCTION replace_value(data JSON, key text, value anyelement) RETURNS JSON AS $$ import json d = json.loads(data) d[key] = value return json.dumps(d) $$ LANGUAGE…
Wayne Werner
  • 49,299
  • 29
  • 200
  • 290
3
votes
1 answer

Python can open file, PL/Python can't

Connected to mydb in PostgreSQL: mydb=# CREATE FUNCTION file_test () RETURNS text AS $$ if open('mydir/myfile.xsl'): return 'success' $$ LANGUAGE plpythonu; CREATE FUNCTION mydb=# SELECT file_test(); ERROR: IOError: [Errno 2] No such file or…
3
votes
0 answers

Calling a Python script file with a PL/Python function in PostgreSQL

I'm trying to call an external Python script file from a PostgreSQL function written in PL/Python. My intuition drove me to code something like this : CREATE OR REPLACE FUNCTION foo() Returns boolean AS $$ import subprocess cmd =…
Martin Tovmassian
  • 1,010
  • 1
  • 10
  • 19
3
votes
0 answers

How to Install extension python 3.3 for PostgreSQL 9.4 WINx64

I have problem with installing plpython3u for PostgreSQL 9.4 when I write: CREATE EXTENSION plpython3u; i have this message: ERROR: Could not load the library "C: / Program Files / PostgreSQL / 9.4 / lib / plpython3.dll": unknown error 126 SQL…
pyer
  • 85
  • 1
  • 1
  • 6
3
votes
1 answer

What is difference between plpython, plpythonu, plpython2u

what is difference between plpython, plpythonu, plpython2u. What does u and 2u mean. Looking around I could't find any info on that matter.
user505160
  • 1,176
  • 8
  • 25
  • 44
3
votes
2 answers

How to get the result of a query executed by plpy

I am working with postgres 9.3 and Python 2.7. In a plpython function, I want to execute a query that returns a boolean. How can I get the boolean result? For example: result = plpy.execute('select 1<2 ')
Andromida
  • 1,095
  • 1
  • 11
  • 28
3
votes
1 answer

postgresql 9 plpython2.dll not found

I am trying to enable PL/Python2 in my postgresql database. My setup is as follows windows 7 64-bit postgresql 9.2 64-bit In the \lib folder i have plpython3.dll but no plpython2.dll which I need as a function I need to use was written in…
tjmgis
  • 1,589
  • 4
  • 23
  • 42
3
votes
1 answer

How to return resultset with Plpython3 in Postgres

How can a plpython function return result set as a normal sql query resultset (not as text). Here is function definition - DROP FUNCTION IF EXISTS demo_report(); CREATE OR REPLACE FUNCTION demo_report() RETURNS SETOF AS $$ rv =…
Ravi Kumar
  • 1,382
  • 16
  • 22
3
votes
2 answers

Make pivot tables in sql like in spss

I have lots of data in PostgreSQL. But I need to do some pivot tables like it does SPSS. For example i have table with cities and states. create table cities ( city integer, state integer ); insert into cities(city,state) values…
norecces
  • 207
  • 3
  • 8
3
votes
1 answer

Can i share composite types across postgres and plpython

I have a composite type called tt to be used by all my plpgsql and plpythonu procedures. is there some kind of plpy. means of accessing the catalogue or schema in a consistent way so as to derive types or iterable structs to return without having to…
usbdongle
  • 81
  • 6
2
votes
1 answer

problem to access of the properties of an edge when using plpython3u in PostgreSQL to create functions

I implement python function for for the following query and i get correct answer, but when i try to create functions in postgreSQL by using plpython3u extension, it doesn't have any error but still doesn't return the results to the table. Also, I…
2
votes
2 answers

From a python module, called from a pl/python function, how to get the return value?

Is there any reason this function call would not return 'result'? CREATE OR REPLACE FUNCTION myfunction (input int, OUT result int) AS $$ result = mymodule.object(input,plpy) plpy.info(" ========= EXTRA-module result: ===",result) $$ LANGUAGE…
DrLou
  • 649
  • 5
  • 21
2
votes
4 answers

PostgreSQL 13 + Python 3.7.9 + plpython3u: 'psql: server closed the connection unexepectedly.' + 'The application has lost the database connection.'

I have added all of the details I could find, with all of the links, and there is no way to get plpython3u to work on Windows in PostgreSQL 13, it seems. OLD, since the accepted answer shows that v3.7.0 solves it: Better do not read through this…
questionto42
  • 7,175
  • 4
  • 57
  • 90
2
votes
1 answer

In Python, how to write back a stringIO text file to a zip archive, then back to bytea field in PostgreSQL?

A relative noob to Python, I've successfully pulled a text file, out of a zip archive, contained in a PostgreSQL bytea field, using this code: myzip = ZipFile(StringIO(rv[0]["archivefield"]), 'a') data = myzip.read("content.txt",'a') # *** WORK ON…
DrLou
  • 649
  • 5
  • 21
2
votes
0 answers

Use plpython in PostgreSQL13 function to connect pymssql error

I want to use plpython in postgresql's function. I installed Python3.9 and configured the path and some other configations, and I copied the python's dll into the pg directory (my server is windows server 2019, my pg is pg13), and I created the…
Jsy
  • 63
  • 7
1 2
3
11 12