Re: Exception handling from trigger - Mailing list pgsql-sql

From Tom Lane
Subject Re: Exception handling from trigger
Date
Msg-id 16661.1092071643@sss.pgh.pa.us
Whole thread Raw
In response to Exception handling from trigger  (Vlad Dimitriu <vlad.dimitriu@base.ro>)
Responses Re: Exception handling from trigger
Re: Exception handling from trigger
List pgsql-sql
Vlad Dimitriu <vlad.dimitriu@base.ro> writes:
> I would like to handle the exceptions that a database returns. For example,
> if a "mycolumn" column is defined as varchar(64), I'd like to catch
> if the new.mycolumn is larger than 64 with my own trigger

You can't.  From a logical perspective this is sensible, because the
trigger is handed data already formed into a tuple.  If the presented
tuple contained a mycolumn value wider than 64 characters then it would
not be a legal value of the rowtype (any more than if, say, the column
value were an integer and not a varchar at all).

What I'd suggest if you want this is to remove the datatype restriction
and instead rely on your trigger to enforce the limitation.
        regards, tom lane


pgsql-sql by date:

Previous
From: Rod Taylor
Date:
Subject: Re: Exception handling from trigger
Next
From: Josh Berkus
Date:
Subject: Re: surrogate keys and replication.