summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc G. Fournier1997-04-02 18:24:52 +0000
committerMarc G. Fournier1997-04-02 18:24:52 +0000
commita51df14a6927933ba576850a50125fccf283a175 (patch)
tree0c498bc3a1e1b0e5cc42975aad9f1d1d3b0da8b4
parent17b5bd33e415404734d9f904615a54814b80900b (diff)
From: "Martin J. Laubach" <mjl@CSlab.tuwien.ac.at>
Subject: [HACKERS] Patch: SET var TO 'val' Here is a patch that adds a "SET variable TO 'somevalue'" capability to the parser, and then calls the SetPGVariable() function (which does just issue a elog(NOTICE) to see whether it works). That's the framework for adding timezone/date format/language/... stuff.
-rw-r--r--src/backend/parser/gram.y33
-rw-r--r--src/backend/tcop/utility.c15
-rw-r--r--src/backend/tcop/variable.c4
-rw-r--r--src/include/nodes/nodes.h3
-rw-r--r--src/include/nodes/parsenodes.h13
5 files changed, 59 insertions, 9 deletions
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index 15fc14e9b13..402f3343ae4 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 1.28 1997/04/02 04:01:03 vadim Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 1.29 1997/04/02 18:23:07 scrappy Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
@@ -108,11 +108,12 @@ static Node *makeA_Expr(int oper, char *opname, Node *lexpr, Node *rexpr);
RevokeStmt, RuleStmt, TransactionStmt, ViewStmt, LoadStmt,
CreatedbStmt, DestroydbStmt, VacuumStmt, RetrieveStmt, CursorStmt,
ReplaceStmt, AppendStmt, NotifyStmt, DeleteStmt, ClusterStmt,
- ExplainStmt
+ ExplainStmt, VariableSetStmt
%type <str> relation_name, copy_file_name, copy_delimiter, def_name,
database_name, access_method_clause, access_method, attr_name,
- class, index_name, var_name, name, file_name, recipe_name
+ class, index_name, var_name, name, file_name, recipe_name,
+ var_name
%type <str> opt_id, opt_portal_name,
before_clause, after_clause, all_Op, MathOp, opt_name, opt_unique,
@@ -168,7 +169,7 @@ static Node *makeA_Expr(int oper, char *opname, Node *lexpr, Node *rexpr);
%type <ival> Iconst
%type <str> Sconst
-%type <str> Id, date
+%type <str> Id, date, var_value
/*
@@ -273,6 +274,30 @@ stmt : AddAttrStmt
| CreatedbStmt
| DestroydbStmt
| VacuumStmt
+ | VariableSetStmt
+ ;
+
+/*****************************************************************************
+ *
+ * Set PG internal variable
+ * SET var_name TO 'var_value'
+ *
+ *****************************************************************************/
+
+VariableSetStmt: SET var_name TO var_value
+ {
+ VariableSetStmt *n = makeNode(VariableSetStmt);
+ n->name = $2;
+ n->value = $4;
+
+ $$ = (Node *) n;
+ }
+ ;
+
+var_name: Id { $$ = $1; }
+ ;
+
+var_value: Sconst { $$ = $1; }
;
/*****************************************************************************
diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c
index 7511b154a61..ec4c7c68aef 100644
--- a/src/backend/tcop/utility.c
+++ b/src/backend/tcop/utility.c
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.13 1997/04/02 04:06:32 vadim Exp $
+ * $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.14 1997/04/02 18:23:34 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
@@ -44,6 +44,7 @@
#include "rewrite/rewriteDefine.h"
#include "tcop/tcopdebug.h"
#include "tcop/dest.h"
+#include "tcop/variable.h"
#include "tcop/utility.h"
#include "fmgr.h" /* For load_file() */
@@ -634,7 +635,17 @@ ProcessUtility(Node *parsetree,
beginRecipe(stmt);
}
break;
-
+
+ /* ********************************
+ * set variable statements
+ *********************************/
+ case T_VariableSetStmt:
+ {
+ VariableSetStmt *n = (VariableSetStmt *) parsetree;
+ SetPGVariable(n->name, n->value);
+ commandTag = "SET_VARIABLE";
+ }
+ break;
/* ********************************
* default
diff --git a/src/backend/tcop/variable.c b/src/backend/tcop/variable.c
index 6f279897556..e3041361394 100644
--- a/src/backend/tcop/variable.c
+++ b/src/backend/tcop/variable.c
@@ -1,8 +1,10 @@
#include "postgres.h"
#include "tcop/variable.h"
-bool SetPGVariable(const char *varName, const char *value)
+bool SetPGVariable(const char *name, const char *value)
{
+ elog(NOTICE, "Variable %s set to \"%s\"", name, value);
+
return TRUE;
}
diff --git a/src/include/nodes/nodes.h b/src/include/nodes/nodes.h
index 560fd1a38d0..a7c7ae95f1c 100644
--- a/src/include/nodes/nodes.h
+++ b/src/include/nodes/nodes.h
@@ -6,7 +6,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
- * $Id: nodes.h,v 1.6 1997/04/02 03:34:44 vadim Exp $
+ * $Id: nodes.h,v 1.7 1997/04/02 18:24:38 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
@@ -179,6 +179,7 @@ typedef enum NodeTag {
T_VacuumStmt,
T_ExplainStmt,
T_CreateSeqStmt,
+ T_VariableSetStmt,
T_A_Expr = 700,
T_Attr,
diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h
index dee1c1eac57..b806326e9ed 100644
--- a/src/include/nodes/parsenodes.h
+++ b/src/include/nodes/parsenodes.h
@@ -6,7 +6,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
- * $Id: parsenodes.h,v 1.11 1997/04/02 03:34:46 vadim Exp $
+ * $Id: parsenodes.h,v 1.12 1997/04/02 18:24:52 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
@@ -423,6 +423,17 @@ typedef struct ExplainStmt {
bool verbose; /* print plan info */
} ExplainStmt;
+/* ----------------------
+ * Set Statement
+ * ----------------------
+ */
+
+typedef struct VariableSetStmt {
+ NodeTag type;
+ char *name;
+ char *value;
+ } VariableSetStmt;
+
/*****************************************************************************
* Optimizable Statements