1
0
Fork 0
database/20230219044854_improve_functions.up.sql

30 lines
543 B
MySQL
Raw Normal View History

2023-02-18 23:55:18 -05:00
BEGIN;
CREATE OR REPLACE FUNCTION is_sane_text(value TEXT)
RETURNS BOOLEAN
IMMUTABLE
PARALLEL SAFE
LANGUAGE plpgsql
AS $$BEGIN
IF value IS NULL THEN
RETURN TRUE;
ELSE
RETURN value = btrim(value) AND length(value) > 0;
END IF;
END$$;
CREATE OR REPLACE FUNCTION is_language_code(value VARCHAR)
RETURNS BOOLEAN
IMMUTABLE
PARALLEL SAFE
LANGUAGE plpgsql
AS $$BEGIN
IF value IS NULL THEN
RETURN TRUE;
ELSE
RETURN value ~ '^[a-z]{2}$';
END IF;
END$$;
COMMIT;