1
0
Fork 0
database/20230219044854_improve_functions.down.sql
2023-02-19 08:55:18 +04:00

21 lines
443 B
PL/PgSQL

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