Handling SQL errors using libpq

From: brennan(at)unix2(dot)netaxs(dot)com (William Brennan)
To: pgsql-interfaces(at)postgresql(dot)org
Subject: Handling SQL errors using libpq
Date: 2002-11-21 18:37:07
Message-ID: nJ9D9.575$cX3.467535@newshog.newsread.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message Rudy Lippan 2002-11-21 19:20:52 Re: :PgSQL: More Queestions
Previous Message Jason E. Stewart 2002-11-21 17:06:20 Re: DBD::Pg timings