From e248b2f4fefeed28f09546e24fb6d7dc9b935d6e Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 3 Oct 2022 11:04:39 +0200 Subject: Task 1 plpgsql done --- challenge-185/luca-ferrari/postgresql/ch-1.sql | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 challenge-185/luca-ferrari/postgresql/ch-1.sql 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; -- cgit