Re: please help with converting a view in oracle into postgresql readably code

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Matthew Geddert" <geddert(at)yahoo(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: please help with converting a view in oracle into postgresql readably code
Date: 2002-10-04 14:17:34
Message-ID: 20460.1033741054@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"Matthew Geddert" <geddert(at)yahoo(dot)com> writes:
> create or replace view events_orders_states
> as
> select o.*,
> o_states.order_state
> from events_orders o,
> (select
> order_id,
> decode (floor(avg (decode (reg_state,
> 'canceled', 0,
> 'waiting', 1,
> 'pending', 2,
> 'shipped', 3,
> 0))),
> 0, 'canceled',
> 1, 'incomplete',
> 2, 'incomplete',
> 3, 'fulfilled',
> 'void') as order_state
> from events_registrations
> group by order_id) o_states
> where o_states.order_id = o.order_id;

DECODE() is an Oracle-ism. You can use the SQL-standard CASE construct
instead. See

http://www.ca.postgresql.org/users-lounge/docs/7.2/postgres/functions-conditional.html

Other than the DECODE() calls this should run fine in PG.

regards, tom lane

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2002-10-04 14:24:47 Re: Rule creation
Previous Message Tom Lane 2002-10-04 14:14:06 Re: Can Postgres cache a table in memory?