Skip to content

Commit 427a964

Browse files
committed
|From: Keith Parks <emkxp01@mtcc.demon.co.uk>
|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);
1 parent 1d8a696 commit 427a964

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/backend/parser/sysfunc.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,26 @@ static char *Sysfunc_system_date(void)
4545
return &buf[0];
4646
}
4747

48+
static char *Sysfunc_system_time(void)
49+
{
50+
time_t cur_time_secs;
51+
struct tm *cur_time_expanded;
52+
static char buf[10]; /* Just for safety, y'understand... */
53+
54+
time(&cur_time_secs);
55+
cur_time_expanded = localtime(&cur_time_secs);
56+
sprintf(buf, "%2.2d:%2.2d:%2.2d", cur_time_expanded->tm_hour,
57+
cur_time_expanded->tm_min, cur_time_expanded->tm_sec);
58+
59+
return &buf[0];
60+
}
61+
4862
char *SystemFunctionHandler(char *funct)
4963
{
5064
if (!strcmp(funct, "SYS_DATE"))
5165
return Sysfunc_system_date();
66+
if (!strcmp(funct, "SYS_TIME"))
67+
return Sysfunc_system_time();
5268
return "*unknown function*";
5369
}
5470

0 commit comments

Comments
 (0)