PostgreSQL PL/Python - Python Procedural Language 安装
2015-07-25 11:13
706 查看
PL/Python - Python Procedural Language 安装
前提是你系统里安装了python2,python3,pg数据库。查看系统提供plpython包(已经编译好的)。
[code][root@localhost ~]# dnf search python |grep postgresql python3-postgresql.x86_64 : Connect to PostgreSQL with Python 3 python-storm-postgresql.x86_64 : PostgreSQL backend for python-storm postgresql-plpython.x86_64 : The Python2 procedural language for PostgreSQL postgresql95-plpython.x86_64 : The Python procedural language for PostgreSQL postgresql94-plpython.x86_64 : The Python procedural language for PostgreSQL postgresql-plpython3.x86_64 : The Python3 procedural language for PostgreSQL postgresql94-python-debuginfo.x86_64 : Debug information for package : postgresql94-python postgresql94-python.x86_64 : Development module for Python code to access a python-testing.postgresql.noarch : Automatically setup a PostgreSQL testing python3-testing.postgresql.noarch : Automatically setup a PostgreSQL testing
我用的是fedora22系统。postgresql-plpython.x86_64、postgresql-plpython3.x86_64是我们需要安装的(Python2和Python3版本都支持)。
安装插件包
[code][root@localhost ~]# dnf install postgresql-plpython.x86_64 [root@localhost ~]# dnf install postgresql-plpython3.x86_64
检查一下安装目录是否有插件:
[code]-bash-4.3$ pwd /usr/share/pgsql/extension -bash-4.3$ ll |grep python -rw-r--r--. 1 root root 351 6月 13 03:06 plpython2u--1.0.sql -rw-r--r--. 1 root root 196 6月 13 03:06 plpython2u.control -rw-r--r--. 1 root root 402 6月 13 03:06 plpython2u--unpackaged--1.0.sql -rw-r--r--. 1 root root 351 6月 13 03:06 plpython3u--1.0.sql -rw-r--r--. 1 root root 196 6月 13 03:06 plpython3u.control -rw-r--r--. 1 root root 402 6月 13 03:06 plpython3u--unpackaged--1.0.sql -rw-r--r--. 1 root root 347 6月 13 03:06 plpythonu--1.0.sql -rw-r--r--. 1 root root 194 6月 13 03:06 plpythonu.control -rw-r--r--. 1 root root 393 6月 13 03:06 plpythonu--unpackaged--1.0.sql -bash-4.3$
plpython3u.control、plpython2u.control等已经有了。
pg数据库安装plpython扩展
[code]CREATE EXTENSION plpython3u; CREATE EXTENSION plpython2u;
上述sql的执行可以在pgAdmin IDE工具里执行(有权限用户)。可以查看是否安装了扩展。
试一下创建一个函数:
[code]CREATE FUNCTION pymax (a integer, b integer) RETURNS integer AS $$ if a > b: return a return b $$ LANGUAGE plpython3u;
执行一下:
[code]select pymax(12,13);
输出13。
pgAdmin 查看已经安装的扩展图:
错误处理:
错误处理错误: 无法打开扩展控制文件 "/usr/share/pgsql/extension/plpythonu3.control": 没有那个文件或目录********** 错误 **********
错误: 无法打开扩展控制文件 "/usr/share/pgsql/extension/plpythonu3.control": 没有那个文件或目录SQL 状态: 58P01
上述错误表示插件安装包没能安装正确。必须确保pg扩展目录内有,才可以。
相关文章推荐
- Python自动扫雷实现方法
- Python导出DBF文件到Excel的方法
- Python实现的RSS阅读器实例
- Python获取央视节目单的实现代码
- python学习之模块添加
- Python实现将DOC文档转换为PDF的方法
- python ,java 变量作用域
- 90行python搭一个音乐搜索工具 —— Song Finder
- Python 异常
- Python学习-String(一)
- python抓价记(4)
- Python实现将DOC文档转换为PDF的方法
- Python实现的RSS阅读器实例
- Python导出DBF文件到Excel的方法
- Python自动扫雷实现方法
- Python实现对excel文件列表值进行统计的方法
- Python基于PycURL实现POST的方法
- Python基于PycURL自动处理cookie的方法
- Python实现截屏的函数
- Python实现简单的代理服务器