Today I realized a number of points where PostgreSQL (v10.3) is rather lackluster and sparse in its error messages.
Re: Problems with Error Messages wrt Domains, Checks - Mailing list pgsql-hackers
From | David G. Johnston |
---|---|
Subject | Re: Problems with Error Messages wrt Domains, Checks |
Date | |
Msg-id | CAKFQuwbFLvUiVOV4N7a1Fdh6hQthuLZCy-WwcQ6w5Cp6C4MRyw@mail.gmail.com Whole thread Raw |
In response to | Problems with Error Messages wrt Domains, Checks (john frazer <johnfrazer783@gmail.com>) |
List | pgsql-hackers |
psql:db/experiments/pg-error-
fail-illegal-regex.sql:17: ERROR: invalid regular expression: parentheses () not balanced There are several problems with this error message:
FAILURE: the error is really in line 5 where a syntactically invalid RegEx is created; the fact that it is a RegEx and not a general string is obvious from the semantics of the
~
(tilde) operator at that point in time.
FAILURE: the offending RegEx is not referred to and not quoted in the error message.
As such, it could be anywhere in my many, many kLOCs big DB definition. I cannot even search the RegEx with a RegEx because all I know is some parenthesis is missing, somewhere:
RegExes cannot match parentheses,
and PG RegExes do not have a unique syntactic marker to them.
FAILURE: before the
insert
statement, everything runs dandy. We could have built an entire data warehouse application on top of a table definition that can never be syntactically processed but which will only fail when someone accidentally tries to insert a line.
FAILURE: I can select from a table with a syntactically invalid definition.
With only line B active, this gives:
psql:db/experiments/pg-error-
fail-no-constraint-name.sql:16 : ERROR: new row for relation "table_with_constraints" violates check constraint "field b must have 3 characters" DETAIL: Failing row contains (xxxx). SUCCESS: we get the name of the relation and the name of the violated rule.
SUCCESS: the offending piece of data is quoted.
FAILURE: we don't get the full name of the relation, which is "X"."table_with_constraints". Neither do we get the name of the column that received the offending value.
Lastly, with only line A (not line B) active:
psql:db/experiments/pg-error-
fail-no-constraint-name.sql:16 : ERROR: value for domain x.a_legal_regex violates check constraint "a_legal_regex_check" FAILURE: no reference to the affected table, column is made.
FAILURE: no reference to the offending piece of data is made
FAILURE: no reference to the offended constraint is made ("column a must start with x").
What are the best practices or workarounds for the above shortcomings? I've been trying for several hours to figure out what causes an error message a la
value for domain xxx violates check constraint "xxx_check"
by rewriting table definitions, inserting data row by row and so on, to no avail. What I need is a full chain of the objects (column -> table -> constraint -> domain -> check) that are involved in the error.
I'm writing this to the developers' list because I see the above observations as serious shortcomings in an otherwise great piece of software that can probably not be fixed by using client-side code only.
pgsql-hackers by date: