clock_timestamp() and transaction_timestamp() function - Mailing list pgsql-patches

From Wang Mike
Subject clock_timestamp() and transaction_timestamp() function
Date
Msg-id BAY4-F179BziBEmmZji0001c5fa@hotmail.com
Whole thread Raw
Responses Re: clock_timestamp() and transaction_timestamp() function
Re: clock_timestamp() and transaction_timestamp() function
List pgsql-patches
add clock_timestamp() and transaction_timestamp() function

see TODO list get more

-----------------------------------------------------------------

diff -u -r ../cvs/pgsql/src/backend/utils/adt/timestamp.c
../pgsql/src/backend/utils/adt/timestamp.c
--- ../cvs/pgsql/src/backend/utils/adt/timestamp.c    2003-07-18
21:59:07.000000000 +0800
+++ ../pgsql/src/backend/utils/adt/timestamp.c    2003-07-18
22:45:03.000000000 +0800
@@ -28,6 +28,7 @@
 #include "miscadmin.h"
 #include "utils/array.h"
 #include "utils/builtins.h"
+#include "utils/nabstime.h"

 /*
  * gcc's -ffast-math switch breaks routines that expect exact results from
@@ -835,6 +836,9 @@
     return TRUE;
 }    /* EncodeSpecialTimestamp() */

+/* see pg_proc.h function now()  [line 1602]
+ * deleted by Xiongjian Wang (Mike Wang)
+ * Email: mikewang@zhengmai.com.cn
 Datum
 now(PG_FUNCTION_ARGS)
 {
@@ -848,6 +852,56 @@

     PG_RETURN_TIMESTAMPTZ(result);
 }
+*/
+
+/*
+ * Function transaction_timestamp() return current transaction timestamp.
+ * Added by Xiongjian Wang (Mike Wang)
+ * Email: mikewang@zhengmai.com.cn
+*/
+Datum
+transaction_timestamp(PG_FUNCTION_ARGS)
+{
+    TimestampTz result;
+    AbsoluteTime sec;
+    int            usec;
+
+    sec = GetCurrentTransactionStartTimeUsec(&usec);
+
+    result = AbsoluteTimeUsecToTimestampTz(sec, usec);
+
+    PG_RETURN_TIMESTAMPTZ(result);
+}    /* transaction_timestamp() */
+
+/*
+ * Function clock_timestamp() return current clock timestamp.
+ * Added by Xiongjian Wang (Mike Wang)
+ * Email: mikewang@zhengmai.com.cn
+*/
+Datum
+clock_timestamp(PG_FUNCTION_ARGS)
+{
+    TimestampTz result;
+    AbsoluteTime sec;
+    int            usec;
+
+    sec = GetCurrentAbsoluteTimeUsec(&usec);
+
+    result = AbsoluteTimeUsecToTimestampTz(sec, usec);
+
+    PG_RETURN_TIMESTAMPTZ(result);
+}    /* clock_timestamp() */
+
+/* Please tell me what is statement_timestamp() ?
+ * Email: mikewang@zhengmai.com.cn
+Datum
+statement_timestamp(PG_FUNCTION_ARGS)
+{
+    TimestampTz result;
+
+    PG_RETURN_TIMESTAMPTZ(result);
+}
+*/

 void
 dt2time(Timestamp jd, int *hour, int *min, int *sec, fsec_t *fsec)
diff -u -r ../cvs/pgsql/src/include/catalog/pg_proc.h
../pgsql/src/include/catalog/pg_proc.h
--- ../cvs/pgsql/src/include/catalog/pg_proc.h    2003-07-01
08:04:38.000000000 +0800
+++ ../pgsql/src/include/catalog/pg_proc.h    2003-07-18 21:47:15.000000000
+0800
@@ -1598,7 +1598,9 @@
 DESCR("convert date and time with time zone to timestamp with time zone");
 DATA(insert OID = 1298 (  timetzdate_pl    PGNSP PGUID 14 f f t f i 2 1184
"1266 1082"    "select ($2 + $1)" - _null_ ));
 DESCR("convert time with time zone and date to timestamp with time zone");
-DATA(insert OID = 1299 (  now               PGNSP PGUID 12 f f t f s 0 1184 ""  now
- _null_ ));
+
+/* Function Now() only a alias of transaction_timestamp() */
+DATA(insert OID = 1299 (now   PGNSP PGUID 12 f f t f s 0 1184 ""
transaction_timestamp - _null_ ));
 DESCR("current transaction time");

 /* OIDS 1300 - 1399 */
@@ -3406,6 +3408,12 @@
 DESCR("I/O");


+DATA(insert OID = 2510 (transaction_timestamp PGNSP PGUID 12 f f t f s 0
1184 ""  transaction_timestamp - _null_ ));
+DESCR("current transaction time");
+
+DATA(insert OID = 2511 (clock_timestamp PGNSP PGUID 12 f f t f v 0 1184 ""
 clock_timestamp - _null_ ));
+DESCR("current clock time");
+
 /*
  * Symbolic values for provolatile column: these indicate whether the
result
  * of a function is dependent *only* on the values of its explicit
arguments,
diff -u -r ../cvs/pgsql/src/include/utils/timestamp.h
../pgsql/src/include/utils/timestamp.h
--- ../cvs/pgsql/src/include/utils/timestamp.h    2003-05-13
07:08:52.000000000 +0800
+++ ../pgsql/src/include/utils/timestamp.h    2003-07-18 21:24:12.000000000
+0800
@@ -231,7 +231,9 @@
 extern Datum timestamptz_trunc(PG_FUNCTION_ARGS);
 extern Datum timestamptz_part(PG_FUNCTION_ARGS);

-extern Datum now(PG_FUNCTION_ARGS);
+/* extern Datum now(PG_FUNCTION_ARGS); */
+extern Datum transaction_timestamp(PG_FUNCTION_ARGS);
+extern Datum transaction_timestamp(PG_FUNCTION_ARGS);

 /* Internal routines (not fmgr-callable) */

_________________________________________________________________
与联机的朋友进行交流,请使用 MSN Messenger:  http://messenger.msn.com/cn


pgsql-patches by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: Datetime patch
Next
From: Bruce Momjian
Date:
Subject: Re: [HACKERS] allowed user/db variables