aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuca Ferrari <fluca1978@gmail.com>2023-01-03 18:46:30 +0100
committerLuca Ferrari <fluca1978@gmail.com>2023-01-03 18:46:30 +0100
commite8e7e45887788949e90bdab9a4602e3588820397 (patch)
treea3c626c510a5c6e553e529f1e9be047748ce658b
parent95eed7fdd1ad6a54bb83cd05a9f304200669af8e (diff)
downloadperlweeklychallenge-club-e8e7e45887788949e90bdab9a4602e3588820397.tar.gz
perlweeklychallenge-club-e8e7e45887788949e90bdab9a4602e3588820397.tar.bz2
perlweeklychallenge-club-e8e7e45887788949e90bdab9a4602e3588820397.zip
Task 1 done plpgsql
-rw-r--r--challenge-198/luca-ferrari/postgresql/ch-1.sql22
1 files changed, 22 insertions, 0 deletions
diff --git a/challenge-198/luca-ferrari/postgresql/ch-1.sql b/challenge-198/luca-ferrari/postgresql/ch-1.sql
new file mode 100644
index 0000000000..b5b1e7fdbb
--- /dev/null
+++ b/challenge-198/luca-ferrari/postgresql/ch-1.sql
@@ -0,0 +1,22 @@
+CREATE SCHEMA IF NOT EXISTS pwc198;
+
+CREATE OR REPLACE FUNCTION
+pwc198.task1_plpgsql( l int[] )
+RETURNS int
+AS $CODE$
+
+ with counting as (
+ select v, v - lag( v, 1, v ) over w as d
+ from unnest( l ) v
+ window w as (order by v asc )
+ )
+ , max_counting as (
+ select max( d ) from counting
+ )
+ select count(*)
+ from counting
+ where d = ( select * from max_counting );
+
+
+$CODE$
+LANGUAGE sql;