pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: brennan@unix2.netaxs.com
To: pgsql-interfaces@postgresql.org
Subject: Handling SQL errors using libpq
Date: Thu, 21 Nov 2002 18:37:07 GMT
Message-ID: <nJ9D9.575$cX3.467535@newshog.newsread.com> (raw)

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



view thread (2+ messages)  latest in thread

Message-ID: <nJ9D9.575$cX3.467535@newshog.newsread.com>
Permalink:  ../nJ9D9.575$cX3.467535@newshog.newsread.com/
Also on:    postgresql.org/message-id/nJ9D9.575$cX3.467535@newshog.newsread.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: brennan@unix2.netaxs.com
  Subject: Re: Handling SQL errors using libpq
  In-Reply-To: <nJ9D9.575$cX3.467535@newshog.newsread.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox