plpython

How to install PL/Python on PostgreSQL 9.3 x64 Windows 7?

痞子三分冷 提交于 2019-12-05 08:00:00
I have tried to install the PL/Python v2.x language inside PostgreSQL on my database running the query: CREATE EXTENSION plpythonu; (I got this from http://www.postgresql.org/docs/9.3/static/plpython.html ) But I'm getting this error: ERRO: não pôde acessar arquivo "$libdir/plpython2": No such file or directory ********** Error ********** ERRO: não pôde acessar arquivo "$libdir/plpython2": No such file or directory SQL state: 58P01 How to install this in an automated way? I need to install it on many computers. Typically this error message is a misleading one emitted by the Windows API

PostgreSQL PL/Python: call stored procedure in virtualenv

隐身守侯 提交于 2019-12-05 02:32:52
问题 When I call a PostgreSQL PL/Python stored procedure in my Python application, it seems to be executed in a separate process running as user postgres . So far, this only had the side effect that I had to make my logfile writable for both myself and the database user, so application and stored procedure can both write to it. Now however, I started using virtualenv and added a number of .pth files to my ~/.virtualenvs/virt_env/lib/python2.7/site-packages/ folder that add the paths to my modules

PostgreSQL PL/Python: call stored procedure in virtualenv

早过忘川 提交于 2019-12-03 17:31:40
When I call a PostgreSQL PL/Python stored procedure in my Python application, it seems to be executed in a separate process running as user postgres . So far, this only had the side effect that I had to make my logfile writable for both myself and the database user, so application and stored procedure can both write to it. Now however, I started using virtualenv and added a number of .pth files to my ~/.virtualenvs/virt_env/lib/python2.7/site-packages/ folder that add the paths to my modules to the Python path. When the stored procedure is executed, user postgres is not in the same virtual

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

落爺英雄遲暮 提交于 2019-12-02 05:57:59
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 '' $$ LANGUAGE plpythonu; select testing(); Error message: ERROR: ('Traceback (most recent call last):\n File "<string>", line 5, in __plpython_procedure_testing_1517640\n File "D:\\Python26\\Lib\\ctypes\\__init__.py", line 431, in LoadLibrary\n return self._dlltype(name)\n File "D:\\Python26\\Lib\\ctypes\\__init__.py", line 353, in __init__\n self._handle = _dlopen(self.

Unicode normalization in Postgres

烈酒焚心 提交于 2019-11-30 17:17:19
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 have found a solution from an old Postgres nabble mail list from 2009, using pl/python, create or replace function unicode_normalize(str text) returns text as $$ import unicodedata return unicodedata.normalize('NFC', str.decode('UTF-8')) $$ LANGUAGE PLPYTHONU; This works, as expected, but made me wonder if there was any way of doing it directly with

Unicode normalization in Postgres

Deadly 提交于 2019-11-30 16:33:04
问题 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 have found a solution from an old Postgres nabble mail list from 2009, using pl/python, create or replace function unicode_normalize(str text) returns text as $$ import unicodedata return unicodedata.normalize('NFC', str.decode('UTF-8')) $$ LANGUAGE

How to install 3rd party module for postgres pl/python?

扶醉桌前 提交于 2019-11-30 06:21:18
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: <type 'exceptions.ImportError'>: No module named lucene ********** Error ********** ERROR: PL/Python: PL/Python function "to_tsvector_luc" failed SQL state: XX000 Detail: <type 'exceptions.ImportError'>: No module named lucene How do I install the module into pl/python, so that I can import it from inside my stored procedure code? pl/python has access

How are import statements in plpython handled?

我们两清 提交于 2019-11-30 04:54:25
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? The import is executed on every function call. This is the same behavior you would get if you wrote a normal Python module with the import statement inside a function body as oppposed to at the module level. Yes, this will affect performance. You can work around this by caching your imports like this: CREATE FUNCTION test() RETURNS text LANGUAGE plpythonu AS $$ if 'json' in SD:

How to aggregate matching pairs into “connected components” in Python

馋奶兔 提交于 2019-11-30 00:25:30
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 of ABC" might be the same person, or might not be. Often examination of additional information (e.g., comparison of biographical data on "John Smith, director of XYZ" and "John Smith, director of ABC") makes it possible to resolve whether two observations are the same person or not. Conceptual version of the problem: In that spirit, am collecting

How to install 3rd party module for postgres pl/python?

久未见 提交于 2019-11-29 06:07:52
问题 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: <type 'exceptions.ImportError'>: No module named lucene ********** Error ********** ERROR: PL/Python: PL/Python function "to_tsvector_luc" failed SQL state: XX000 Detail: <type 'exceptions.ImportError'>: No module named lucene How do I install the