1
0
Fork 0

Add some functions

This commit is contained in:
Alex Kotov 2023-01-25 19:27:20 +04:00
parent 65a56d33d7
commit d74f8fc584
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
2 changed files with 20 additions and 0 deletions

View file

@ -0,0 +1,4 @@
BEGIN;
DROP FUNCTION is_name;
DROP FUNCTION is_language_code;
COMMIT;

View file

@ -0,0 +1,16 @@
BEGIN;
CREATE FUNCTION is_name(value TEXT) RETURNS BOOLEAN LANGUAGE plpgsql AS $$
BEGIN
RETURN value = btrim(value) AND length(value) > 0;
END;
$$;
CREATE FUNCTION is_language_code(value VARCHAR) RETURNS BOOLEAN LANGUAGE plpgsql
AS $$
BEGIN
RETURN value ~ '^[a-z]{2}$';
END;
$$;
COMMIT;