Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id E07BB475FBF for ; Wed, 2 Oct 2002 02:05:09 -0400 (EDT) Received: from brasileiro.net (slxwy.dorms.usu.edu [129.123.236.160]) by postgresql.org (Postfix) with ESMTP id 6EF73475FBD for ; Wed, 2 Oct 2002 02:05:09 -0400 (EDT) Received: from roberto by brasileiro.net with local (Exim 3.35 #1 (Debian)) id 17wcjv-0000dk-00; Wed, 02 Oct 2002 00:12:07 -0600 Date: Wed, 2 Oct 2002 00:12:07 -0600 From: Roberto Mello To: mgeddert Cc: pgsql-sql@postgresql.org Subject: Re: please help with converting a view in oracle into postgresql readably code Message-ID: <20021002061207.GA2075@cc.usu.edu> References: <000001c269d6$54d29580$a6267f18@ULTRAENIGMA> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <000001c269d6$54d29580$a6267f18@ULTRAENIGMA> User-Agent: Mutt/1.4i X-message-flag: Please consider using an e-mail program other than Outlook. It's insecure. X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200210/10 X-Sequence-Number: 9728 On Tue, Oct 01, 2002 at 10:41:17PM -0700, mgeddert wrote: > create or replace view events_orders_states as select o.*, o_states.order_state from events_orders o, ( SELECT order_id, CASE ( floor (avg ( CASE reg_state WHEN 'canceled' THEN 0 WHEN 'waiting' THEN 1 WHEN 'pending' THEN 2 WHEN 'shipped' THEN 3 ELSE 0)) ) WHEN 0 THEN 'canceled' WHEN 1 THEN 'incomplete' WHEN 2 THEN 'incomplete' WHEN 3 THEN 'fulfilled' ELSE 'void') as order_state FROM events_registrations GROUP BY order_id ) o_states WHERE o_states.order_id = o.order_id; Oracle 9 does support SQL92-compliant CASE WHEN. It's much more clear than using cryptic decode to me. See http://www.postgresql.org/idocs/index.php?functions-conditional.html Hope this works. -Roberto P.S.: Some indenting goes a long way through helping to understand your code. -- +----| Roberto Mello - http://www.brasileiro.net/ |------+ + Computer Science Graduate Student, Utah State University + + USU Free Software & GNU/Linux Club - http://fslc.usu.edu/ + "Hello, World!" 17 Errors, 31 Warnings....