X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 433959DC833 for ; Wed, 18 Jan 2006 08:38:00 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 31880-08 for ; Wed, 18 Jan 2006 08:38:01 -0400 (AST) X-Greylist: delayed 00:05:01.231941 by SQLgrey- Received: from rwcrmhc12.comcast.net (rwcrmhc13.comcast.net [204.127.198.39]) by postgresql.org (Postfix) with ESMTP id 6F6BA9DC814 for ; Wed, 18 Jan 2006 08:37:56 -0400 (AST) Received: from [70.195.227.113] (113.sub-70-195-227.myvzw.com[70.195.227.113]) by comcast.net (rwcrmhc13) with SMTP id <20060118123257015009m6mpe>; Wed, 18 Jan 2006 12:32:58 +0000 Mime-Version: 1.0 (Apple Message framework v746.2) In-Reply-To: <20060118091815.83323.qmail@web54314.mail.yahoo.com> References: <20060118091815.83323.qmail@web54314.mail.yahoo.com> Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: Content-Transfer-Encoding: 7bit From: Daryl Richter Subject: Re: bug with if ... then ... clause in views Date: Wed, 18 Jan 2006 07:32:53 -0500 To: pgsql-sql@postgresql.org X-Mailer: Apple Mail (2.746.2) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/118 X-Sequence-Number: 23907 On Jan 18, 2006, at 4:18 AM, Emil Rachovsky wrote: > While trying to create some views I stumbled on some > problem with using the if-then clause. Here is a > simple example : > > CREATE OR REPLACE VIEW public.SomeView > as select d.id, > if (true) then d.DocNumber endif from > public.Z_Documents as d; > > I get the following error : > syntax error at or near "then" at character 72 > > I don't have a clue what is going on here. Any > suggestions? I see 2 issues. 1) if *what* is true? 2) AFAIK, there is no IF conditional in SQL. Perhaps you want CASE? e.g. CREATE OR REPLACE VIEW SomeView as select d.id, case when condition = true then d.doc_number else 'Bad Doc' end from documents as d; go > > Thanks in advance, > Emil > -- Daryl "Stress rarely has a positive impact on our ability to think. Never, I'd guess." -- Ron Jeffries, 2005