Slide 26
Slide 26 text
PostgreSQL Example
-- Create a user
create function create_user(new_name VARCHAR, new_email varchar, new_phone varchar, OUT data jsonb) as $$
BEGIN
insert into users(name, email, phone) values(new_name, new_email, new_phone);
data := get_user(new_email);
Exception when integrity_constraint_violation then
if sqlerrm like '%valid_phone%' then
RAISE 'The phone format is invalid' USING CONSTRAINT = 'valid_phone';
ELSIF sqlerrm like '%valid_email%' then
RAISE 'The email format is invalid' USING CONSTRAINT = 'valid_email';
END IF;
END;
$$ LANGUAGE PLPGSQL;