Re: Request for Implementation of Custom Error Messages for CHECK Constraints - Mailing list pgsql-hackers

From Marcos Pegoraro
Subject Re: Request for Implementation of Custom Error Messages for CHECK Constraints
Date
Msg-id CAB-JLwbM6FPanbpjynt5VLPbgD3+5fxKcLZOnvFSe5yrHHQmig@mail.gmail.com
Whole thread Raw
In response to Request for Implementation of Custom Error Messages for CHECK Constraints  ("Miguel Ferreira" <miguelmbferreira@gmail.com>)
List pgsql-hackers
Em sáb., 10 de mai. de 2025 às 21:57, David G. Johnston <david.g.johnston@gmail.com> escreveu:
Constraints can be targeted by “comment on”.

So, why not using that COMMENT ON message to raise when that constraint gets violated ?
A GUC like Constraint_Exception_Returns_MessageOn = {Never | Always | If_Exists}
with its default value set to Never, so it runs like today, but if changed to If_Exists it will try to 
get that message or always, to show that COMMENT ON, even empty.

alter table b add constraint fk_b_a foreign key(ID) references a(ID);
comment on constraint fk_b_a on b is 'There is a problem on Foreign Key on Table B related to Table A';

regards
Marcos
 

pgsql-hackers by date:

Previous
From: Álvaro Herrera
Date:
Subject: Re: Valgrind - showing memory leaks
Next
From: Álvaro Herrera
Date:
Subject: Re: Trivial comment fix for tsquerysend()