> fast-fail (the first check constraint violated would bubble the error upward) rather than slow-fail (collect all invalid fields and return the collection of errors, which IME is more common on average web forms or api requests)
... > Has a more ergonomic approach to validation-error collection been developed other than writing a large function to iterate the new record fieldwise against the schema?
Thats an interesting problem that makes sense in the context of form validation.
re: have the ergonomics improved -> no
but you could hack that behavior together like this:
```
create or replace function handle_errors(errors text[])
returns bool
language plpgsql
as $$begin
if errors = array[]::text[] then
return true;
end if;
raise exception using errcode='22000', message=(select string_agg(x, ', ') from unnest(errors) v(x));
end;$$;
create table account(
id int primary key,
email text,
first_name text
check (
handle_errors(
array[]::text[]
|| case when email is null then 'email must not be empty' else null end
|| case when first_name is null then 'first_name must not be empty' else null end
)
)
);insert into account(id, email, first_name)
values (1, null, null);
-- ERROR: email must not be empty, first_name must not be empty
```
not that I'd recommend it :)