aboutsummaryrefslogtreecommitdiff
path: root/challenge-287/luca-ferrari/plpgsql/ch-1.sql
diff options
context:
space:
mode:
authorDave Jacoby <jacoby.david@gmail.com>2024-09-25 14:53:58 -0400
committerDave Jacoby <jacoby.david@gmail.com>2024-09-25 14:53:58 -0400
commit351a05d8cf592f39d6807167875515c68cf485eb (patch)
tree1e2f740dc47fe5e61eb710cab9dc357b0059fc0e /challenge-287/luca-ferrari/plpgsql/ch-1.sql
parentf86f5e2fec16020c1d86f9028fb0f61cfeac106e (diff)
parent4a2fee41a38b28f1e17b26768caf000185fa5350 (diff)
downloadperlweeklychallenge-club-351a05d8cf592f39d6807167875515c68cf485eb.tar.gz
perlweeklychallenge-club-351a05d8cf592f39d6807167875515c68cf485eb.tar.bz2
perlweeklychallenge-club-351a05d8cf592f39d6807167875515c68cf485eb.zip
Merge branch 'master' of https://github.com/manwar/perlweeklychallenge-club
Diffstat (limited to 'challenge-287/luca-ferrari/plpgsql/ch-1.sql')
-rw-r--r--challenge-287/luca-ferrari/plpgsql/ch-1.sql58
1 files changed, 58 insertions, 0 deletions
diff --git a/challenge-287/luca-ferrari/plpgsql/ch-1.sql b/challenge-287/luca-ferrari/plpgsql/ch-1.sql
new file mode 100644
index 0000000000..2df3b950cc
--- /dev/null
+++ b/challenge-287/luca-ferrari/plpgsql/ch-1.sql
@@ -0,0 +1,58 @@
+--
+-- Perl Weekly Challenge 287
+-- Task 1
+-- See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-287>
+--
+
+CREATE SCHEMA IF NOT EXISTS pwc287;
+
+CREATE OR REPLACE FUNCTION
+pwc287.task1_plpgsql( pwd text )
+RETURNS bool
+AS $CODE$
+DECLARE
+ counter int := 0;
+BEGIN
+
+ IF length( pwd ) < 6 THEN
+ RETURN false;
+ END IF;
+
+ SELECT count( x )
+ INTO counter
+ FROM regexp_matches( pwd, '[a-z]', 'g' ) x;
+
+ IF counter <= 0 THEN
+ RETURN false;
+ END IF;
+
+ SELECT count( x )
+ INTO counter
+ FROM regexp_matches( pwd, '[A-Z]', 'g' ) x;
+
+ IF counter <= 0 THEN
+ RETURN false;
+ END IF;
+
+ SELECT count( x )
+ INTO counter
+ FROM regexp_matches( pwd, '[0-9]', 'g' ) x;
+
+ IF counter <= 0 THEN
+ RETURN false;
+ END IF;
+
+
+ SELECT count( x )
+ INTO counter
+ FROM regexp_matches( pwd, '(.)\1\1', 'g' ) x;
+
+ IF counter > 0 THEN
+ RETURN false;
+ END IF;
+
+
+ RETURN true;
+END
+$CODE$
+LANGUAGE plpgsql;