From be74113f7626faf233c72a3458121d59d0e2a9d4 Mon Sep 17 00:00:00 2001
From: "Thomas G. Lockhart" <lockhart@fourpalms.org>
Date: Thu, 30 Oct 1997 16:52:11 +0000
Subject: [PATCH] Add initial backend support for SET/SHOW/RESET TIME ZONE. 
 Uses TZ environment variable.  Needs additional schemes for brain-dead SQL92
 time offsets.

---
 src/backend/tcop/variable.c | 50 ++++++++++++++++++++++++++++++++++---
 1 file changed, 46 insertions(+), 4 deletions(-)

diff --git a/src/backend/tcop/variable.c b/src/backend/tcop/variable.c
index 260fdd6eb5a..dc6300a8118 100644
--- a/src/backend/tcop/variable.c
+++ b/src/backend/tcop/variable.c
@@ -1,8 +1,8 @@
 /*
- * Routines for handling of 'SET var TO', 'SHOW var' and 'RESET var'
- * statements.
+ * Routines for handling of 'SET var TO',
+ *  'SHOW var' and 'RESET var' statements.
  *
- * $Id: variable.c,v 1.17 1997/10/25 01:10:22 momjian Exp $
+ * $Id: variable.c,v 1.18 1997/10/30 16:52:11 thomas Exp $
  *
  */
 
@@ -136,6 +136,7 @@ get_token(char **tok, char **val, const char *str)
 }
 
 /*-----------------------------------------------------------------------*/
+#if FALSE
 static bool
 parse_null(const char *value)
 {
@@ -153,6 +154,7 @@ reset_null(const char *value)
 {
 	return TRUE;
 }
+#endif
 
 static bool
 parse_geqo(const char *value)
@@ -398,6 +400,46 @@ reset_date()
 	return TRUE;
 }
 
+static bool
+parse_timezone(const char *value)
+{
+	char	   *tok;
+
+	while ((value = get_token(&tok, NULL, value)) != 0)
+	{
+		setenv("TZ", tok, TRUE);
+		tzset();
+		PFREE(tok);
+	}
+
+	return TRUE;
+} /* parse_timezone() */
+
+static bool
+show_timezone()
+{
+	char		buf[64];
+	char	   *tz;
+
+	tz = getenv("TZ");
+
+	strcpy(buf, "Time zone is ");
+	strcat(buf, ((tz != NULL)? tz: "unknown"));
+
+	elog(NOTICE, buf, NULL);
+
+	return TRUE;
+} /* show_timezone() */
+
+static bool
+reset_timezone()
+{
+	unsetenv("TZ");
+	tzset();
+
+	return TRUE;
+} /* reset_timezone() */
+
 /*-----------------------------------------------------------------------*/
 struct VariableParsers
 {
@@ -412,7 +454,7 @@ struct VariableParsers
 		"datestyle", parse_date, show_date, reset_date
 	},
 	{
-		"timezone", parse_null, show_null, reset_null
+		"timezone", parse_timezone, show_timezone, reset_timezone
 	},
 	{
 		"cost_heap", parse_cost_heap,
-- 
GitLab