Re: Porting Oracle Decode to Postgresql

From: Tod McQuillin <devin(at)spamcop(dot)net>
To: MindTerm <mindterm(at)yahoo(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Porting Oracle Decode to Postgresql
Date: 2001-11-22 09:47:50
Message-ID: 20011122184250.G20207-100000@glass.pun-pun.prv
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Thu, 22 Nov 2001, MindTerm wrote:

> I am writing to ask how to port oracle's decode( ..)
> function to postgresql ?

The ANSI SQL version of decode is CASE.

See http://www.postgresql.org/idocs/index.php?functions-conditional.html
for the full documentation, but basically, it works like this:

Oracle:
decode (value, 0, 'zero', 1, 'one', 'unknown')

ANSI:
CASE WHEN value=0 THEN 'zero' WHEN value=1 THEN 'one' ELSE 'unknown' END

or

CASE value WHEN 0 THEN 'zero' WHEN 1 THEN 'one' ELSE 'unknown' END

--
Tod McQuillin

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message MindTerm 2001-11-22 09:54:57 Re: Porting Oracle Decode to Postgresql
Previous Message MindTerm 2001-11-22 08:13:18 Porting Oracle Decode to Postgresql