Top
Enterprise Postgres 17 SP1 Application Development Guide

10.4.1 DECODE

Description

Compares values and if they match, returns a corresponding value.

Syntax
DECODE(expr, srch, result [, srch, result ]... [, default ])
General rules

Example

In the following example, the value of col3 in table t1 is compared and converted to a different value. If the col3 value matches search value 1, the result value returned is "one". If the col3 value does not match any of search values 1, 2, or 3, the default value "other number" is returned.

SELECT col1, DECODE(col3, 1000, 'one',
                               2000, 'two',
                               3000, 'three',
                               'other number') "num-word"
       FROM t1;
col1  | num-word
------+----------
 1001 | one
 1002 | two
 1003 | three
(3 rows)