How to get column, table or parameter name reporting when violating DOMAIN type constraint

Поиск
Список
Период
Сортировка
От Valerio Battaglia
Тема How to get column, table or parameter name reporting when violating DOMAIN type constraint
Дата
Msg-id CACxJNSkpT8vC0jnsfObZDargLA1vCiP-VKF2ji9y58VaAOSpVA@mail.gmail.com
обсуждение исходный текст
Ответы Re: How to get column, table or parameter name reporting when violating DOMAIN type constraint  ("David G. Johnston" <david.g.johnston@gmail.com>)
Список 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 по дате отправления:

Предыдущее
От: Laurenz Albe
Дата:
Сообщение: Re: PgAdmin Lapse
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: How to get column, table or parameter name reporting when violating DOMAIN type constraint