Re: Is it correct to raise an exception in a domain check
В списке pgsql-general по дате отправления:
| От | Tom Lane |
|---|---|
| Тема | Re: Is it correct to raise an exception in a domain check |
| Дата | |
| Msg-id | 805459.1749591064@sss.pgh.pa.us обсуждение |
| Ответ на | Is it correct to raise an exception in a domain check (Logan Grosz <logan.grosz@gmail.com>) |
| Список | pgsql-general |
Logan Grosz <logan.grosz@gmail.com> writes:
> I have a `DOMAIN` on `JSONB`. I need to verify the shape of the JSON, so I
> have a check expression written in PL/pgSQL. The docs say
>> Each constraint must be an expression producing a Boolean result
> Would it be correct to raise an exception to indicate a failed
> check?
It'd be better just to have the CHECK expression return false.
Admittedly, that's usually just going to end in an exception,
but pre-judging that inside the expression doesn't seem ideal.
An example of why not is that you'd break "soft" input error
handling in COPY.
As you say, there are some cases where it's hard to avoid
an exception, but I'm not sure that "better error message"
is a good justification for throwing one. Still, in the
end it's your own judgment to make.
regards, tom lane
В списке pgsql-general по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера