473,405 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

nested elseif woes

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

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

Nov 23 '05 #1
6 3114
Dear Ivan:

On Mon, 10 May 2004, Ivan Sergio Borgonovo wrote:
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

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.


Is this the literal function? If so, try changing the "elseif" to "elsif".
No 2nd 'e'.

-frank

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 23 '05 #2
Ivan Sergio Borgonovo wrote:
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
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 23 '05 #3


On Mon, 10 May 2004, Ivan Sergio Borgonovo wrote:
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


Don't you mean ELSIF, not ELSEIF?

Kris Jurka
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 23 '05 #4
On Mon, 10 May 2004 13:56:39 -0500 (EST)
Kris Jurka <bo***@ejurka.com> wrote:
On Mon, 10 May 2004, Ivan Sergio Borgonovo wrote:
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


Don't you mean ELSIF, not ELSEIF?


thanks to everyone.
Curiously enough, trying to figure out what was wrong with my code,
I've been able to write versions with the wrong spelling that didn't
complain. That brought me astray.

Anyway does anyone know any public big enough project written in
plpgsql from which I could learn lurking at the code?
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 23 '05 #5
On Tue, May 11, 2004 at 12:58:55AM +0200, Ivan Sergio Borgonovo wrote:
thanks to everyone.
Curiously enough, trying to figure out what was wrong with my code,
I've been able to write versions with the wrong spelling that didn't
complain. That brought me astray.

Anyway does anyone know any public big enough project written in
plpgsql from which I could learn lurking at the code?


OpenACS (from openacs.org) is a huge web application framework with
the vast majority of the business logic written in PL/SQL. It has
a wide selection of PL/SQL functions, with equivalents for both
Oracle and PostgreSQL.

Cheers,
Steve

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 23 '05 #6
On 11/05/04, Ivan Sergio Borgonovo (ma**@webthatworks.it) wrote:
Anyway does anyone know any public big enough project written in
plpgsql from which I could learn lurking at the code?


Hi Ivan

I've written a small demo app in PHP and postgres. Whether or not you
use php, the bugadb.php file shows different ways of calling the plpgsql
functions.

You can see a (slightly out of date) version of the small demo running
here:

http://campbell-lange.net/bugaboo/

You can download the source from the bottom of my index page under the
link "Download the 24K zip file of bugaboo sources".

Bear in mind that I'm not an expert. However we have been doing webapps
for the last 2.5 years with a huge amount of success using plpgsql
functions handling the spatial arrangement of data and perl or php to do
the formatting and data verification.

Comments and corrections gratefully received.

Rory

--
Rory Campbell-Lange
<ro**@campbell-lange.net>
<www.campbell-lange.net>

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Angelina | last post by:
Hi, I need some help in writing a 'if-then-else' statement. I currently have wrote one that looks something like this.. If Combobox1 = xxx and textbox1 <> "" then 'run stored procedure 1 to...
4
by: Dthmtlgod | last post by:
Could someone please look at my code below, I am trying to nest a couple of if statements together and it is not working. I think I am close. if len(rsMove("MonitorID1")) > 0 and...
9
by: Thanks2U | last post by:
I have 2 if statements that are unrelated to each other, but the outcome of the variable of each of these are. Here is my first one: If sToEMail = "" Then sTo = "DT" &...
1
by: hdogg | last post by:
Scope Woes - IF statement nested in WHILE statement -PHP I have an array $actuals_sum. <?php while(conditions) { if($i == '24) {
0
by: rupalirane07 | last post by:
Both grids displays fine. But the problem is only parent datagrid sorting works fine but when i clik on child datagrid for sorting it gives me error: NullReferenceException error Any...
13
by: JRough | last post by:
I got lost on formatting the nested if/else's on the bottom of the file right up the last else/if there seems to be a stray bracket. I'm trying to line up the brackets so I can read it. Is it...
4
by: Patrick A | last post by:
All, I rely on nested IF statements with multiple conditions heavily, and someone suggested recently writing the statements (and especially reading them months later) would be much easier if I...
13
by: scottbouley | last post by:
HELP! I'm trying to check a form for missing values. Two of the fields are required and therefore the corresponding message boxes are VBOkOnly. The other two are for warning purposes and their...
4
by: henry | last post by:
Folks: Using Dreamweaver CS3... Consider a home page, "index.php" which conditionally REQUIREs one of 'N' HTML files of pure content. All site styles are specified in a master CSS file,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.