summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc G. Fournier1997-01-26 17:28:48 +0000
committerMarc G. Fournier1997-01-26 17:28:48 +0000
commit427a964c302dd6ec2359eb4a8318303b09bc9363 (patch)
treecd4a3f7f6b20b7d6c7e014dc424ebfe3c6f4e7b3
parent1d8a696fd555a664961f9d365de29dcc6689e15a (diff)
|From: Keith Parks <[email protected]>
|Subject: [PATCH] adding SYS_TIME just for fun. | |Hi, | |Whilst I was playing round with the European dates patch I noticed the sysfunc() |that allows you to do :- | |create table test ( da date); |insert into test values (SYS_DATE); | |and have the current system date inserted. | |So I thought it would be nice to have the SYS_TIME facility too. | |I've cloned the function and changed a few things and there you have it, |you can now do: | |create table test2 ( ti time); |insert into test2 values (SYS_TIME);
-rw-r--r--src/backend/parser/sysfunc.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/backend/parser/sysfunc.c b/src/backend/parser/sysfunc.c
index 18e3c5afe54..fac1b60fd5a 100644
--- a/src/backend/parser/sysfunc.c
+++ b/src/backend/parser/sysfunc.c
@@ -45,10 +45,26 @@ static char *Sysfunc_system_date(void)
return &buf[0];
}
+static char *Sysfunc_system_time(void)
+{
+ time_t cur_time_secs;
+ struct tm *cur_time_expanded;
+ static char buf[10]; /* Just for safety, y'understand... */
+
+ time(&cur_time_secs);
+ cur_time_expanded = localtime(&cur_time_secs);
+ sprintf(buf, "%2.2d:%2.2d:%2.2d", cur_time_expanded->tm_hour,
+ cur_time_expanded->tm_min, cur_time_expanded->tm_sec);
+
+ return &buf[0];
+}
+
char *SystemFunctionHandler(char *funct)
{
if (!strcmp(funct, "SYS_DATE"))
return Sysfunc_system_date();
+ if (!strcmp(funct, "SYS_TIME"))
+ return Sysfunc_system_time();
return "*unknown function*";
}