pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jeff <threshar@torgo.978.org>
To: Emil Rachovsky <zsevgymko@yahoo.com>
Cc: pgsql-sql@postgresql.org <pgsql-sql@postgresql.org>
Cc: pgsql-general@postgresql.org <pgsql-general@postgresql.org>
Subject: Re: bug with if ... then ... clause in views
Date: Wed, 18 Jan 2006 10:41:42 -0500
Message-ID: <43CE61B6.8010704@torgo.978.org> (raw)
In-Reply-To: <20060118091815.83323.qmail@web54314.mail.yahoo.com>
References: <20060118091815.83323.qmail@web54314.mail.yahoo.com>

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@jefftrout.com>
http://www.jefftrout.com/
http://www.stuarthamm.net/




view thread (4+ messages)

Message-ID: <43CE61B6.8010704@torgo.978.org>
Permalink:  ../43CE61B6.8010704@torgo.978.org/
Also on:    postgresql.org/message-id/43CE61B6.8010704@torgo.978.org

 · 

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: threshar@torgo.978.org, zsevgymko@yahoo.com, pgsql-general@postgresql.org
  Subject: Re: bug with if ... then ... clause in views
  In-Reply-To: <43CE61B6.8010704@torgo.978.org>

* 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