Thread: message for constraint

message for constraint

From
Jaime Casanova
Date:
Hi,

From time to time people ask me if there is a way to "customize"
messages for constraints so they could be more informative to the
user...

Imagine something like:

create table foo (fld int4 check (fld > 0));
message for constraint foo_fld_check on foo is 'fld field must contain
possitive numbers only.';

so i can let this message go directly to my users, and they can
respond without knowing waht a check constraint is...

we can use the pg_description catalog with a column added to indicate
if it is a comment or a message for constraint...

what do you think, it's worth the effort?

--
regards,
Jaime Casanova
(DBA: DataBase Aniquilator ;)


Re: message for constraint

From
Peter Eisentraut
Date:
Jaime Casanova wrote:
> From time to time people ask me if there is a way to "customize"
> messages for constraints so they could be more informative to the
> user...

What about this?

=> create table foo (fld int4 constraint "fld must contain positive numbers" check (fld > 0));
CREATE TABLE
=> insert into foo values (-5);
ERROR:  new row for relation "foo" violates check constraint "fld must contain positive numbers"

-- 
Peter Eisentraut
http://developer.postgresql.org/~petere/


Re: message for constraint

From
Jaime Casanova
Date:
On 1/14/06, Peter Eisentraut <peter_e@gmx.net> wrote:
> Jaime Casanova wrote:
> > From time to time people ask me if there is a way to "customize"
> > messages for constraints so they could be more informative to the
> > user...
>
> What about this?
>
> => create table foo (fld int4 constraint "fld must contain positive numbers" check (fld > 0));
> CREATE TABLE
> => insert into foo values (-5);
> ERROR:  new row for relation "foo" violates check constraint "fld must contain positive numbers"
>
> --
> Peter Eisentraut
> http://developer.postgresql.org/~petere/
>

ok, i didn't know you can use such names...

--
regards,
Jaime Casanova
(DBA: DataBase Aniquilator ;)