OSDN Git Service

Allow plpgsql variables' default value expressions to reference
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 23 Dec 2003 00:01:57 +0000 (00:01 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 23 Dec 2003 00:01:57 +0000 (00:01 +0000)
existing variables (such as function parameters).  Per gripe from
David Fetter.

src/pl/plpgsql/src/gram.y

index 78772c2..45c50d0 100644 (file)
@@ -4,7 +4,7 @@
  *                                               procedural language
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/pl/plpgsql/src/gram.y,v 1.49 2003/11/29 19:52:12 pgsql Exp $
+ *       $PostgreSQL: pgsql/src/pl/plpgsql/src/gram.y,v 1.50 2003/12/23 00:01:57 tgl Exp $
  *
  *       This software is copyrighted by Jan Wieck - Hamburg.
  *
@@ -628,52 +628,9 @@ decl_defval                : ';'
                                        { $$ = 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;
-                                               }
+                                               plpgsql_ns_setlocal(false);
+                                               $$ = plpgsql_read_expression(';', ";");
+                                               plpgsql_ns_setlocal(true);
                                        }
                                ;