1
0
Fork 0
database/20230125142000_functions.up.sql

22 lines
421 B
MySQL
Raw Normal View History

2023-01-25 10:27:20 -05:00
BEGIN;
CREATE FUNCTION is_sane_text(value TEXT)
2023-01-25 11:10:19 -05:00
RETURNS BOOLEAN
IMMUTABLE
PARALLEL SAFE
LANGUAGE plpgsql
2023-01-25 10:46:16 -05:00
AS $$BEGIN
2023-01-25 11:10:19 -05:00
RETURN value IS NOT NULL AND value = btrim(value) AND length(value) > 0;
2023-01-25 10:46:16 -05:00
END$$;
2023-01-25 10:27:20 -05:00
2023-01-25 11:10:19 -05:00
CREATE FUNCTION is_language_code(value VARCHAR)
RETURNS BOOLEAN
IMMUTABLE
PARALLEL SAFE
LANGUAGE plpgsql
2023-01-25 10:46:16 -05:00
AS $$BEGIN
2023-01-25 11:10:19 -05:00
RETURN value IS NOT NULL AND value ~ '^[a-z]{2}$';
2023-01-25 10:46:16 -05:00
END$$;
2023-01-25 10:27:20 -05:00
COMMIT;