Skip to content

CHECK constraint with a name #780

@xamgore

Description

@xamgore

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions