Forum OpenACS Q&A: ad_form validation
In this way you avoid accessing the database in the case where there are no unique violations.
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.