X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 6FB359DC97E; Wed, 18 Jan 2006 11:41:50 -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 65545-06; Wed, 18 Jan 2006 11:41:54 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id EA4429DC87F; Wed, 18 Jan 2006 11:41:47 -0400 (AST) Received: from insiderscore.com (mail01.insiderscore.com [69.84.139.233]) by svr4.postgresql.org (Postfix) with ESMTP id 8E3B95AF0D3; Wed, 18 Jan 2006 15:41:52 +0000 (GMT) Received: from [10.10.10.105] (mail01.insiderscore.com [69.84.139.233]) by insiderscore.com (Postfix) with ESMTP id 801F511C4295; Wed, 18 Jan 2006 10:41:44 -0500 (EST) Message-ID: <43CE61B6.8010704@torgo.978.org> Date: Wed, 18 Jan 2006 10:41:42 -0500 From: Jeff User-Agent: Mozilla Thunderbird 1.0.7 (Macintosh/20050923) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Emil Rachovsky Cc: "pgsql-sql@postgresql.org" , "pgsql-general@postgresql.org" Subject: Re: bug with if ... then ... clause in views References: <20060118091815.83323.qmail@web54314.mail.yahoo.com> In-Reply-To: <20060118091815.83323.qmail@web54314.mail.yahoo.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200601/809 X-Sequence-Number: 89754 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? > > > IF / THEN is not part of SQL. it is part of plpgsql. However you'll find that CASE can do the same thing. select d.id, case when true then d.docNumber else 'something else' end as blah, public.Z_documents as d ... -- Jeff Trout http://www.jefftrout.com/ http://www.stuarthamm.net/