Add some functions
This commit is contained in:
parent
65a56d33d7
commit
d74f8fc584
2 changed files with 20 additions and 0 deletions
4
20230125142000_functions.down.sql
Normal file
4
20230125142000_functions.down.sql
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
BEGIN;
|
||||||
|
DROP FUNCTION is_name;
|
||||||
|
DROP FUNCTION is_language_code;
|
||||||
|
COMMIT;
|
16
20230125142000_functions.up.sql
Normal file
16
20230125142000_functions.up.sql
Normal 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;
|
Loading…
Reference in a new issue