7

I always use NVL() for assigning a default value when the result is null.

However in PostgreSql there is only COALESCE().

Can I give the COALESCE function an alias so it executes with NVL?

Or can I copy the function declaration somehow?

Tommy
  • 596
  • 6
  • 30
  • What's wrong with using `coalesce()` it's part of the SQL standard and also supported by Oracle. –  Oct 28 '16 at 08:27
  • 3
    @a_horse_with_no_name May sound trite but saving a few letters in the case of applying this function to dozens of columns can matter. – WestCoastProjects Oct 10 '19 at 22:39

1 Answers1

7

You can use this wrapper:

create or replace function nvl (anyelement, anyelement)
returns anyelement language sql as $$
    select coalesce($1, $2)
$$;

See also Oracle Differences between NVL and Coalesce.

Community
  • 1
  • 1
klin
  • 112,967
  • 15
  • 204
  • 232