[racket] DB library - postgres and user defined errors...

From: Ryan Culpepper (ryan at cs.utah.edu)
Date: Fri Nov 18 15:19:11 EST 2011

On 11/18/2011 12:41 PM, Curtis Dutton wrote:
> What is a good way to get user defined exceptions, written inside of
> postrges function to be reflected to the end user?
> Say I have an item table in a database and it has a unique 'name' column.
> When I call my 'create_item' function in the postgres database, and the
> name given conflicts with an existing row in that table, I would like
> the exception returned to be 'that name already exists' and then pass
> that message through my web interface down to the user.
> Of course other types of exceptions, that I didn't anticipate, don't
> ultimately get sent to my client and they just see an "OOPS!" message.

If you use RAISE (as described here: 
it should get translated to an exn:fail:sql exception, which preserves 
all of the error properties present (MESSAGE, HINT, etc) in an 
association list. The exn:fail:sql struct isn't currently exported, but 
I'll fix that.


Posted on the users mailing list.