Skip to content

Commit 4b53191

Browse files
committed
To: Thomas Lockhart <Thomas.G.Lockhart@jpl.nasa.gov>
Subject: Re: [PATCHES] SET DateStyle patches On Tue, 22 Apr 1997, Thomas Lockhart wrote: > Some more patches! These (try to) finish implementing SET variable TO value > for "DateStyle" (changed the name from simply "date" to be more descriptive). > This is based on code from Martin and Bruce (?), which was easy to modify. > The syntax is > > SET DateStyle TO 'iso' > SET DateStyle TO 'postgres' > SET DateStyle TO 'sql' > SET DateStyle TO 'european' > SET DateStyle TO 'noneuropean' > SET DateStyle TO 'us' (same as "noneuropean") > SET DateStyle TO 'default' (current same as "postgres,us") > > ("european" is just compared for the first 4 characters, and "noneuropean" > is compared for the first 7 to allow less typing). > > Multiple arguments are allowed, so SET datestyle TO 'sql,euro' is valid. > > My mods also try to implement "SHOW variable" and "RESET variable", but > that part just core dumps at the moment. I would guess that my errors > are obvious to someone who knows what they are doing with the parser stuff, > so if someone (Bruce and/or Martin??) could have it do the right thing > we will have a more complete set of what we need. > > Also, I would like to have a floating point precision global variable to > implement "SET precision TO 10" and perhaps "SET precision TO 10,2" for > float8 and float4, but I don't know how to do that for integer types rather > than strings. If someone is fixing the SHOW and RESET code, perhaps they can > add some hooks for me to do the floats while they are at it. > > I've left some remnants of variable structures in the source code which > I did not use in the interests of getting something working for v6.1. > We'll have time to clean things up for the next release...
1 parent cf39859 commit 4b53191

File tree

7 files changed

+392
-41
lines changed

7 files changed

+392
-41
lines changed

src/backend/parser/gram.y

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 1.30 1997/04/05 06:25:59 vadim Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 1.31 1997/04/23 03:17:00 scrappy Exp $
1414
*
1515
* HISTORY
1616
* AUTHOR DATE MAJOR EVENT
@@ -108,7 +108,7 @@ static Node *makeA_Expr(int oper, char *opname, Node *lexpr, Node *rexpr);
108108
RevokeStmt, RuleStmt, TransactionStmt, ViewStmt, LoadStmt,
109109
CreatedbStmt, DestroydbStmt, VacuumStmt, RetrieveStmt, CursorStmt,
110110
ReplaceStmt, AppendStmt, NotifyStmt, DeleteStmt, ClusterStmt,
111-
ExplainStmt, VariableSetStmt
111+
ExplainStmt, VariableSetStmt, VariableShowStmt, VariableResetStmt
112112

113113
%type <str> relation_name, copy_file_name, copy_delimiter, def_name,
114114
database_name, access_method_clause, access_method, attr_name,
@@ -190,8 +190,8 @@ static Node *makeA_Expr(int oper, char *opname, Node *lexpr, Node *rexpr);
190190
NONE, NOT, NOTHING, NOTIFY, NOTNULL,
191191
OIDS, ON, OPERATOR, OPTION, OR, ORDER,
192192
PNULL, PRIVILEGES, PUBLIC, PURGE, P_TYPE,
193-
RENAME, REPLACE, RETRIEVE, RETURNS, REVOKE, ROLLBACK, RULE,
194-
SELECT, SET, SETOF, STDIN, STDOUT, STORE,
193+
RENAME, REPLACE, RESET, RETRIEVE, RETURNS, REVOKE, ROLLBACK, RULE,
194+
SELECT, SET, SETOF, SHOW, STDIN, STDOUT, STORE,
195195
TABLE, TO, TRANSACTION, UNIQUE, UPDATE, USING, VACUUM, VALUES
196196
VERBOSE, VERSION, VIEW, WHERE, WITH, WORK
197197
%token EXECUTE, RECIPE, EXPLAIN, LIKE, SEQUENCE
@@ -275,6 +275,8 @@ stmt : AddAttrStmt
275275
| DestroydbStmt
276276
| VacuumStmt
277277
| VariableSetStmt
278+
| VariableShowStmt
279+
| VariableResetStmt
278280
;
279281

280282
/*****************************************************************************
@@ -289,14 +291,34 @@ VariableSetStmt: SET var_name TO var_value
289291
VariableSetStmt *n = makeNode(VariableSetStmt);
290292
n->name = $2;
291293
n->value = $4;
292-
294+
293295
$$ = (Node *) n;
294296
}
295297
;
296298

297299
var_value: Sconst { $$ = $1; }
298300
;
299301

302+
VariableShowStmt: SHOW var_name
303+
{
304+
VariableSetStmt *n = makeNode(VariableSetStmt);
305+
n->name = $2;
306+
n->value = NULL;
307+
308+
$$ = (Node *) n;
309+
}
310+
;
311+
312+
VariableResetStmt: RESET var_name
313+
{
314+
VariableSetStmt *n = makeNode(VariableSetStmt);
315+
n->name = $2;
316+
n->value = NULL;
317+
318+
$$ = (Node *) n;
319+
}
320+
;
321+
300322
/*****************************************************************************
301323
*
302324
* QUERY :

src/backend/parser/keywords.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.8 1997/04/02 04:49:13 vadim Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.9 1997/04/23 03:17:04 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -116,6 +116,7 @@ static ScanKeyword ScanKeywords[] = {
116116
{ "recipe", RECIPE },
117117
{ "rename", RENAME },
118118
{ "replace", REPLACE },
119+
{ "reset", RESET },
119120
{ "retrieve", RETRIEVE },
120121
{ "returns", RETURNS },
121122
{ "revoke", REVOKE },
@@ -125,6 +126,7 @@ static ScanKeyword ScanKeywords[] = {
125126
{ "sequence", SEQUENCE },
126127
{ "set", SET },
127128
{ "setof", SETOF },
129+
{ "show", SHOW },
128130
{ "stdin", STDIN },
129131
{ "stdout", STDOUT },
130132
{ "store", STORE },

src/backend/tcop/utility.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.14 1997/04/02 18:23:34 scrappy Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.15 1997/04/23 03:17:09 scrappy Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -643,7 +643,23 @@ ProcessUtility(Node *parsetree,
643643
{
644644
VariableSetStmt *n = (VariableSetStmt *) parsetree;
645645
SetPGVariable(n->name, n->value);
646-
commandTag = "SET_VARIABLE";
646+
commandTag = "SET VARIABLE";
647+
}
648+
break;
649+
650+
case T_VariableShowStmt:
651+
{
652+
VariableSetStmt *n = (VariableSetStmt *) parsetree;
653+
GetPGVariable(n->name);
654+
commandTag = "SHOW VARIABLE";
655+
}
656+
break;
657+
658+
case T_VariableResetStmt:
659+
{
660+
VariableSetStmt *n = (VariableSetStmt *) parsetree;
661+
ResetPGVariable(n->name);
662+
commandTag = "RESET VARIABLE";
647663
}
648664
break;
649665

src/backend/tcop/variable.c

Lines changed: 122 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,49 @@
11
/*
22
* Routines for handling of SET var TO statements
33
*
4-
* $Id: variable.c,v 1.3 1997/04/17 13:50:30 scrappy Exp $
4+
* $Id: variable.c,v 1.4 1997/04/23 03:17:16 scrappy Exp $
55
*
66
* $Log: variable.c,v $
7+
* Revision 1.4 1997/04/23 03:17:16 scrappy
8+
* To: Thomas Lockhart <Thomas.G.Lockhart@jpl.nasa.gov>
9+
* Subject: Re: [PATCHES] SET DateStyle patches
10+
*
11+
* On Tue, 22 Apr 1997, Thomas Lockhart wrote:
12+
*
13+
* > Some more patches! These (try to) finish implementing SET variable TO value
14+
* > for "DateStyle" (changed the name from simply "date" to be more descriptive).
15+
* > This is based on code from Martin and Bruce (?), which was easy to modify.
16+
* > The syntax is
17+
* >
18+
* > SET DateStyle TO 'iso'
19+
* > SET DateStyle TO 'postgres'
20+
* > SET DateStyle TO 'sql'
21+
* > SET DateStyle TO 'european'
22+
* > SET DateStyle TO 'noneuropean'
23+
* > SET DateStyle TO 'us' (same as "noneuropean")
24+
* > SET DateStyle TO 'default' (current same as "postgres,us")
25+
* >
26+
* > ("european" is just compared for the first 4 characters, and "noneuropean"
27+
* > is compared for the first 7 to allow less typing).
28+
* >
29+
* > Multiple arguments are allowed, so SET datestyle TO 'sql,euro' is valid.
30+
* >
31+
* > My mods also try to implement "SHOW variable" and "RESET variable", but
32+
* > that part just core dumps at the moment. I would guess that my errors
33+
* > are obvious to someone who knows what they are doing with the parser stuff,
34+
* > so if someone (Bruce and/or Martin??) could have it do the right thing
35+
* > we will have a more complete set of what we need.
36+
* >
37+
* > Also, I would like to have a floating point precision global variable to
38+
* > implement "SET precision TO 10" and perhaps "SET precision TO 10,2" for
39+
* > float8 and float4, but I don't know how to do that for integer types rather
40+
* > than strings. If someone is fixing the SHOW and RESET code, perhaps they can
41+
* > add some hooks for me to do the floats while they are at it.
42+
* >
43+
* > I've left some remnants of variable structures in the source code which
44+
* > I did not use in the interests of getting something working for v6.1.
45+
* > We'll have time to clean things up for the next release...
46+
*
747
* Revision 1.3 1997/04/17 13:50:30 scrappy
848
* From: "Martin J. Laubach" <mjl@CSlab.tuwien.ac.at>
949
* Subject: [HACKERS] Patch: set date to euro/us postgres/iso/sql
@@ -24,8 +64,10 @@
2464
*/
2565
/*-----------------------------------------------------------------------*/
2666

67+
#include <stdio.h>
2768
#include <string.h>
2869
#include "postgres.h"
70+
#include "miscadmin.h"
2971
#include "tcop/variable.h"
3072

3173
/*-----------------------------------------------------------------------*/
@@ -70,38 +112,55 @@ static bool parse_null(const char *value)
70112
return TRUE;
71113
}
72114

115+
static bool show_null(const char *value)
116+
{
117+
return TRUE;
118+
}
119+
120+
static bool reset_null(const char *value)
121+
{
122+
return TRUE;
123+
}
124+
73125
static bool parse_date(const char *value)
74126
{
75127
char tok[32];
76128
int dcnt = 0, ecnt = 0;
77129

78-
while(value = get_token(tok, sizeof(tok), value))
130+
while((value = get_token(tok, sizeof(tok), value)) != 0)
79131
{
80132
/* Ugh. Somebody ought to write a table driven version -- mjl */
81133

82134
if(!strcasecmp(tok, "iso"))
83135
{
84-
PGVariables.date.format = Date_ISO;
136+
DateStyle = USE_ISO_DATES;
85137
dcnt++;
86138
}
87139
else if(!strcasecmp(tok, "sql"))
88140
{
89-
PGVariables.date.format = Date_SQL;
141+
DateStyle = USE_SQL_DATES;
90142
dcnt++;
91143
}
92144
else if(!strcasecmp(tok, "postgres"))
93145
{
94-
PGVariables.date.format = Date_Postgres;
146+
DateStyle = USE_POSTGRES_DATES;
95147
dcnt++;
96148
}
97-
else if(!strcasecmp(tok, "euro"))
149+
else if(!strncasecmp(tok, "euro", 4))
150+
{
151+
EuroDates = TRUE;
152+
ecnt++;
153+
}
154+
else if((!strcasecmp(tok, "us"))
155+
|| (!strncasecmp(tok, "noneuro", 7)))
98156
{
99-
PGVariables.date.euro = TRUE;
157+
EuroDates = FALSE;
100158
ecnt++;
101159
}
102-
else if(!strcasecmp(tok, "us"))
160+
else if(!strcasecmp(tok, "default"))
103161
{
104-
PGVariables.date.euro = FALSE;
162+
DateStyle = USE_POSTGRES_DATES;
163+
EuroDates = FALSE;
105164
ecnt++;
106165
}
107166
else
@@ -116,16 +175,39 @@ static bool parse_date(const char *value)
116175
return TRUE;
117176
}
118177

178+
static bool show_date()
179+
{
180+
char buf[64];
181+
182+
sprintf( buf, "Date style is %s with%s European conventions",
183+
((DateStyle == USE_ISO_DATES)? "iso": ((DateStyle == USE_ISO_DATES)? "sql": "postgres")),
184+
((EuroDates)? "": "out"));
185+
186+
elog(NOTICE, buf, NULL);
187+
188+
return TRUE;
189+
}
190+
191+
static bool reset_date()
192+
{
193+
DateStyle = USE_POSTGRES_DATES;
194+
EuroDates = FALSE;
195+
196+
return TRUE;
197+
}
198+
119199
/*-----------------------------------------------------------------------*/
120200
struct VariableParsers
121201
{
122202
const char *name;
123203
bool (*parser)(const char *);
204+
bool (*show)();
205+
bool (*reset)();
124206
} VariableParsers[] =
125207
{
126-
{ "date", parse_date },
127-
{ "timezone", parse_null },
128-
{ NULL }
208+
{ "datestyle", parse_date, show_date, reset_date },
209+
{ "timezone", parse_null, show_null, reset_null },
210+
{ NULL, NULL, NULL }
129211
};
130212

131213
/*-----------------------------------------------------------------------*/
@@ -139,14 +221,39 @@ bool SetPGVariable(const char *name, const char *value)
139221
return (vp->parser)(value);
140222
}
141223

142-
elog(NOTICE, "No such variable %s", name);
224+
elog(NOTICE, "Unrecognized variable %s", name);
143225

144226
return TRUE;
145227
}
146228

147229
/*-----------------------------------------------------------------------*/
148-
const char *GetPGVariable(const char *varName)
230+
bool GetPGVariable(const char *name)
149231
{
150-
return NULL;
232+
struct VariableParsers *vp;
233+
234+
for(vp = VariableParsers; vp->name; vp++)
235+
{
236+
if(!strcasecmp(vp->name, name))
237+
return (vp->show)();
238+
}
239+
240+
elog(NOTICE, "Unrecognized variable %s", name);
241+
242+
return TRUE;
151243
}
244+
152245
/*-----------------------------------------------------------------------*/
246+
bool ResetPGVariable(const char *name)
247+
{
248+
struct VariableParsers *vp;
249+
250+
for(vp = VariableParsers; vp->name; vp++)
251+
{
252+
if(!strcasecmp(vp->name, name))
253+
return (vp->reset)();
254+
}
255+
256+
elog(NOTICE, "Unrecognized variable %s", name);
257+
258+
return TRUE;
259+
}

src/include/nodes/nodes.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: nodes.h,v 1.7 1997/04/02 18:24:38 scrappy Exp $
9+
* $Id: nodes.h,v 1.8 1997/04/23 03:17:29 scrappy Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -180,6 +180,8 @@ typedef enum NodeTag {
180180
T_ExplainStmt,
181181
T_CreateSeqStmt,
182182
T_VariableSetStmt,
183+
T_VariableShowStmt,
184+
T_VariableResetStmt,
183185

184186
T_A_Expr = 700,
185187
T_Attr,

0 commit comments

Comments
 (0)