Grammar-problems with pl/pgsql in gram.y

From: Klaus Reger <K(dot)Reger(at)gmx(dot)de>
To: pgsql-hackers <pgsql-hackers(at)postgreSQL(dot)org>
Subject: Grammar-problems with pl/pgsql in gram.y
Date: 2001-05-16 10:29:16
Message-ID: 200105161029.f4GATII18440@pc01.reger-clan.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

I want to learn, how the pl/plsql-parser/compiler works. Therefore I planned
to implement a simple ELSIF, like oracle does.

I added the following K_ELSIF branch to gram.y, in the hope that, when ELSIF
is parsed, simply another if-structure in inserted.

---------------------------------------------------------
stmt_else :
{
PLpgSQL_stmts *new;

new = malloc(sizeof(PLpgSQL_stmts));
memset(new, 0, sizeof(PLpgSQL_stmts));
$$ = new;
elog(NOTICE, "empty ELSE detected");
}
| K_ELSIF expr_until_then proc_sect stmt_else
{
PLpgSQL_stmt_if *new;
elog(NOTICE, "ELSIF detected");
new = malloc(sizeof(PLpgSQL_stmt_if));
memset(new, 0, sizeof(PLpgSQL_stmt_if));
new->cmd_type = PLPGSQL_STMT_IF;
// new->lineno = $2;
new->cond = $2;
new->true_body = $3;
new->false_body = $4;

$$ = (PLpgSQL_stmts *)new;


}
| K_ELSE proc_sect
{
$$ = $2;
elog(NOTICE, "ELSE detected (%s)",
strdup(yytext));
}
;
--------------------------------------------------------------

A testprocedure, which looks like that:
--------------------------------------------------------------

DECLARE
iPar1PI ALIAS FOR $1;
iTmp integer;
iResult varchar;

BEGIN

iTmp = iPar1PI;

raise notice '1.0';

if iTmp IS NULL then
raise notice '2.0';
iResult = 'Echt NULL';

else
if iTmp = 0 then
raise notice '2.1.0';
iResult = 'Null (0)';

elsif (iTmp < 0) THEN
raise notice '2.1.1';
iResult = 'Negativ';

elsif (iTmp > 0) THEN
raise notice '2.1.2';
iResult = 'Positiv';

else
raise notice '2.1.3';
iResult = 'Gibts nicht!';
end if;
end if;

raise notice '3.0';

return iResult;
END;
--------------------------------------------------------------

is dumped in this way ...

--------------------------------------------------------------
Execution tree of successfully compiled PL/pgSQL function kr_test:

Functions data area:
entry 0: VAR $1 type int4 (typoid 23) atttypmod -1
entry 1: VAR found type bool (typoid 16) atttypmod -1
entry 2: VAR itmp type int4 (typoid 23) atttypmod -1
entry 3: VAR iresult type varchar (typoid 1043) atttypmod -1

Functions statements:
8:BLOCK <<*unnamed*>>
10: ASSIGN var 2 := 'SELECT $1 {$1=0}'
12: RAISE ''1.0''
14: IF 'SELECT $1 IS NULL {$1=2}' THEN
15: RAISE ''2.0''
16: ASSIGN var 3 := 'SELECT 'Echt NULL''
ELSE
19: IF 'SELECT $1 = 0 {$1=2}' THEN
20: RAISE ''2.1.0''
21: ASSIGN var 3 := 'SELECT 'Null (0)''
ELSE
ENDIF
ENDIF
37: RAISE ''3.0''
39: RETURN 'SELECT $1 {$1=3}'
END -- *unnamed*

End of execution tree of function kr_test
--------------------------------------------------------------

So my question is: Why does my inserted
PLpgSQL_stmt_if *new;
is not executed, because I do it in the same way like stmt_if does?

Who can halp me (Maybe Jan??)

Regards, Klaus

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Nils Zonneveld 2001-05-16 12:56:44 Re: Queries across multiple databases (was: SELECT from a table in another database).
Previous Message Trygve Falch 2001-05-16 07:58:27 Queries across multiple databases (was: SELECT from a table in another database).