When i wrote the functions to import contact, i already created a couple of “temporary” functions to validate whether the input given from the Excel files was correct according to the various domains used in the relations, so i can know whether i can import that data. I realized that i could do exactly the same when validating forms: check that the value conforms to the domain, in the exact same way, so i can make sure that the value will be accepted without duplicating the logic, at the expense of a call to the database. In an ideal world, i would use pg_input_is_valid, but this function is only available in PostgreSQL 16 and Debian 12 uses PostgreSQL 15. These functions are in the public schema because initially i wanted to use them to also validate email, which is needed in the login form, but then i recanted and kept the same email validation in Go, because something felt off about using the database for that particular form, but i do not know why.
8 lines
138 B
PL/PgSQL
8 lines
138 B
PL/PgSQL
-- Verify numerus:input_is_valid on pg
|
|
|
|
begin;
|
|
|
|
select has_function_privilege('public.input_is_valid(text, text)', 'execute');
|
|
|
|
rollback;
|