aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-195/luca-ferrari/postgresql/ch-1.sql30
1 files changed, 30 insertions, 0 deletions
diff --git a/challenge-195/luca-ferrari/postgresql/ch-1.sql b/challenge-195/luca-ferrari/postgresql/ch-1.sql
new file mode 100644
index 0000000000..a736df90b1
--- /dev/null
+++ b/challenge-195/luca-ferrari/postgresql/ch-1.sql
@@ -0,0 +1,30 @@
+-- Perl Weekly Challenge 195
+-- Task 1
+
+CREATE SCHEMA IF NOT EXISTS pwc195;
+
+CREATE OR REPLACE FUNCTION
+pwc195.task1_plpgsql( n int )
+RETURNS int
+AS $CODE$
+DECLARE
+ i int;
+ freq int;
+ counter int := 0;
+BEGIN
+ FOR i IN 1 .. n LOOP
+ SELECT count(*)
+ INTO freq
+ FROM regexp_split_to_table( i::text, '' ) as n(d)
+ GROUP BY d;
+
+ IF freq = 1 THEN
+ counter := counter + 1;
+ END IF;
+
+ END LOOP;
+
+ RETURN counter;
+END
+$CODE$
+LANGUAGE plpgsql;