summaryrefslogtreecommitdiff
path: root/src/db/rest/util/_api_trim.sql
diff options
context:
space:
mode:
Diffstat (limited to 'src/db/rest/util/_api_trim.sql')
-rw-r--r--src/db/rest/util/_api_trim.sql25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/db/rest/util/_api_trim.sql b/src/db/rest/util/_api_trim.sql
new file mode 100644
index 0000000..c972282
--- /dev/null
+++ b/src/db/rest/util/_api_trim.sql
@@ -0,0 +1,25 @@
+CREATE FUNCTION _api.trim(
+ _text TEXT
+)
+RETURNS TEXT
+LANGUAGE plpgsql VOLATILE
+AS $BODY$
+DECLARE
+ _new TEXT;
+BEGIN
+
+ IF _text IS NULL THEN
+ RETURN NULL;
+ END IF;
+
+ _new = _text;
+ _new = TRIM(_new);
+ _new = REGEXP_REPLACE(_new, '^(?: |\r|\n)*', '');
+ _new = REGEXP_REPLACE(_new, '(?: |\r|\n)*$', '');
+
+ RETURN _new;
+END
+$BODY$;
+
+GRANT EXECUTE ON FUNCTION _api.trim(TEXT)
+ TO rest_anon, rest_user;