De: David G. Johnston <david.g.johns...@gmail.com> Enviada: 11 de maio de 2025 01:58
ALTER TABLE table_name ADD CONSTRAINT constraint_name CHECK (condition) MESSAGE 'Custom error message when the condition is not met.'; >> I’m seeing some value here but, odds are, there is not enough obvious >> benefit or design to convince someone else to try and envision specifically >> how the behavior should work and effort to push it through. if I have to use a trigger to set a different message, then I have to write the same rule twice, in CHECK and TRIGGER, which is redundant. -------------------------------------------------------------------------------------------------------------------------- Improved User Experience: Applications could capture and display more contextual and helpful error messages to end-users, improving usability and reducing confusion. >> Arguably a layering violation. To make this point more clearly, do you need >> to account for i18n? No -------------------------------------------------------------------------------------------------------------------------- Enhanced Debugging: Developers could immediately identify the specific business rule that has been violated, speeding up the debugging and resolution of data integrity issues. >> Is there really a meaningful gap here? I think there is a significant gap here, especially in complex constraints. The constraint name does not always reveal which specific part of the business rule was violated, which can delay debugging. Personalized messages could provide this information directly -------------------------------------------------------------------------------------------------------------------------- Implicit Documentation: The custom message would serve as a way to document the intent of the constraint directly within the database schema, facilitating understanding and maintenance of the data model. >> Constraints can be targeted by “comment on”. I agree, but the proposal aims at specific error messages when the constraint is violated, for better feedback in development and in applications. -------------------------------------------------------------------------------------------------------------------------- Consistency: It would allow for a more consistent approach to providing informative feedback on business rule violations, complementing the existing capability in triggers. Two different tools that can do the same job. One with structure and one customizable. Because triggers exist the proposed feature is less useful. Best regards, Miguel Ferreira