pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Matthew Geddert <geddert@yahoo.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: please help with converting a view in oracle into postgresql readably code
Date: Fri, 04 Oct 2002 10:17:34 -0400
Message-ID: <20460.1033741054@sss.pgh.pa.us> (raw)
In-Reply-To: <000301c269c6$3cab1000$a6267f18@ULTRAENIGMA>
References: <000301c269c6$3cab1000$a6267f18@ULTRAENIGMA>

"Matthew Geddert" <geddert@yahoo.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



view thread (4+ messages)

Message-ID: <20460.1033741054@sss.pgh.pa.us>
Permalink:  ../20460.1033741054@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/20460.1033741054@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, geddert@yahoo.com
  Subject: Re: please help with converting a view in oracle into postgresql readably code
  In-Reply-To: <20460.1033741054@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox