I am using CentOS-6 with Python 3.8, PostgreSQL 12 and PyGreSQL 5.2.2. This is the error I get trying to insert data into my database.
>>> db.insert('settings', None, **data)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.8/site-packages/pg.py", line 2322, in insert
adapt = params.add
File "/usr/local/lib/python3.8/site-packages/pg.py", line 1667, in __getattr__
if self.db:
AttributeError: 'pg.Connection' object has no attribute 'escape_identifier'
Can anyone point me towards what is wrong?
The method
escape_identifieron the connection corresponds to the functionPQescapeIdentifierin libpq. It exists since PostgreSQL 9 which is required by PyGreSQL 5.2. PyGreSQL does not compile support for these functions if it is installed with theno-escaping-funcsoption or if it thinks PostgreSQL is older than version 9.Since you say that you have PostgreSQL 12 installed, a possible explanation could be that you still have the client library (
libpq) of an old PostgreSQL version installed as well, and thepg_configtool reports that old version. You should check this withpg_config --version. Thepg_configtool is inlibpq-devel, so make sure you havelibpqandlibpq-develinstalled for PostgreSQL 12.You can also try to explicitly enable the escaping functions by installing PyGreSQL with
python setup.py build_ext --escaping-funcs install, but you will still need the latestlibpq, and there will be other functions disabled as well when PyGreSQL thinks that libpq is too old. So the proper solution is to make surelibpqis up to date andpg_config --versionreports the corresponding PostgreSQL version.