or download this
select first(v), first_nonnull(v), last(v), last_nonnull(v)
from ( select NULL::text as v union all
...
select first(v), first_nonnull(v), last(v), last_nonnull(v)
from ( select 'one'::text as v union all
select 'two' as v union all select NULL as v ) as q;