Re: [HACKERS] clock_timestamp() and transcation_timestamp() patch

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Wang Mike <itlist(at)msn(dot)com>
Cc: PostgreSQL-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [HACKERS] clock_timestamp() and transcation_timestamp() patch
Date: 2003-07-24 02:26:43
Message-ID: 200307240226.h6O2QhG18520@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches


This looks really good, but we are in feature freeze right now.

This has been saved for the 7.5 release:

http:/momjian.postgresql.org/cgi-bin/pgpatches2

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

Wang Mike wrote:
> diff -u -r ../postgresql-snapshot/src/backend/utils/adt/nabstime.c
> ../pgsql/src/backend/utils/adt/nabstime.c
> --- ../postgresql-snapshot/src/backend/utils/adt/nabstime.c 2003-05-13
> 07:08:50.000000000 +0800
> +++ ../pgsql/src/backend/utils/adt/nabstime.c 2003-07-15 11:08:06.000000000
> +0800
> @@ -76,7 +76,6 @@
> * Function prototypes -- internal to this file only
> */
>
> -static AbsoluteTime tm2abstime(struct tm * tm, int tz);
> static void reltime2tm(RelativeTime time, struct tm * tm);
> static int istinterval(char *i_string,
> AbsoluteTime *i_start,
> @@ -311,7 +310,7 @@
> * Convert a tm structure to abstime.
> * Note that tm has full year (not 1900-based) and 1-based month.
> */
> -static AbsoluteTime
> +AbsoluteTime
> tm2abstime(struct tm * tm, int tz)
> {
> int day;
> diff -u -r ../postgresql-snapshot/src/backend/utils/adt/timestamp.c
> ../pgsql/src/backend/utils/adt/timestamp.c
> --- ../postgresql-snapshot/src/backend/utils/adt/timestamp.c 2003-05-13
> 07:08:50.000000000 +0800
> +++ ../pgsql/src/backend/utils/adt/timestamp.c 2003-07-15
> 20:42:39.000000000 +0800
> @@ -847,7 +847,65 @@
> result = AbsoluteTimeUsecToTimestampTz(sec, usec);
>
> PG_RETURN_TIMESTAMPTZ(result);
> -}
> +} /* now() */
> +
> +/*
> + * Function transaction_timestamp() return current transaction timestamp.
> + * Added by Xiongjian Wang (MikeWang)
> +*/
> +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 (MikeWang)
> +*/
> +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() */
> +
> +Datum
> +transaction_interval(PG_FUNCTION_ARGS)
> +{
> + Timestamp trans_tz;
> + Timestamp clock_tz;
> +
> + AbsoluteTime trans_sec;
> + AbsoluteTime clock_sec;
> + int trans_usec;
> + int clock_usec;
> +
> + clock_sec = GetCurrentAbsoluteTimeUsec(&clock_usec);
> + trans_sec = GetCurrentTransactionStartTimeUsec(&trans_usec);
> +
> + trans_tz = AbsoluteTimeUsecToTimestampTz(trans_sec, trans_usec);
> + clock_tz = AbsoluteTimeUsecToTimestampTz(clock_sec, clock_usec);
> +
> + return DirectFunctionCall2(timestamp_mi,
> + TimestampGetDatum(clock_tz),
> + TimestampGetDatum(trans_tz));
> +} /* transaction_interval() */
>
> void
> dt2time(Timestamp jd, int *hour, int *min, int *sec, fsec_t *fsec)
> diff -u -r ../postgresql-snapshot/src/include/catalog/pg_proc.h
> ../pgsql/src/include/catalog/pg_proc.h
> --- ../postgresql-snapshot/src/include/catalog/pg_proc.h 2003-06-23
> 06:04:55.000000000 +0800
> +++ ../pgsql/src/include/catalog/pg_proc.h 2003-07-15 20:54:06.000000000
> +0800
> @@ -3394,6 +3394,15 @@
> DATA(insert OID = 2503 ( anyarray_send PGNSP PGUID 12 f f t f s 1 17
> "2277" anyarray_send - _null_ ));
> DESCR("I/O");
>
> +/* Added by Xiongjian Wang (MikeWang) */
> +DATA(insert OID = 5001 ( transaction_timestamp PGNSP PGUID 12 f f t f s 0
> 1184 "" transaction_timestamp - _null_ ));
> +DESCR("current transaction timestamp like as function now()");
> +
> +DATA(insert OID = 5002 ( clock_timestamp PGNSP PGUID 12 f f t f v 0 1184
> "" clock_timestamp - _null_ ));
> +DESCR("current clock timestamp");
> +
> +DATA(insert OID = 5003 ( transaction_interval PGNSP PGUID 12 f f t f v 0
> 1186 "" transaction_interval - _null_ ));
> +DESCR("current transaction runs into present interval");
>
> /*
> * Symbolic values for provolatile column: these indicate whether the
> result
> diff -u -r ../postgresql-snapshot/src/include/utils/nabstime.h
> ../pgsql/src/include/utils/nabstime.h
> --- ../postgresql-snapshot/src/include/utils/nabstime.h 2003-05-13
> 07:08:52.000000000 +0800
> +++ ../pgsql/src/include/utils/nabstime.h 2003-07-15 11:06:41.000000000
> +0800
> @@ -165,5 +165,5 @@
> extern AbsoluteTime GetCurrentAbsoluteTimeUsec(int *usec);
> extern TimestampTz AbsoluteTimeUsecToTimestampTz(AbsoluteTime sec, int
> usec);
> extern void abstime2tm(AbsoluteTime time, int *tzp, struct tm * tm, char
> **tzn);
> -
> +extern AbsoluteTime tm2abstime(struct tm * tm, int tz);
> #endif /* NABSTIME_H */
> diff -u -r ../postgresql-snapshot/src/include/utils/timestamp.h
> ../pgsql/src/include/utils/timestamp.h
> --- ../postgresql-snapshot/src/include/utils/timestamp.h 2003-05-13
> 07:08:52.000000000 +0800
> +++ ../pgsql/src/include/utils/timestamp.h 2003-07-15 20:44:35.000000000
> +0800
> @@ -233,20 +233,24 @@
>
> extern Datum now(PG_FUNCTION_ARGS);
>
> -/* Internal routines (not fmgr-callable) */
> +/* Add by Xiongjian Wang (Mike Wang) */
> +extern Datum transaction_timestamp(PG_FUNCTION_ARGS);
> +extern Datum clock_timestamp(PG_FUNCTION_ARGS);
> +extern Datum transaction_interval(PG_FUNCTION_ARGS);
>
> -extern int tm2timestamp(struct tm * tm, fsec_t fsec, int *tzp, Timestamp
> *dt);
> +/* Internal routines (not fmgr-callable) */
> +extern int tm2timestamp(struct tm * tm, fsec_t fsec, int *tzp, Timestamp
> *dt);
> extern int timestamp2tm(Timestamp dt, int *tzp, struct tm * tm,
> fsec_t *fsec, char **tzn);
> extern void dt2time(Timestamp dt, int *hour, int *min, int *sec, fsec_t
> *fsec);
>
> -extern int interval2tm(Interval span, struct tm * tm, fsec_t *fsec);
> -extern int tm2interval(struct tm * tm, fsec_t fsec, Interval *span);
> +extern int interval2tm(Interval span, struct tm * tm, fsec_t *fsec);
> +extern int tm2interval(struct tm * tm, fsec_t fsec, Interval *span);
>
> extern Timestamp SetEpochTimestamp(void);
> extern void GetEpochTime(struct tm * tm);
>
> extern void isoweek2date(int woy, int *year, int *mon, int *mday);
> -extern int date2isoweek(int year, int mon, int mday);
> +extern int date2isoweek(int year, int mon, int mday);
>
> #endif /* TIMESTAMP_H */
>
> -------------------------------------------------------------------
>
> or see my attachment .
>
> and I have a problem, what is stetement_timestamp() ??
>
> _________________________________________________________________
> MSN Explorer: http://explorer.msn.com/lccn/

[ Attachment, skipping... ]

>
> ---------------------------(end of broadcast)---------------------------
> TIP 7: don't forget to increase your free space map settings

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Mike Mascari 2003-07-24 03:38:54 Re: this is in plain text (row level locks)
Previous Message Bruce Momjian 2003-07-24 02:20:58 Re:

Browse pgsql-patches by date

  From Date Subject
Next Message Bruce Momjian 2003-07-24 04:01:43 Re: Eliminate information_schema from oid2name listing
Previous Message Tom Lane 2003-07-23 15:09:42 Re: Czech NLS