clock_timestamp() and transaction_timestamp() function

From: "Wang Mike" <itlist(at)msn(dot)com>
To: pgsql-patches(at)postgresql(dot)org
Subject: clock_timestamp() and transaction_timestamp() function
Date: 2003-07-19 02:33:32
Message-ID: BAY4-F179BziBEmmZji0001c5fa@hotmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)zhengmai(dot)com(dot)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(at)zhengmai(dot)com(dot)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(at)zhengmai(dot)com(dot)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(at)zhengmai(dot)com(dot)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

Responses

Browse pgsql-patches by date

  From Date Subject
Next Message Bruce Momjian 2003-07-19 03:11:28 Re: [NOVICE] connectby(... pos_of_sibling)
Previous Message Sean Chittenden 2003-07-18 23:54:08 pg_ping(1) utility...