Handling SQL errors using libpq - Mailing list pgsql-interfaces

From brennan@unix2.netaxs.com (William Brennan)
Subject Handling SQL errors using libpq
Date
Msg-id nJ9D9.575$cX3.467535@newshog.newsread.com
Whole thread Raw
Responses Re: Handling SQL errors using libpq  (Oliver Elphick <olly@lfix.co.uk>)
List pgsql-interfaces
I'm new to Postgresql, so please bear with me.

After a call to libpq, I would like to be able to recognize specific 
SQL errors which might occur, beyond the simple results obtainable
via a call to PQresultStatus().  I want more precision.

For example, I have a table with a primary key.  If I attempt to insert
a new row with a duplicate key, PQresultStatus() rightly returns an
error (PGRES_FATAL_ERROR).  However my program has no way to distinguish
from this blunt instrument whether it's a duplicate-key problem, or
any of hundreds of other problems.

How should my program recognize the duplicate-key error?  And more
generally, how to I reconize other anticipated SQL errors?

Thanks for your help!

-- Bill


pgsql-interfaces by date:

Previous
From: "Jason E. Stewart"
Date:
Subject: Re: DBD::Pg timings
Next
From: Tim Bunce
Date:
Subject: Re: :PgSQL: More Queestions