From: Josh Berkus <josh@agliodbs.com>
To: sqllist <pgsql-sql@postgresql.org>
Subject: Request for change in PL/PGSQL function handler
Date: Fri, 26 Jan 2001 09:27:50 -0800
Message-ID: <3A71B396.43FB80D@agliodbs.com> (raw)
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@agliodbs.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
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: josh@agliodbs.com
Subject: Re: Request for change in PL/PGSQL function handler
In-Reply-To: <3A71B396.43FB80D@agliodbs.com>
References: <3A71B396.43FB80D@agliodbs.com>
* 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