I was able to compile libpq for PG-8.3 on Vista, and build pyPgSQL-2.5.1.
Then I got:
File "c:\Python25\lib\site-packages\pyPgSQL\PgSQL.py", line 2210, in connect
return Connection(connInfo, client_encoding, unicode_results)
File "c:\Python25\lib\site-packages\pyPgSQL\PgSQL.py", line 2365, in __init__
raise DatabaseError, m
libpq.DatabaseError: Invalid format for PgVersion construction.
The "Invalid format for PgVersion?" problem is a simple code fix. pyPgSQL's pgversion.c basically calls:
postgres=# select version();
version
-----------------------------------------------------
PostgreSQL 8.3.5, compiled by Visual C++ build 1400
...but expects the result to always be of the form: "PostgreSQL M.m.p on ...", and mine doesn't follow that form. Commenting out some of the version parsing code fixes it:
PyErr_SetString(PyExc_ValueError,
"Invalid format for PgVersion construction.");
token = pg_strtok_r(s, " \t", &save_ptr);
if (strcmp(token, "PostgreSQL") != 0)
goto new_error;
vstr = pg_strtok_r((char *)NULL, " \t", &save_ptr);
token = pg_strtok_r((char *)NULL, " \t", &save_ptr);
/* if (strcmp(token, "on") != 0)
goto new_error; */
Those last two lines are what I commented out.
Yes indeed.
I too just encountered this "Invalid format for PgVersion?" problem while connecting to a PostgreSQL 8.3 server on a Windows XP box. PyPgSQL used to work fine connecting to PostgreSQL 8.2 (specifically, python-pgsql 2.5.1-2ubuntu3 "A Python DB-API 2.0 interface to PostgreSQL")
forgot to say version string:
PostgreSQL 8.3.6, compiled by Visual C++ build 1400