Thread: Re: ERROR: Cannot insert a duplicate key into a unique

Re: ERROR: Cannot insert a duplicate key into a unique

From
Rachit Siamwalla
Date:
Count me in for error codes. You can just see part of the code i'm using to
deal with the problem (some of the error messages changed from 7.0 to 7.1 --
i had to fix that):
   def parseError(self, errval):       # first compile all the exceptions. Ideally we don't have to compile       # all
ofthem first, but this makes the code that much readable, and       # speed is not important in the error case.
re_refInt= re.compile('.*referential integrity.*')       re_dupKey = re.compile('.*duplicate key.*')       re_nullAttr
=re.compile('.*Fail to add null value in not null
 
attribute (.*)')       re_nonInt = re.compile('.*pg_atoi: error in "(.*)": can\'t parse.*')       re_nonBool =
re.compile('.*Badboolean external representation
 
\'(.*)\'')       re_nonIP = re.compile('.*invalid INET value.*')       re_nonTimestamp = re.compile('.*Bad timestamp
external
representation \'(.*)\'')       re_invalidAttribute = re.compile('.*Relation \'(.*)\' does not have
attribute \'(.*)\'.*')       re_deadlockDetected = re.compile('.*Deadlock detected.*')
       # various errors captured from posgres       # ERROR:  Relation 'users' does not have attribute 'blah'       #
ERROR: <unnamed> referential integrity violation - key in
 
managedservers stillreferenced from managedserverstatus       #       # ERROR:  Bad boolean external representation
'3.4.5.6'      # ERROR:  invalid INET value '3456' ## for ip       # ERROR:  ExecAppend: Fail to add null value in not
nullattribute
 
mystr       # ERROR:  Relation 'users' does not have attribute 'blah'       # pg_atoi: error in "hello": can't parse
"hello"      # ERROR:  Bad timestamp external representation 'fdsa'       # ERROR: Deadlock detected.
 


-----Original Message-----
From: Christopher Kings-Lynne [mailto:chriskl@familyhealth.com.au]
Sent: Thursday, September 13, 2001 3:31 AM
To: Haller Christoph; pgsql-hackers@postgresql.org
Subject: Re: [HACKERS] ERROR: Cannot insert a duplicate key into a
unique index


In our PHP app, we are also forced to parse error messages to get that kind
of information.  Register my vote for error codes (Tom Lane style...)

Chris

> -----Original Message-----
> From: pgsql-hackers-owner@postgresql.org
> [mailto:pgsql-hackers-owner@postgresql.org]On Behalf Of Haller Christoph
> Sent: Thursday, 13 September 2001 7:18 PM
> To: pgsql-hackers@postgresql.org
> Subject: [HACKERS] ERROR: Cannot insert a duplicate key into a unique
> index
>
>
> [HACKERS] ERROR:  Cannot insert a duplicate key into a unique index
>
> I'm working on a C code application using loads of
> insert commands.
> It is essential to distinguish between an error
> coming from a misformed command or other fatal
> reasons and a duplicate key.
> In either case, the PQresultStatus() returns
> PGRES_FATAL_ERROR
> I can check PQresultErrorMessage() for the
> error message above, but then I have to rely
> on this string never be changed.
> This is no good programming style.
> Does anybody have another, better idea or is
> there at least a header file available, where
> all the error messages can be found?
>
> Regards, Christoph
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
>


---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org