How to get column, table or parameter name reporting when violating DOMAIN type constraint - Mailing list pgsql-novice

From Valerio Battaglia
Subject How to get column, table or parameter name reporting when violating DOMAIN type constraint
Date
Msg-id CACxJNSkpT8vC0jnsfObZDargLA1vCiP-VKF2ji9y58VaAOSpVA@mail.gmail.com
Whole thread Raw
Responses Re: How to get column, table or parameter name reporting when violating DOMAIN type constraint
List pgsql-novice
Hi,

I am reaching out to request assistance with obtaining column, table or parameter name when a DOMAIN type constraint is violated in PostgreSQL. Specifically, I am looking for a way to easily identify the column or parameter that is causing the constraint violation, so that I can have better error / validation reporting in the client.

Imagine the following SQL code:
CREATE DOMAIN my_domain AS integer
CONSTRAINT value_min CHECK (VALUE > 0)
CONSTRAINT value_max CHECK (VALUE <= 200); CREATE FUNCTION my_function(first_parameter my_domain, second_parameter my_domain) RETURNS void AS $$ BEGIN INSERT INTO my_table (first_column, second_column) VALUES (first_parameter, second_parameter); END; $$ LANGUAGE plpgsql;
When I call this function with a value that violates the DOMAIN type constraint, I receive the following error message:
SELECT my_function(100, -100);
-- ERROR: value for domain my_domain violates check constraint "value_min"

However, this error message does not provide any information about which column or parameter is causing the constraint violation. The same scenario applies when calling the INSERT INTO statement directly as well.

Is there a way to obtain more detailed information about the column, table or parameter that is causing the constraint violation in this scenario? I would greatly appreciate any guidance or advice you could provide on this matter.

Thanks

pgsql-novice by date:

Previous
From: Laurenz Albe
Date:
Subject: Re: PgAdmin Lapse
Next
From: "David G. Johnston"
Date:
Subject: Re: How to get column, table or parameter name reporting when violating DOMAIN type constraint