begin;

drop function if exists year(timestamp);
create or replace function year(timestamp)
returns int as $$
    select extract(year from $1)::int;
$$ language sql immutable;

drop function if exists segfault_setof(int);
create or replace function segfault_setof(int)
returns setof date as $$
    select s::date
    from generate_series(timestamp '2001-01-01', timestamp '2020-01-01', '1 day') s
    where year(s) <= $1 and year(s) >= $1;
$$ language sql stable;

select s from segfault_setof(year(current_date)::int) s;

rollback;
