From 5dba324368d526b878978f60d55ae1db3b795804 Mon Sep 17 00:00:00 2001
From: Luca Ferrari <fluca1978@gmail.com>
Date: Mon, 22 Apr 2024 12:10:47 +0200
Subject: PWC 266

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-266/luca-ferrari/plpgsql/ch-1.sql | 37 +++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
 create mode 100644 challenge-266/luca-ferrari/plpgsql/ch-1.sql

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

diff --git a/challenge-266/luca-ferrari/plpgsql/ch-1.sql b/challenge-266/luca-ferrari/plpgsql/ch-1.sql
new file mode 100644
index 0000000000..7df21faa26
--- /dev/null
+++ b/challenge-266/luca-ferrari/plpgsql/ch-1.sql
@@ -0,0 +1,37 @@
+--
+-- Perl Weekly Challenge 266
+-- Task 1
+-- See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-266>
+--
+
+CREATE SCHEMA IF NOT EXISTS pwc266;
+
+CREATE OR REPLACE FUNCTION
+pwc266.task1_plpgsql( l text, r text )
+RETURNS SETOF text
+AS $CODE$
+
+   WITH left_words AS (
+   	   SELECT w, count( w ) as c
+	   FROM regexp_split_to_table( l, '\W+' ) w
+   	   GROUP BY 1
+	   )
+    , right_words AS (
+          SELECT w, count( w ) as c
+          FROM regexp_split_to_table( R, '\W+' ) w
+          GROUP BY 1
+    )
+
+    SELECT w
+    FROM left_words
+    WHERE w NOT IN ( SELECT w FROM right_words )
+    AND c = 1
+    UNION
+    SELECT w
+    FROM right_words
+    WHERE w NOT IN ( SELECT w FROM left_words )
+    AND c = 1
+   ;
+
+$CODE$
+LANGUAGE sql;
-- 
cgit 

