aboutsummaryrefslogtreecommitdiff
path: root/challenge-137/luca-ferrari/postgresql/ch-1.sql
blob: 798e9070fbb26f982c1df817157376f1686f8426 (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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
testdb=> select * from f_long_year();
f_long_year
-------------
1903
1908
1914
1920
1925
1931
1936
1942
1948
1953
1959
1964
1970
1976
1981
1987
1992
1998
2004
2009
2015
2020
2026
2032
2037
2043
2048
2054
2060
2065
2071
2076
2082
2088
2093
2099
(36 rows)


*/
CREATE OR REPLACE FUNCTION
f_long_year()
RETURNS SETOF int
AS $CODE$
DECLARE
        current_year int;
BEGIN
        FOR current_year IN 1900 .. 2100 LOOP
           IF date_part( 'week', make_Date( current_year, 12, 31 ) ) = 53 THEN
              RETURN NEXT current_year;
           END IF;
        END LOOP;

        RETURN;
END
$CODE$
LANGUAGE plpgsql;