Improve functions
This commit is contained in:
parent
9ae355f105
commit
f9f0dbe246
2 changed files with 50 additions and 0 deletions
21
20230219044854_improve_functions.down.sql
Normal file
21
20230219044854_improve_functions.down.sql
Normal file
|
@ -0,0 +1,21 @@
|
|||
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;
|
29
20230219044854_improve_functions.up.sql
Normal file
29
20230219044854_improve_functions.up.sql
Normal file
|
@ -0,0 +1,29 @@
|
|||
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;
|
Loading…
Add table
Reference in a new issue