From b9256920c8b9f0095867078e3e71025314604acb Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Wed, 20 Apr 2022 11:12:24 +0200 Subject: Task1 PL/Perl done --- challenge-161/luca-ferrari/postgresql/ch-1.plperl | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 challenge-161/luca-ferrari/postgresql/ch-1.plperl diff --git a/challenge-161/luca-ferrari/postgresql/ch-1.plperl b/challenge-161/luca-ferrari/postgresql/ch-1.plperl new file mode 100644 index 0000000000..8d4e596abe --- /dev/null +++ b/challenge-161/luca-ferrari/postgresql/ch-1.plperl @@ -0,0 +1,27 @@ +CREATE SCHEMA IF NOT EXISTS pwc161; + +/* +testdb=> create schema pwc161; +cCREATE SCHEMA +testdb=> create table pwc161.dictionary( word text ); +CREATE TABLE + +$ psql -h miguel -U luca -c 'COPY pwc161.dictionary( word ) FROM STDIN;' testdb < ../../data/dictionary.txt +COPY 39172 +*/ + + +CREATE OR REPLACE FUNCTION +pwc161.plperl_abecedarian() +RETURNS SETOF text +AS $CODE$ + + my $query = spi_query( 'SELECT word FROM pwc161.dictionary ORDER BY length( word ) ASC' ); + while ( defined ( $row = spi_fetchrow( $query ) ) ) { + my @letters = split //, $row->{ word }; + return_next( $row->{ word } ) if ( $row->{ word } eq join( '', sort( @letters ) ) ); +} + +return undef; +$CODE$ +LANGUAGE plperl; -- cgit