aboutsummaryrefslogtreecommitdiff
path: root/challenge-275/luca-ferrari/plpgsql/ch-2.sql
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-275/luca-ferrari/plpgsql/ch-2.sql')
-rw-r--r--challenge-275/luca-ferrari/plpgsql/ch-2.sql32
1 files changed, 32 insertions, 0 deletions
diff --git a/challenge-275/luca-ferrari/plpgsql/ch-2.sql b/challenge-275/luca-ferrari/plpgsql/ch-2.sql
new file mode 100644
index 0000000000..3d5642972d
--- /dev/null
+++ b/challenge-275/luca-ferrari/plpgsql/ch-2.sql
@@ -0,0 +1,32 @@
+--
+-- Perl Weekly Challenge 275
+-- Task 2
+-- See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-275>
+--
+
+CREATE SCHEMA IF NOT EXISTS pwc275;
+
+CREATE OR REPLACE FUNCTION
+pwc275.task2_plpgsql( s text )
+RETURNS text
+AS $CODE$
+DECLARE
+ output text := '';
+ previous text;
+ c text;
+BEGIN
+
+ FOR c IN SELECT v FROM regexp_split_to_table( s, '' ) v LOOP
+ IF c ~ '[a-z]' THEN
+ previous := c;
+ ELSE
+ c := chr( c::int + ascii( 'a' ) );
+ END IF;
+
+ output := output || c;
+ END LOOP;
+
+ return output;
+END
+$CODE$
+LANGUAGE plpgsql;