加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

PostgreSQL 9.1: Installing plpythonu/plpython3u (Python) in

发布时间:2020-12-13 17:30:41 所属栏目:百科 来源:网络整理
导读:PostgreSQL 9.1: Installing plpythonu/plpython3u (Python) in Windows Install plpython3u If you're lucky,the following command will just work,and the Python language has been successfully installed: Select All 1 CREATE EXTENSION plpython3u ;

PostgreSQL 9.1: Installing plpythonu/plpython3u (Python) in Windows

Install plpython3u

If you're lucky,the following command will just work,and the Python language has been successfully installed:

Select All
1
CREATE EXTENSION plpython3u;

If you encounter the following error:

1
ERROR:  could not load library "C:/Program Files/PostgreSQL/9.1/lib/plpython3.dll": The specified module could not be found.

We have a little more work to do.

PostgreSQL 9.1 requires a VERY specific sub-version of the Python DLL: Python 3.2.x. (availablehere) Any other version (3.1.x,3.3.x,or otherwise) will cause the installation of plpython3u to fail. In addition,PostgreSQL 9.1 unfortunately does not appear to ship with Python 2.x support either.

If Python 3.2.x is not installed,download and install it.

Browse to your Python 3.2.x installation directory. By default,this should be something similar to: C:Python32. From here,navigate to theDDLsdirectory and locate a DLL namedpython3.dll.

In a separate window,browse to you PostgreSQL installation directory. By default,this should be something similar to: C:Program FilesPostgreSQL9.1. From there,navigate into thelibdirectory and copy the python3.dll from the other window into this directory. Rename the copied DLL from python3.dll topython32.dll.

Finally,attempt to run the CREATE EXTENSION command again:

CREATE EXTENSION plpython3u;

This time,you should receive the expected result; signalling the installation was successful.

CREATE EXTENSION

Testing Your plpython3u Extension

First,we need a stored procedure which utilizes the Python language:

1 2 3 4 5 6 7
DROP FUNCTION test_fn(a integer, b integer);
CREATE OR REPLACE )
RETURNS text AS $$
	result = object()
	import pickle
	return pickle.dumps({'a':a, 'b':b})
$$ LANGUAGE plpython3u

Now,let's query our new function:

SELECT test_fn(1,2)

You should receive a response similar to the following:

b'x80x03}qx00(Xx01x00x00x00aqx01Kx01Xx01x00x00x00bqx02Kx02u.'
原地址 http://www.youlikeprogramming.com/2013/08/postgresql-9-1-installing-plpythonuplpython3u-python-in-windows/

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读