changeset 3731:0d45a3c34900

schema: Added function to detect string representation of ISRS codes.
author Sascha Wilde <wilde@intevation.de>
date Mon, 24 Jun 2019 11:21:41 +0200
parents d9ac1c56bfe0
children b1fe61b58048
files schema/isrs_functions.sql
diffstat 1 files changed, 13 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/schema/isrs_functions.sql	Mon Jun 24 11:20:34 2019 +0200
+++ b/schema/isrs_functions.sql	Mon Jun 24 11:21:41 2019 +0200
@@ -210,3 +210,16 @@
     $$
     LANGUAGE plpgsql
     STABLE PARALLEL SAFE;
+
+
+-- Check if a given string looks like an ISRS code
+CREATE OR REPLACE FUNCTION is_ISRSstring(str text) RETURNS boolean
+AS $$
+BEGIN
+  str = upper(str);
+  RETURN (SELECT str SIMILAR TO '[A-Z]{2}[A-Z0-9]{13}[0-9]{5}')
+         AND is_country(substring(str from 1 for 2));
+END;
+    $$
+    LANGUAGE plpgsql
+    IMMUTABLE PARALLEL SAFE;