Re: bug with if ... then ... clause in views

From: Jeff <threshar(at)torgo(dot)978(dot)org>
To: Emil Rachovsky <zsevgymko(at)yahoo(dot)com>
Cc: "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: bug with if ... then ... clause in views
Date: 2006-01-18 15:41:42
Message-ID: 43CE61B6.8010704@torgo.978.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql

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 <jeff(at)jefftrout(dot)com>
http://www.jefftrout.com/
http://www.stuarthamm.net/

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2006-01-18 16:38:46 Re: Huge number of disk writes after migration to 8.1
Previous Message Stephan Szabo 2006-01-18 15:25:33 Re: "REFERENCES" and UNIQUE

Browse pgsql-sql by date

  From Date Subject
Next Message Vraj Mohan 2006-01-18 16:35:39 Re: Matching several rows
Previous Message Patrick JACQUOT 2006-01-18 14:28:19 Re: Matching several rows