Request for change in PL/PGSQL function handler
От | Josh Berkus |
---|---|
Тема | Request for change in PL/PGSQL function handler |
Дата | |
Msg-id | 3A71B396.43FB80D@agliodbs.com обсуждение исходный текст |
Ответы |
Re: Request for change in PL/PGSQL function handler
|
Список | 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'; ELSEIF 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 THENreturn_text := 'One'; ELSEIF b THENreturn_text := 'Two'; ELSIF c THENreturn_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 THENRETURN 'One'; END IF; IF b THENRETURN '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 informationtechnology 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
В списке pgsql-sql по дате отправления: