aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuca Ferrari <fluca1978@gmail.com>2022-04-20 12:02:40 +0200
committerLuca Ferrari <fluca1978@gmail.com>2022-04-20 12:02:40 +0200
commit232cb84b704d4cf898156d5da68c4ae3b45bccfe (patch)
tree820db75b775b63776200c29031288b0a4bb31b9b
parent9230b85385d88aef1a8782fffe86e953ee90a1c1 (diff)
downloadperlweeklychallenge-club-232cb84b704d4cf898156d5da68c4ae3b45bccfe.tar.gz
perlweeklychallenge-club-232cb84b704d4cf898156d5da68c4ae3b45bccfe.tar.bz2
perlweeklychallenge-club-232cb84b704d4cf898156d5da68c4ae3b45bccfe.zip
Task 2 done in PL/Perl
-rw-r--r--challenge-161/luca-ferrari/postgresql/ch-2.plperl28
1 files changed, 28 insertions, 0 deletions
diff --git a/challenge-161/luca-ferrari/postgresql/ch-2.plperl b/challenge-161/luca-ferrari/postgresql/ch-2.plperl
new file mode 100644
index 0000000000..edae5c307c
--- /dev/null
+++ b/challenge-161/luca-ferrari/postgresql/ch-2.plperl
@@ -0,0 +1,28 @@
+-- Perl Weekly Challenge 161
+CREATE SCHEMA IF NOT EXISTS pwc161;
+
+
+CREATE OR REPLACE FUNCTION pwc161.pangrams()
+RETURNS SETOF text
+AS $CODE$
+ my @found;
+
+ for my $letter ( 'a' .. 'z' ){
+ my $query = spi_query( "SELECT word FROM pwc161.dictionary WHERE word like '%$letter%' order by random()" );
+
+ while ( defined ( $row = spi_fetchrow( $query ) ) ) {
+ # first word ever
+ push @found, $row->{ word } and return_next( $row->{ word } ) if ! @found;
+
+ next if grep /$letter/, @found;
+
+ # add the word
+ push @found, $row->{ word };
+ return_next( $row->{ word } );
+
+ }
+}
+
+return undef;
+$CODE$
+LANGUAGE plperl;