Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHECK constraint with a name #780

Open
xamgore opened this issue May 20, 2024 · 0 comments
Open

CHECK constraint with a name #780

xamgore opened this issue May 20, 2024 · 0 comments

Comments

@xamgore
Copy link

xamgore commented May 20, 2024

Motivation

Having a schema with defined constraint checks, I'd like to see a meaningful error message.

.check(Expr::col(Products::Price).gt(0))

Without it, all we'll get is:

⛔️ new row for relation "products" violates check constraint "products_check".

Proposed Solutions

Extend the API in a way it could introduce names for constraints.

CREATE TABLE products (
    product_no integer,
    name text,
    price numeric CONSTRAINT positive_price CHECK (price > 0)
--                           ^^^^^^^^^^^^^^
);

Matching error messages against those "positive_price" names allows translating them for end users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant