Re: [GENERAL] Allowing SYSDATE to Work

From: "Matt Miller" <pgsql(at)mattmillersf(dot)fastmail(dot)fm>
To: "Alvaro Herrera" <alvherre(at)commandprompt(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [GENERAL] Allowing SYSDATE to Work
Date: 2006-11-18 00:05:29
Message-ID: 1163808329.14079.276325895@webmail.messagingengine.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

Redirecting from -general.

> > I'd like SYSDATE to work syntactically and semantically the same as
> > CURRENT_TIMESTAMP
>
> current_time and the like are hardcoded in the grammar. You'd have to
> do the same for sysdate.

Okay, I patched. The patch follows. Please comment. In particular,
I've just copied the CURRENT_TIMESTAMP code block in gram.y. Is this
the best approach? I saw similar code copying between a couple of the
other time-related functions in gram.y. Can't keywords share code
blocks in bison?

I found it interesting that gram.c and parse.h already supported SYSDATE.
I patched only gram.y and keywords.c

> I'd question the hassle of having to patch all the Postgres
> installations you're going to want to run your code on.

Yeah, and I don't expect that they'll be a rush to commit this to head
anytime soon. I'll be happy enough tracking this locally. I think it's
a win for my situation.

===================================================================
RCS file: /projects/cvsroot/pgsql/src/backend/parser/gram.y,v
retrieving revision 2.568
diff -c -r2.568 gram.y
*** gram.y 5 Nov 2006 22:42:09 -0000 2.568
--- gram.y 17 Nov 2006 23:36:35 -0000
***************
*** 419,425 ****
SERIALIZABLE SESSION SESSION_USER SET SETOF SHARE
SHOW SIMILAR SIMPLE SMALLINT SOME STABLE START STATEMENT
STATISTICS STDIN STDOUT STORAGE STRICT_P SUBSTRING SUPERUSER_P SYMMETRIC
! SYSID SYSTEM_P

TABLE TABLESPACE TEMP TEMPLATE TEMPORARY THEN TIME TIMESTAMP
TO TRAILING TRANSACTION TREAT TRIGGER TRIM TRUE_P
--- 419,425 ----
SERIALIZABLE SESSION SESSION_USER SET SETOF SHARE
SHOW SIMILAR SIMPLE SMALLINT SOME STABLE START STATEMENT
STATISTICS STDIN STDOUT STORAGE STRICT_P SUBSTRING SUPERUSER_P SYMMETRIC
! SYSDATE SYSID SYSTEM_P

TABLE TABLESPACE TEMP TEMPLATE TEMPORARY THEN TIME TIMESTAMP
TO TRAILING TRANSACTION TREAT TRIGGER TRIM TRUE_P
***************
*** 7540,7545 ****
--- 7540,7559 ----
n->location = @1;
$$ = (Node *)n;
}
+ | SYSDATE
+ {
+ /*
+ * Translate as "now()", since we have a function that
+ * does exactly what is needed.
+ */
+ FuncCall *n = makeNode(FuncCall);
+ n->funcname = SystemFuncName("now");
+ n->args = NIL;
+ n->agg_star = FALSE;
+ n->agg_distinct = FALSE;
+ n->location = @1;
+ $$ = (Node *)n;
+ }
| CURRENT_TIMESTAMP '(' Iconst ')'
{
/*
***************
*** 8893,8898 ****
--- 8907,8913 ----
| SESSION_USER
| SOME
| SYMMETRIC
+ | SYSDATE
| TABLE
| THEN
| TO
Index: keywords.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/backend/parser/keywords.c,v
retrieving revision 1.177
diff -c -r1.177 keywords.c
*** keywords.c 7 Oct 2006 21:51:02 -0000 1.177
--- keywords.c 17 Nov 2006 23:36:35 -0000
***************
*** 324,329 ****
--- 324,330 ----
{"substring", SUBSTRING},
{"superuser", SUPERUSER_P},
{"symmetric", SYMMETRIC},
+ {"sysdate", SYSDATE},
{"sysid", SYSID},
{"system", SYSTEM_P},
{"table", TABLE},

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jeff Davis 2006-11-18 00:05:33 Re: PostgreSQL: Question about rules
Previous Message Ron Johnson 2006-11-17 23:55:08 Re: Allowing SYSDATE to Work

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2006-11-18 00:05:54 Re: pgsql: Clarify description of CIDR-address column
Previous Message Ron Johnson 2006-11-17 23:55:08 Re: Allowing SYSDATE to Work