Request for change in PL/PGSQL function handler

From: Josh Berkus <josh(at)agliodbs(dot)com>
To: sqllist <pgsql-sql(at)postgresql(dot)org>
Subject: Request for change in PL/PGSQL function handler
Date: 2001-01-26 17:27:50
Message-ID: 3A71B396.43FB80D@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Jan, Tom, etc:

Currently (7.0.3) the PLPGSQL function compiler permits only one RETURN
statment, at the end of the function. RETURN statements placed
elsewhere cause a compile error.

This, combined with the lack of an ELSEIF statement, has forced me into
sometimes 7 levels of nested IF..THEN statements. WHile they work fine,
they're a bit hard to read and edit. For example, say I want to test
for a, b, c, or d sequentially, under the 7.0.3 compiler, I must:

BEGIN
IF a THEN
return_text := 'One';
ELSE
IF b THEN
return_text := 'Two';
ELSE
IF c THEN
return_text := 'Three';
ELSE
IF d THEN
return_text := 'Four';
ELSE
return_text := 'Not Found';
END IF;
END IF;
END IF;
END IF;
RETURN return_text;
END;

As you can see, this kind of structure gets kind of had to read and
maintain for more complex statments. I have two suggested revisions to
the compiler that would make this much easier:

SUGGESTION A: Support of an ELSEIF statement, as:

IF a THEN
return_text := 'One';
ELSEIF b THEN
return_text := 'Two';
ELSIF c THEN
return_text := 'Three';
...etc.

SUGGESTION B: Allow more than one RETURN statment in the function text,
with funciton processing to terminate as soon as a RETURN is reached in
the program logic, but otherwise be ignored:

IF a THEN
RETURN 'One';
END IF;

IF b THEN
RETURN 'Two';
END IF;

...etc.

Both approaches would, from my perspective, make my code easier to read
and maintain. And, of course, you may have already implemented one or
the other in 7.1 (which I have not yet got to run on an alternate port).

Thanks for your hard work and consideration towards us users.

-Josh Berkus

--
______AGLIO DATABASE SOLUTIONS___________________________
Josh Berkus
Complete information technology josh(at)agliodbs(dot)com
and data management solutions (415) 436-9166
for law firms, small businesses fax 436-0137
and non-profit organizations. pager 338-4078
San Francisco

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Glen and Rosanne Eustace 2001-01-26 17:44:26 Re: Re: Problem with Dates
Previous Message Kyle 2001-01-26 17:20:22 Re: Rule not invoked in 7.1