Help for this page

Select Code to Download


  1. or download this
    create function first_nonnull( one anyelement, two anyelement )
        returns anyelement
    ...
      , sfunc = last
      , finalfunc = first
    );
    
  2. 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;
    
  3. or download this
     first | first_nonnull | last | last_nonnull
    -------+---------------+------+--------------
           | one           | two  | two
     one   | one           |      | two
    (2 rows)