Re: Doc patch--clarifying $1 in PL/PgSQL - Mailing list pgsql-patches

From Tom Lane
Subject Re: Doc patch--clarifying $1 in PL/PgSQL
Date
Msg-id 28628.1072137791@sss.pgh.pa.us
Whole thread Raw
In response to Re: Doc patch--clarifying $1 in PL/PgSQL  (David Fetter <david@fetter.org>)
Responses Re: Doc patch--clarifying $1 in PL/PgSQL
List pgsql-patches
David Fetter <david@fetter.org> writes:
> On Mon, Dec 22, 2003 at 05:50:12PM -0500, Tom Lane wrote:
>> David Fetter <david@fetter.org> writes:
> +      Note that it is not possible to assign function arguments during
> +      a <literal>DECLARE</> block.
>>
>> Seems to me this is a bug that should be fixed, not documented.

> I got the impression from Jan Wieck that it wasn't fixable, or at
> least not without a major rewrite of the plpgsql engine.  I'm sure
> somebody will correct me if I got a mistaken impression, though :)

Not that hard ... just requires replacing some special-purpose code with
general-purpose code ...

            regards, tom lane


*** src/pl/plpgsql/src/gram.y.orig    Sat Nov 29 14:52:12 2003
--- src/pl/plpgsql/src/gram.y    Mon Dec 22 18:50:35 2003
***************
*** 628,679 ****
                      { $$ = NULL; }
                  | decl_defkey
                      {
!                         int                tok;
!                         int                lno;
!                         PLpgSQL_dstring ds;
!                         PLpgSQL_expr    *expr;
!
!                         lno = plpgsql_scanner_lineno();
!                         expr = malloc(sizeof(PLpgSQL_expr));
!                         plpgsql_dstring_init(&ds);
!                         plpgsql_dstring_append(&ds, "SELECT ");
!
!                         expr->dtype   = PLPGSQL_DTYPE_EXPR;
!                         expr->plan      = NULL;
!                         expr->nparams = 0;
!
!                         tok = yylex();
!                         switch (tok)
!                         {
!                             case 0:
!                                 yyerror("unexpected end of function");
!                             case K_NULL:
!                                 if (yylex() != ';')
!                                     yyerror("expected \";\" after \"NULL\"");
!
!                                 free(expr);
!                                 plpgsql_dstring_free(&ds);
!
!                                 $$ = NULL;
!                                 break;
!
!                             default:
!                                 plpgsql_dstring_append(&ds, yytext);
!                                 while ((tok = yylex()) != ';')
!                                 {
!                                     if (tok == 0)
!                                         yyerror("unterminated default value");
!
!                                     if (plpgsql_SpaceScanned)
!                                         plpgsql_dstring_append(&ds, " ");
!                                     plpgsql_dstring_append(&ds, yytext);
!                                 }
!                                 expr->query = strdup(plpgsql_dstring_get(&ds));
!                                 plpgsql_dstring_free(&ds);
!
!                                 $$ = expr;
!                                 break;
!                         }
                      }
                  ;

--- 628,636 ----
                      { $$ = NULL; }
                  | decl_defkey
                      {
!                         plpgsql_ns_setlocal(false);
!                         $$ = plpgsql_read_expression(';', ";");
!                         plpgsql_ns_setlocal(true);
                      }
                  ;


pgsql-patches by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: Alpha test
Next
From: Tom Lane
Date:
Subject: Re: Alpha test