aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-185/luca-ferrari/postgresql/ch-1.sql27
1 files changed, 27 insertions, 0 deletions
diff --git a/challenge-185/luca-ferrari/postgresql/ch-1.sql b/challenge-185/luca-ferrari/postgresql/ch-1.sql
new file mode 100644
index 0000000000..571e0ee4ae
--- /dev/null
+++ b/challenge-185/luca-ferrari/postgresql/ch-1.sql
@@ -0,0 +1,27 @@
+-- Perl Weekly Challenge 185
+-- Task 1
+
+CREATE SCHEMA IF NOT EXISTS pwc185;
+
+CREATE OR REPLACE FUNCTION
+pwc185.task1_plpgsql( mac_input text )
+RETURNS text
+AS $CODE$
+DECLARE
+ c int := 1;
+ d char;
+ mac_output text := '';
+BEGIN
+ mac_input := replace( mac_input, '.', '' );
+ FOREACH d IN ARRAY regexp_split_to_array( mac_input, '' ) LOOP
+ mac_output := mac_output || d;
+ IF c % 2 = 0 THEN
+ mac_output := mac_output || ':';
+ END IF;
+ c := c + 1;
+ END LOOP;
+
+ RETURN mac_output;
+END
+$CODE$
+LANGUAGE plpgsql;