From ab26905beb70d890b8e43bbb1ae0e06a00a22491 Mon Sep 17 00:00:00 2001
From: Luca Ferrari <fluca1978@gmail.com>
Date: Fri, 20 Sep 2024 09:38:38 +0200
Subject: PWC 287

Task 1 Raku done
Task 2 Raku done

Task 1 PL/Perl done
Task 2 PL/Perl done

Task 1 PL/PgSQL done
Task 2 PL/PgSQL done

Task 1 PL/Java done
Task 2 PL/Java done

Task 1 Python done
Task 2 Python done
---
 challenge-287/luca-ferrari/plpgsql/ch-1.sql | 58 +++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)
 create mode 100644 challenge-287/luca-ferrari/plpgsql/ch-1.sql

(limited to 'challenge-287/luca-ferrari/plpgsql/ch-1.sql')

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;
-- 
cgit 

