README

decode - decode function implementation

Module decode helps with implementation of well know Oracle's decode
functions. This functions is very dificult implementable via classic
PostgreSQL way. The coercion rules are too specific. When we should to use
transform hook, the decode implementation is trivial. Inside transformation
the function call is transformed to CASE statement. The code is little bit
more dificult, because respect more decode behave than CASE behave. For
decode's parameters an expression NULL = NULL is true.

postgres=# select decode(10,20,'a', 10, 'b',null,'c', 'd');
ERROR:  function decode(integer, integer, unknown, integer, unknown,
unknown, unknown, unknown) does not exist
LINE 1: select decode(10,20,'a', 10, 'b',null,'c', 'd');

postgres=# select decode(67,20,'a', 10, 'b',null,'c', 'd');
 decode 
--------
 d
(1 row)

postgres=# select decode(20,20,'a', 10, 'b',null,'c', 'd');
 decode 
--------
 a
(1 row)

postgres=# select decode(null::int, 20,'a', 10, 'b',null,'c', 'd');
 decode 
--------
 c
(1 row)

Last case signalise, so this implementation needs some work.

