To expand on Don's response...
If you have the latest pg database driver, the error condition will be described in the global tcl variable "errorInfo". You can use a regex to extract the constraint name that is associated with the unique constraint violation. That is, if you have named your constraints.
Randy