aboutsummaryrefslogtreecommitdiff
path: root/challenge-277/luca-ferrari/plpgsql/ch-1.sql
blob: 70bfb4aab7162290ec074c31fe7b873a6f50476f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
CREATE OR REPLACE FUNCTION
pwc277.task1_plpgsql( words1 text[], words2 text[] )
RETURNS int
AS $CODE$

   WITH w1 AS (
       SELECT w::text
    FROM unnest( words1 ) w
    GROUP BY w
    HAVING count(*) = 1
  ),
  w2 AS (
         SELECT w::text
    FROM unnest( words2 ) w
    GROUP BY w
    HAVING count(*) = 1
  )
  SELECT count( l.w )
  FROM w1 l, w2 r
  WHERE l.w = r.w

$CODE$
LANGUAGE sql;