Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

plpython bug - sre

Status
Not open for further replies.

gloonie

MIS
Dec 5, 2002
6
US
There seems to be a bug in PostgreSQL 7.3.2 when attempting to write a simple function using regular expressions. Attempting to import sre results in the error message:

found.exceptions.ImportError: No module named _sre

Has anyone had this problem? It completely stops Python development.

TIA,

Glenn
 
Are you sure this isn't a Python problem? I use regex all the time in PostgreSQL 7.3.2 and it works fine.

Why don't you post the code you are attempting to write, so we can get a better idea of the problem.

-------------------------------------------

My PostgreSQL FAQ --
 
It might well be a problem in Python (or at least a change. I am using Redhat 9.0 (kernel 2.4.20-13.9) with PostgreSQL 7.3.2.3 and Python 2.2.2.26.

I did notice that the same problem was reported to the PostgreSQL bug list on Fri, 6 Sep 2002 in an email entitled "problem with pl/python in 7.2.2". No reply was ever posted, so I don't know how that turned out.

Here is the example I use:

drop function replace_e_to_a(text);
DROP
postgres=# CREATE FUNCTION replace_e_to_a(text) RETURNS text AS
postgres-# '
postgres'#
postgres'# import re
postgres'# return ''this is a test''
postgres'# '
postgres-# LANGUAGE 'plpython';
CREATE
postgres=#
postgres=# select replace_e_to_a('text');
ERROR: plpython: Call of function `__plpython_procedure_replace_e_to_a_16596' failed.
exceptions.ImportError: No module named _sre
 
Did you compile PostgreSQL or install the RPM? Ditto for Python. Reason I mention this is that RedHat tends toward a non-standard directory layout (non Unix-like), and sometimes the default compile instructions can't find certain libraries.

-------------------------------------------

My PostgreSQL FAQ --
 
I just found an entry in the PostgreSQL 7.4 development doc that states the need for libpython.so. That does NOT come with the standards python rpm on Redhat. I will compile it and let you know if that's the problem. Thanks for the clues!

Glenn
 
I'm pretty sure that the problem in the lack of a libpython in the RPM. I tried to create one, and it seemed to work, but could not build PostgreSQL. Anyone have any other ideas?

TIA,

Glenn
 
Hi gloonie,

In order to use python functions/stored procedures you will need to compile python support into your RH 9 build of postgres. You can download the latest stable postgres source. Go over all the readme files when you unpack postgres. You enable functionality by passing parameters to the configure file. There is some command like ./configure --help that will list everything available for a build. You might try:

./configure --help > config.txt to redirect the output to a text file which you can open and read.

You will need to pass the configure all the default path for the postgres tree, libraries, etc. You may need to study the current postgres tree to see where everything is. Once you pass the configure script the RH 9 path parameters, all the binaries will placed into /var/lib/pgsql/bin.

Since RH dumps all of postgres in well established paths, do a search to see where postgres and pg_ctl are located. I don't remember for sure, but it seem like all the binaries are in /usr/bin by default. Then copy all the binaries created from the build and located in /var/lib/pgsql/bin to /usr/bin.

Also, you will need to edit the /etc/rc.d/init.d/postgresql startup script to change the version number to the number of the newly install postgres if you want postgres to run as a daemon everytime you bring the system up.

You might want to backup any data and change the current postgres path before building it new. For example the following command will move the current build to a new path:

mv /var/lib/pgsql /var/lib/pgsql_old

You can read the doc for instructions on how to backup.

LelandJ

Leland F. Jackson, CPA
Software - Master (TM)
Nothing Runs Like the Fox
 
Hi Leland123,

Thanks for the info. I will try rebuilding everything, but I am not sure whether or not the problem is with PostgreSQL or Python.

You see, with the standard RH9 and PostgreSQL, I can write stored procedures that work with most of the allowable modules. So far it is only the re module that I can't import into the script.

However, I will try rebuilding PostgreSQL, then Python.

The saga continues...

Glenn
 
Hi gloonie,

I did my build of postgres about six months ago, more as a proof of concept than anything else, except I did my build to include plperl. I didn't have any problems once I figured out how to pass postgres configure the parameters she needed and where everything went after the binaries were compiled. I just kept playing around with all the pieces until I had everything working the way I wanted.

There is one other step that needs to be done once you have postgres running with python support compiled in. I had to create a database like:

createlang plperl dbname

For you the command would be:

createlang plpython dbname

I think this command only need be entered once, but I've slept since building perl into my postgres database, and since I've only done this once, you might want to research this step more. I tried to find something on it, but didn't hit on anything definite with my google search, and for some reason I'm having trouble accessing the postgres web site.

The build I did was for postgres 7.3.1 and it was on RH 8.

Good luck with you build.

LelandJ


Leland F. Jackson, CPA
Software - Master (TM)
Nothing Runs Like the Fox
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top