Skip to content

Instantly share code, notes, and snippets.

@dxdinh
Forked from Samuyi/passwd_func.sql
Created September 1, 2020 01:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dxdinh/c398329e318cb22e3124b3ea20846fcb to your computer and use it in GitHub Desktop.
Save dxdinh/c398329e318cb22e3124b3ea20846fcb to your computer and use it in GitHub Desktop.
passwd function for my article
CREATE FUNCTION passwd_func()
RETURNS TRIGGER
AS $$
BEGIN
IF length(NEW.password) < 10 OR NEW.password IS NULL THEN
RAISE EXCEPTION 'password cannot be less than 10 characters';
END IF;
IF NEW.NAME IS NULL THEN
RAISE EXCEPTION 'Name cannot be NULL';
END IF;
RETURN NEW;
END;
$$
LANGUAGE plpgsql;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment