Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function alias for Postgres default function

Tags:

postgresql

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?

like image 317
Tommy Avatar asked Oct 28 '16 08:10

Tommy


1 Answers

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.

like image 148
klin Avatar answered Sep 24 '22 10:09

klin