Re: postgresql error code

"James Henstridge" <[email protected]>
Newsgroups gmane.comp.python.db.psycopg.devel
Message-ID <[email protected]>
On 06/03/2008, Dražen Odobašić <[email protected]> wrote:
> Is there a way to get postgresql error code when exception occures, i
>  did found some reference that psycopg2 is the only one library that has
>  this implemented. Still, i have no idea how to accomplish this. Can
>  someone help me?

There is a pgcode attribute on the exceptions returned by psycopg2
which holds the SQLSTATE error code documented in the PostgreSQL
documentation.

For released versions of psycopg2 you can only expect this to be set
on errors from execute().  For 2.0.7, it will be set to None by
default everywhere and more methods will set SQLSTATE appropriately
(e.g. commit() and rollback()).

James.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.