Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id D6AAB475AE5 for ; Thu, 21 Nov 2002 13:37:15 -0500 (EST) Received: from news.hub.org (news.hub.org [64.49.215.80]) by postgresql.org (Postfix) with ESMTP id 66C1D475921 for ; Thu, 21 Nov 2002 13:37:15 -0500 (EST) Received: by news.hub.org (Postfix, from userid 8) id 4ADA943A6E1; Thu, 21 Nov 2002 13:37:15 -0500 (EST) X-Newsgroups: comp.databases.postgresql.interfaces Subject: Handling SQL errors using libpq Distribution: comp.databases.postgresql.interfaces Organization: Net Access, Philadelphia, PA From: brennan@unix2.netaxs.com (William Brennan) Lines: 18 Message-ID: Date: Thu, 21 Nov 2002 18:37:07 GMT X-Complaints-To: Abuse Role , We Care To: pgsql-interfaces@postgresql.org X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200211/141 X-Sequence-Number: 3389 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