From: Daryl Richter <daryl@eddl.us>
To: pgsql-sql@postgresql.org
Subject: Re: bug with if ... then ... clause in views
Date: Wed, 18 Jan 2006 07:32:53 -0500
Message-ID: <C0455D84-6156-4777-9427-16E9B08E5296@eddl.us> (raw)
In-Reply-To: <20060118091815.83323.qmail@web54314.mail.yahoo.com>
References: <20060118091815.83323.qmail@web54314.mail.yahoo.com>
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
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: daryl@eddl.us
Subject: Re: bug with if ... then ... clause in views
In-Reply-To: <C0455D84-6156-4777-9427-16E9B08E5296@eddl.us>
References: <20060118091815.83323.qmail@web54314.mail.yahoo.com> <C0455D84-6156-4777-9427-16E9B08E5296@eddl.us>
* 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