1
0
Fork 0

Improve functions

This commit is contained in:
Alex Kotov 2023-01-25 20:10:19 +04:00
parent f9448ab188
commit ac06d83542
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08

View file

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