haskellari / postgresql-simple

Mid-level client library for accessing PostgreSQL from Haskell
Other
85 stars 43 forks source link

`constraintViolation` does not work with check constraints on domains #87

Open photz opened 2 years ago

photz commented 2 years ago

Currently, constraintViolation does not correcty parse the error message generated by Postgres when a check constraint on a domain is violated. So, for instance, if I define a domain like this:

create domain foo as int check (value <> 42);

and then do something to violate the constraint, like so

select 42::foo;

then the error message generated by Postgres is: value for domain foo violates check constraint "foo_check" constraintViolation in that case returns Nothing because it expected the domain name to be surrounded by quotation marks.

photz commented 2 years ago

Actually, the domain name is conditionally wrapped in quotation marks: https://github.com/postgres/postgres/blob/27b77ecf9f4d5be211900eda54d8155ada50d696/src/backend/utils/adt/domains.c#L184 format_type_be() quotes it, if there's whitespace, for example.