[Fwd: Re: nested elseif woes]

From: Ron St-Pierre <rstpierre(at)syscor(dot)com>
To: mail(at)webthatworks(dot)it, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: [Fwd: Re: nested elseif woes]
Date: 2004-05-10 19:15:46
Message-ID: 409FD4E2.3020708@syscor.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Ivan Sergio Borgonovo wrote:

I just re-checked the docs and see that ELSE IF requires an END for each ELSE IF:
> if 1=2 then
> if 1=2 then
> select 1;
> else
if 1=3 then
> select 2;
END IF;
> else
if 1=4 then
> if 1=5 then
> select 3;
END IF;
> else
> select 4;
> end if;
END IF;
> end if;
> end if;

>First thanks to Tom Lane who helped me promptly.
>
>Now let's come to the problem:
>
>create or replace function testa( )
> returns char(32) as
>'
>begin
> if 1=2 then
> if 1=2 then
> select 1;
> elseif 1=3 then
> select 2;
> elseif 1=4 then
> if 1=5 then
> select 3;
> else
> select 4;
> end if;
> end if;
> end if;
> return md5(''aaaa'');
>end;
>' language plpgsql;
>
>test1=# select * from testa();
>ERROR: syntax error at or near "if"
>CONTEXT: compile of PL/pgSQL function "testa" near line 14
>
>
This is odd, I replaced the else ifs with elsif and it worked on 7.4. My
7.3 documentation says that else if and elsif are equivalent.
imp=# select * from testa();
testa
----------------------------------
74b87337454200d4d33f80c4663dc5e5
(1 row)

My test code (yours, slightly modified):
drop function testa( );

create or replace function testa( )
returns char(32) as
'
begin
if 1=2 then
if 1=2 then
select 1;
elsif 1=3 then
select 2;
elsif 1=4 then
if 1=5 then
select 3;
else
select 4;
end if;
end if;
end if;
return md5(''aaaa'');
end;
' language plpgsql;

select * from testa();

>I made several test functions with similar structure with no
>improvements.
>I can't even figure a pattern. I get errors on if, else, and elseif.
>Till now the culprit seems to be elseif. Whenever I write test
>functions without elseif I get no errors.
>Did I misinterpreted the docs (37.7.2.4)?
>
>I really can't see the problem.
>
>I'm running 7.4.2-1 on Debian Sarge.
>
>
>To be less annoying to the list, could anyone point me to somewhere
>where I could look at functions written by others.
>Any good project with enough complicated functions to be useful to
>learn.
>
>
>thx
>
>---------------------------(end of broadcast)---------------------------
>TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org
>
>
>
>
Ron

Browse pgsql-general by date

  From Date Subject
Next Message scott.marlowe 2004-05-10 19:54:47 Re: basic question (shared buffers vs. effective cache
Previous Message Kris Jurka 2004-05-10 19:15:06 Re: domain type and array, is it possible?